
    gu!                     f    d dl Z 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)
    N)partial)	urlencode)DEFAULT_SENTINELGeocoder)Location)logger)Peliasc                   p     e Zd ZdZdZdZ	 deeddedd fdZdedddddd	Zdedd
dZ	d Z
d Z xZS )r	   zPelias geocoder.

    Documentation at:
        https://github.com/pelias/documentation

    See also :class:`geopy.geocoders.GeocodeEarth` which is a Pelias-based
    service provided by the developers of Pelias itself.
    z
/v1/searchz/v1/reverseN)timeoutproxies
user_agentschemessl_contextadapter_factoryc                   t         	|   ||||||       || _        |j                  d      | _        | j
                  d| j                  | j                  | _        | j
                  d| j                  | j                  | _	        y)a%  
        :param str domain: Specify a domain for Pelias API.

        :param str api_key: Pelias API key, optional.

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

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

        :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__api_keystripdomainr   geocode_pathgeocode_apireverse_pathreverse_api)
selfr   r   r   r   r   r   r   r   	__class__s
            V/var/www/api/v1/venv_getwork_v1/lib/python3.12/site-packages/geopy/geocoders/pelias.pyr   zPelias.__init__   s    R 	!#+ 	 	
 ll3'  ;;T5F5FG 	  ;;T5F5FG 	    T)exactly_oner   boundary_rect	countriescountry_biaslanguagec                L   d|i}| j                   r|j                  d| j                   i       |r:| j                  |d      j                  d      \  }	}
}}|	|d<   |
|d<   ||d<   ||d<   |r!t	        j
                  d	t        d
       ||d<   |rdj                  |      |d<   |r||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 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.

        :type boundary_rect: list or tuple of 2 items of :class:`geopy.point.Point`
            or ``(latitude, longitude)`` or ``"%(latitude)s, %(longitude)s"``.
        :param boundary_rect: Coordinates to restrict search within.
            Example: ``[Point(22, 180), Point(-22, -180)]``.

        :param list countries: A list of country codes specified in
            `ISO 3166-1 alpha-2 or alpha-3
            <https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3>`_
            format, e.g. ``['USA', 'CAN']``.
            This is a hard filter.

            .. versionadded:: 2.3

        :param str country_bias: Bias results to this country (ISO alpha-3).

            .. deprecated:: 2.3
                Use ``countries`` instead. This option behaves the same way,
                i.e. it's not a soft filter as the name suggests.
                This parameter is scheduled for removal in geopy 3.0.

        :param str language: Preferred language in which to return results.
            Either uses standard
            `RFC2616 <http://www.ietf.org/rfc/rfc2616.txt>`_
            accept-language string or a simple comma-separated
            list of language codes.

        :rtype: ``None``, :class:`geopy.location.Location` or a list of them, if
            ``exactly_one=False``.
        textr   z#%(lon1)s,%(lat1)s,%(lon2)s,%(lat2)s,zboundary.rect.min_lonzboundary.rect.min_latzboundary.rect.max_lonzboundary.rect.max_latz`country_bias` is deprecated, because it's not a soft filter as the name suggests. Pass a list to the `countries` option instead, which behaves the same way. In geopy 3 the `country_bias` option will be removed.   )
stacklevelzboundary.countrylang?z%s.geocode_api: %sr    r   )r   update_format_bounding_boxsplitwarningswarnDeprecationWarningjoinr   r   r   debugr   __name__r   _parse_json_call_geocoder)r   queryr    r   r!   r"   r#   r$   paramslon1lat1lon2lat2urlcallbacks                  r   geocodezPelias.geocodeU   s;   j %<<MM4<<  %)%>%>D&FFKeCj #D$d.2F*+.2F*+.2F*+.2F*+MMM # *6F%&),))<F%&%F6Nhh(()F*;<=)4>>+B+BCH4++E""3'"BBr   )r    r   r$   c                   	 | j                  |      j                  d      \  }}||d}|r||d<   | j                  r|j	                  d| j                  i       dj                  | j                  t        |      f      }t        j                  d| j                  j                  |       t        | j                  |      }	| j                  ||	|	      S # t        $ r t        d      w xY w)
aZ  
        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 str language: Preferred language in which to return results.
            Either uses standard
            `RFC2616 <http://www.ietf.org/rfc/rfc2616.txt>`_
            accept-language string or a simple comma-separated
            list of language codes.

        :rtype: ``None``, :class:`geopy.location.Location` or a list of them, if
            ``exactly_one=False``.
        r'   z"Must be a coordinate pair or Point)z	point.latz	point.lonr*   r   r+   z%s.reverse: %sr,   r-   )_coerce_point_to_stringr0   
ValueErrorr   r.   r4   r   r   r   r5   r   r6   r   r7   r8   )
r   r9   r    r   r$   latlonr:   r?   r@   s
             r   reversezPelias.reverse   s    B	C33E:@@EHC 

 %F6N<<MM4<<  hh(()F*;<=%t~~'>'>D4++E""3'"BB%  	CABB	Cs   #C C+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name)getr   )r   featurelatitude	longitude	placenames        r   _parse_codezPelias._parse_code   su    ;;z2.22="EaHKK
B/33M2FqI	KKb155f=		Hi#8'BBr   c                     |y |d   }t        |      sy |r| j                  |d         S |D cg c]  }| j                  |       c}S c c}w )Nfeaturesr   )lenrS   )r   responser    rU   rO   s        r   r7   zPelias._parse_json   sZ    J'8}##HQK00=EFX'D$$W-XFFFs   A
)N)r6   
__module____qualname____doc__r   r   r   r   rA   rG   rS   r7   __classcell__)r   s   @r   r	   r	      sr      L L
 :

 %$( :
@ $XC| $5CnC	Gr   r	   )r1   	functoolsr   urllib.parser   geopy.geocoders.baser   r   geopy.locationr   
geopy.utilr   __all__r	    r   r   <module>rc      s,      " ; # 
jGX jGr   