o
    ÔèFhv  ã                   @   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)ÚMapBoxc                	       sj   e Zd ZdZdZdeededdddœ‡ fdd„
Zdd	d
„Zdedddddœdd„Zdedœdd„Z	‡  Z
S )r   zlGeocoder using the Mapbox API.

    Documentation at:
        https://www.mapbox.com/api-documentation/
    z+/geocoding/v5/mapbox.places/%(query)s.json/Nzapi.mapbox.com)ÚschemeÚtimeoutÚproxiesÚ
user_agentÚssl_contextÚadapter_factoryÚdomainÚrefererc          
         sV   t ƒ j||||||d� || _| d¡| _d| j| j| jf | _|	r)|	| jd< dS dS )aF  
        :param str api_key: The API key required by Mapbox to perform
            geocoding requests. API keys are managed through Mapox's account
            page (https://www.mapbox.com/account/access-tokens).

        :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 mapbox

        :param str referer: The URL used to satisfy the URL restriction of
            mapbox tokens.

            .. versionadded:: 2.3
        )r   r   r   r   r   r   ú/z	%s://%s%sÚRefererN)	ÚsuperÚ__init__Úapi_keyÚstripr   r   Úapi_pathÚapiÚheaders)
Úselfr   r   r   r   r   r   r   r   r   ©Ú	__class__© úO/var/www/html/loop/nvenv/lib/python3.10/site-packages/geopy/geocoders/mapbox.pyr      s   .úÿzMapBox.__init__Tc                    s>   |d }|g kr
dS dd„ ‰ |rˆ |d ƒS ‡ fdd„|D ƒS )z7Returns location, (latitude, longitude) from json feed.ÚfeaturesNc                 S   s8   | d }| d d d }| d d d }t |||f| ƒS )NÚ
place_nameÚgeometryÚcoordinatesr   é   r   )ÚfeatureÚlocationÚ	longitudeÚlatituder    r    r!   Úparse_featureW   s   z)MapBox._parse_json.<locals>.parse_featurer   c                    s   g | ]}ˆ |ƒ‘qS r    r    )Ú.0r'   ©r+   r    r!   Ú
<listcomp>_   s    z&MapBox._parse_json.<locals>.<listcomp>r    )r   ÚjsonÚexactly_oner"   r    r-   r!   Ú_parse_jsonQ   s   zMapBox._parse_json)r0   r   Ú	proximityÚcountryÚlanguageÚbboxc                C   sÔ   i }| j |d< |r|  |d¡|d< |sg }t|tƒr|g}|r&d |¡|d< |r6t|ƒ}	d|	j|	jf |d< |r<||d< t| 	d	¡ƒ}
d
 | j
t|
d� t|ƒf¡}t d| jj|¡ t| j|d�}| j|||d�S )u$  
        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 country: Country to filter result in form of
            ISO 3166-1 alpha-2 country code (e.g. ``FR``).
            Might be a Python list of strings.

        :type country: str or list

        :param str language: This parameter controls the language of the text supplied in
            responses, and also affects result scoring, with results matching the userâ€™s
            query in the requested language being preferred over results that match in
            another language. You can pass two letters country codes (ISO 639-1).

            .. versionadded:: 2.3

        :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``.
        Úaccess_tokenz#%(lon1)s,%(lat1)s,%(lon2)s,%(lat2)sr5   ú,r3   z%s,%sr2   r4   úutf-8ú?©Úqueryz%s.geocode: %s©r0   ©r   )r   Ú_format_bounding_boxÚ
isinstanceÚstrÚjoinr	   r)   r*   r   Úencoder   Údictr   r
   Údebugr   Ú__name__r   r1   Ú_call_geocoder)r   r;   r0   r   r2   r3   r4   r5   ÚparamsÚpÚquoted_queryÚurlÚcallbackr    r    r!   Úgeocodea   s0   3
ÿ
ÿzMapBox.geocode)r0   r   c          	      C   sv   i }| j |d< |  |d¡}t| d¡ƒ}d | jt|d� t|ƒf¡}t 	d| j
j|¡ t| j|d�}| j|||d�S )	aL  
        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.

        :rtype: ``None``, :class:`geopy.location.Location` or a list of them, if
            ``exactly_one=False``.
        r6   z%(lon)s,%(lat)sr8   r9   r:   z%s.reverse: %sr<   r=   )r   Ú_coerce_point_to_stringr   rB   rA   r   rC   r   r
   rD   r   rE   r   r1   rF   )	r   r;   r0   r   rG   ÚpointrI   rJ   rK   r    r    r!   Úreverse°   s   
ÿzMapBox.reverse)T)rE   Ú
__module__Ú__qualname__Ú__doc__r   r   r   r1   rL   rO   Ú__classcell__r    r    r   r!   r      s.    õ
<÷Sûr   N)Ú	functoolsr   Úurllib.parser   r   Úgeopy.geocoders.baser   r   Úgeopy.locationr   Úgeopy.pointr	   Ú
geopy.utilr
   Ú__all__r   r    r    r    r!   Ú<module>   s    