a
    }c                     @   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__ U/var/www/html/django/DPS/env/lib/python3.9/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y2   tdY n0 ||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"   )Z_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 )NZgeometryZcoordinates   r   
propertieslabel)getr   )r   featureZlatitudeZ	longitudeZ	placenamer   r   r   _parse_feature   s    zBANFrance._parse_featurec                    sP   |d u sd|vrd S |d }t |s(d S |r: |d S  fdd|D S d S )Nfeaturesr   c                    s   g | ]}  |qS r   )r8   ).0r7   r   r   r   
<listcomp>       z)BANFrance._parse_json.<locals>.<listcomp>)lenr8   )r   responser   r9   r   r;   r   r&      s    zBANFrance._parse_json)r%   
__module____qualname____doc__r   r   r   r   r,   r2   r8   r&   __classcell__r   r   r   r   r      s(   ;0+r   N)	functoolsr   urllib.parser   Zgeopy.geocoders.baser   r   Zgeopy.locationr   Z
geopy.utilr   __all__r   r   r   r   r   <module>   s   