
    g                     ^    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e      Zy	)
    )partial)	urlencode)DEFAULT_SENTINELGeocoder)Location)logger)	BANFrancec                   f     e Zd ZdZdZdZddeededd fd
Zdded	d
ZdeddZ	d Z
d Z x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                   t         |   ||||||       |j                  d      | _        | j                  d| j                  | j
                  | _        | j                  d| j                  | j                  | _        y)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://N)	super__init__stripr   r   geocode_pathgeocode_apireverse_pathreverse_api)	selfr   r   r   r   r   r   r   	__class__s	           Y/var/www/api/v1/venv_getwork_v1/lib/python3.12/site-packages/geopy/geocoders/banfrance.pyr   zBANFrance.__init__   s    L 	!#+ 	 	
 ll3'  ;;T5F5FG 	  ;;T5F5FG 	    T)limitexactly_oner   c                   d|i}|||d<   dj                  | j                  t        |      f      }t        j                  d| j
                  j                  |       t        | j                  |      }| j                  |||      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``.

        qr   ?z%s.geocode: %sr    r   )
joinr   r   r   debugr   __name__r   _parse_json_call_geocoder)r   queryr   r    r   paramsurlcallbacks           r   geocodezBANFrance.geocodeL   s    @ 
 #F7Ohh(()F*;<=%t~~'>'>D4++E""3'"BBr   )r    r   c                |   	 | j                  |      j                  d      \  }}||d}dj                  | j                  t        |      f      }t        j                  d| j                  j                  |       t        | j                  |      }| j                  |||      S # t        $ r t        d      w xY w)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   r2   r3   r,   r-   r.   s	            r   reversezBANFrance.reversex   s    8	C33E:@@EHC
 

 hh(()F*;<=%t~~'>'>D4++E""3'"BB  	CABB	Cs   #B& &B;c                     |j                  di       j                  dg       d   }|j                  di       j                  dg       d   }|j                  di       j                  d      }t        |||f|      S )Ngeometrycoordinates   r   
propertieslabel)getr   )r   featurelatitude	longitude	placenames        r   _parse_featurezBANFrance._parse_feature   su    ;;z2.22="EaHKK
B/33M2FqI	KKb155g>		Hi#8'BBr   c                     |d|vry |d   }t        |      sy |r| j                  |d         S |D cg c]  }| j                  |       c}S c c}w )Nfeaturesr   )lenrC   )r   responser    rE   r?   s        r   r)   zBANFrance._parse_json   sa    z9J'8}&&x{33@HIWD''0IIIs   A)r(   
__module____qualname____doc__r   r   r   r   r/   r7   rC   r)   __classcell__)r   s   @r   r	   r	      s^     LL
 .$$( 5
v $*C` $)CVC	Jr   r	   N)	functoolsr   urllib.parser   geopy.geocoders.baser   r   geopy.locationr   
geopy.utilr   __all__r	    r   r   <module>rS      s)     " ; # 
iJ iJr   