o
    ÔèFh™  ã                   @   sh   d dl mZ d dlmZmZ d dlmZmZ d dlm	Z	 d dl
mZ d dlmZ dZG dd	„ d	eƒZd
S )é    )Úpartial)ÚquoteÚ	urlencode)ÚDEFAULT_SENTINELÚGeocoder©ÚLocation)ÚPoint)Úlogger)ÚMapTilerc                       sh   e Zd ZdZdZdeededddœ‡ fdd„
Zdd	d
„Zdeddddœdd„Zdeddœdd„Z	‡  Z
S )r   z}Geocoder using the MapTiler API.

    Documentation at:
        https://cloud.maptiler.com/geocoding/ (requires sign-up)
    z/geocoding/%(query)s.jsonNzapi.maptiler.com)ÚschemeÚtimeoutÚproxiesÚ
user_agentÚssl_contextÚadapter_factoryÚdomainc          	         sD   t ƒ j||||||d� || _| d¡| _d| j| j| jf | _dS )a¾  
        :param str api_key: The API key required by Maptiler to perform
            geocoding requests. API keys are managed through Maptiler's account
            page (https://cloud.maptiler.com/account/keys).

        :param str scheme:
            See :attr:`geopy.geocoders.options.default_scheme`.

        :param int timeout:
            See :attr:`geopy.geocoders.options.default_timeout`.

        :param dict proxies:
            See :attr:`geopy.geocoders.options.default_proxies`.

        :param str user_agent:
            See :attr:`geopy.geocoders.options.default_user_agent`.

        :type ssl_context: :class:`ssl.SSLContext`
        :param ssl_context:
            See :attr:`geopy.geocoders.options.default_ssl_context`.

        :param callable adapter_factory:
            See :attr:`geopy.geocoders.options.default_adapter_factory`.

            .. versionadded:: 2.0

        :param str domain: base api domain for Maptiler
        )r   r   r   r   r   r   ú/z	%s://%s%sN)ÚsuperÚ__init__Úapi_keyÚstripr   r   Úapi_pathÚapi)	Úselfr   r   r   r   r   r   r   r   ©Ú	__class__© úQ/var/www/html/loop/nvenv/lib/python3.10/site-packages/geopy/geocoders/maptiler.pyr      s   (úzMapTiler.__init__Tc                    s:   |d }|sd S dd„ ‰ |rˆ |d ƒS ‡ fdd„|D ƒS )NÚfeaturesc                 S   s0   | d }| d d }| d d }t |||f| ƒS )NÚ
place_nameÚcenterr   é   r   )ÚfeatureÚlocationÚ	longitudeÚlatituder   r   r   Úparse_featureO   s   z+MapTiler._parse_json.<locals>.parse_featurer   c                    s   g | ]}ˆ |ƒ‘qS r   r   )Ú.0r#   ©r'   r   r   Ú
<listcomp>X   s    z(MapTiler._parse_json.<locals>.<listcomp>r   )r   ÚjsonÚexactly_oner   r   r)   r   Ú_parse_jsonI   s   zMapTiler._parse_json)r,   r   Ú	proximityÚlanguageÚbboxc                C   sÀ   d| j i}|}|r|  |d¡|d< t|tƒr|g}|r"d |¡|d< |r2t|ƒ}d|j|jf |d< t| 	d¡ƒ}	d	 | j
t|	d
� t|ƒf¡}
t d| jj|
¡ t| j|d�}| j|
||d�S )aŽ  
        Return a location point by address.

        :param str query: The address or query you wish to geocode.

        :param bool exactly_one: Return one result or a list of results, if
            available.

        :param int timeout: Time, in seconds, to wait for the geocoding service
            to respond before raising a :class:`geopy.exc.GeocoderTimedOut`
            exception. Set this only if you wish to override, on this call
            only, the value set during the geocoder's initialization.

        :param proximity: A coordinate to bias local results based on a provided
            location.
        :type proximity: :class:`geopy.point.Point`, list or tuple of ``(latitude,
            longitude)``, or string as ``"%(latitude)s, %(longitude)s"``.

        :param language: Prefer results in specific languages. Accepts
            a single string like ``"en"`` or a list like ``["de", "en"]``.
        :type language: str or list

        :param bbox: The bounding box of the viewport within which
            to bias geocode results more prominently.
            Example: ``[Point(22, 180), Point(-22, -180)]``.
        :type bbox: list or tuple of 2 items of :class:`geopy.point.Point` or
            ``(latitude, longitude)`` or ``"%(latitude)s, %(longitude)s"``.

        :rtype: ``None``, :class:`geopy.location.Location` or a list of them, if
            ``exactly_one=False``.
        Úkeyz#%(lon1)s,%(lat1)s,%(lon2)s,%(lat2)sr0   ú,r/   z%s,%sr.   úutf-8ú?©Úqueryz%s.geocode: %s©r,   ©r   )r   Ú_format_bounding_boxÚ
isinstanceÚstrÚjoinr	   r%   r&   r   Úencoder   Údictr   r
   Údebugr   Ú__name__r   r-   Ú_call_geocoder)r   r6   r,   r   r.   r/   r0   ÚparamsÚpÚquoted_queryÚurlÚcallbackr   r   r   ÚgeocodeZ   s(   
)ÿ
ÿzMapTiler.geocode)r,   r   r/   c          
      C   s”   d| j i}t|tƒr|g}|rd |¡|d< |  |d¡}t| d¡ƒ}d | jt|d� t	|ƒf¡}t
 d| jj|¡ t| j|d	�}	| j||	|d
�S )a  
        Return an address by location point.

        :param query: The coordinates for which you wish to obtain the
            closest human-readable addresses.
        :type query: :class:`geopy.point.Point`, list or tuple of ``(latitude,
            longitude)``, or string as ``"%(latitude)s, %(longitude)s"``.

        :param bool exactly_one: Return one result or a list of results, if
            available.

        :param int timeout: Time, in seconds, to wait for the geocoding service
            to respond before raising a :class:`geopy.exc.GeocoderTimedOut`
            exception. Set this only if you wish to override, on this call
            only, the value set during the geocoder's initialization.

        :param language: Prefer results in specific languages. Accepts
            a single string like ``"en"`` or a list like ``["de", "en"]``.
        :type language: str or list

        :rtype: ``None``, :class:`geopy.location.Location` or a list of them, if
            ``exactly_one=False``.
        r1   r2   r/   z%(lon)s,%(lat)sr3   r4   r5   z%s.reverse: %sr7   r8   )r   r:   r;   r<   Ú_coerce_point_to_stringr   r=   r   r>   r   r
   r?   r   r@   r   r-   rA   )
r   r6   r,   r   r/   rB   ÚpointrD   rE   rF   r   r   r   Úreverseš   s   

ÿzMapTiler.reverse)T)r@   Ú
__module__Ú__qualname__Ú__doc__r   r   r   r-   rG   rJ   Ú__classcell__r   r   r   r   r      s,    ö
4øDúr   N)Ú	functoolsr   Úurllib.parser   r   Úgeopy.geocoders.baser   r   Úgeopy.locationr   Úgeopy.pointr	   Ú
geopy.utilr
   Ú__all__r   r   r   r   r   Ú<module>   s    