o
    ÔèFhÒ  ã                   @   sX   d dl mZ d dlmZ d dlmZmZ d dlmZ d dl	m
Z
 dZG dd„ deƒZd	S )
é    )Úpartial)Ú	urlencode)ÚDEFAULT_SENTINELÚGeocoder)ÚLocation)Úlogger)Ú	BANFrancec                       sl   e Zd ZdZdZdZddeededdœ‡ fdd„
Zdd	ed
œdd„Zd	edœdd„Z	dd„ Z
dd„ Z‡  ZS )r   zzGeocoder using the Base Adresse Nationale France API.

    Documentation at:
        https://adresse.data.gouv.fr/api
    z/searchz/reversezapi-adresse.data.gouv.frN)ÚdomainÚschemeÚtimeoutÚproxiesÚ
user_agentÚssl_contextÚadapter_factoryc                   sT   t ƒ j||||||d� | d¡| _d| j| j| jf | _d| j| j| jf | _dS )a/  

        :param str domain: Currently it is ``'api-adresse.data.gouv.fr'``, can
            be changed for testing purposes.

        :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

        )r
   r   r   r   r   r   ú/z	%s://%s%sN)	ÚsuperÚ__init__Ústripr	   r
   Úgeocode_pathÚgeocode_apiÚreverse_pathÚreverse_api)Úselfr	   r
   r   r   r   r   r   ©Ú	__class__© úR/var/www/html/loop/nvenv/lib/python3.10/site-packages/geopy/geocoders/banfrance.pyr      s   &úÿÿzBANFrance.__init__T)ÚlimitÚexactly_oner   c                C   s\   d|i}|dur||d< d  | j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 int limit: Defines the maximum number of items in the
            response structure. If not provided and there are multiple
            results the BAN API will return 5 results by default.
            This will be reset to one if ``exactly_one`` is True.

        :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``.

        ÚqNr   ú?z%s.geocode: %s©r   ©r   )
Újoinr   r   r   Údebugr   Ú__name__r   Ú_parse_jsonÚ_call_geocoder)r   Úqueryr   r   r   ÚparamsÚurlÚcallbackr   r   r   ÚgeocodeL   s    ÿzBANFrance.geocode)r   r   c          	      C   s~   z|   |¡ d¡\}}W n ty   tdƒ‚w ||dœ}d | jt|ƒf¡}t d| jj	|¡ t
| j|d�}| j|||d�S )aM  
        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``.

        ú,z"Must be a coordinate pair or Point)ÚlatÚlonr    z%s.reverse: %sr!   r"   )Ú_coerce_point_to_stringÚsplitÚ
ValueErrorr#   r   r   r   r$   r   r%   r   r&   r'   )	r   r(   r   r   r.   r/   r)   r*   r+   r   r   r   Úreversex   s   ÿþzBANFrance.reversec                 C   sR   |  di ¡  dg ¡d }|  di ¡  dg ¡d }|  di ¡  d¡}t|||f|ƒS )NÚgeometryÚcoordinatesé   r   Ú
propertiesÚlabel)Úgetr   )r   ÚfeatureÚlatitudeÚ	longitudeÚ	placenamer   r   r   Ú_parse_feature£   s   zBANFrance._parse_featurec                    sL   |d u sd|vr
d S |d }t |ƒsd S |rˆ  |d ¡S ‡ fdd„|D ƒS )NÚfeaturesr   c                    s   g | ]}ˆ   |¡‘qS r   )r>   )Ú.0r:   ©r   r   r   Ú
<listcomp>´   s    z)BANFrance._parse_json.<locals>.<listcomp>)Úlenr>   )r   Úresponser   r?   r   rA   r   r&   «   s   zBANFrance._parse_json)r%   Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r,   r3   r>   r&   Ú__classcell__r   r   r   r   r      s*    ÷;ú0û+r   N)Ú	functoolsr   Úurllib.parser   Úgeopy.geocoders.baser   r   Úgeopy.locationr   Ú
geopy.utilr   Ú__all__r   r   r   r   r   Ú<module>   s    