o
    ÔèFhu!  ã                   @   s`   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	„ d	eƒZdS )
é    N)Úpartial)Ú	urlencode)ÚDEFAULT_SENTINELÚGeocoder)ÚLocation)Úlogger)ÚPeliasc                       sv   e Zd ZdZdZdZ	deeddeddœ‡ fdd„Zdeddddd	œd
d„Zdeddœdd„Z	dd„ Z
dd„ Z‡  ZS )r   záPelias 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          	         sZ   t ƒ j||||||d� || _| d¡| _d| j| j| jf | _d| j| j| jf | _	dS )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	%s://%s%sN)
ÚsuperÚ__init__Úapi_keyÚstripÚdomainr   Úgeocode_pathÚgeocode_apiÚreverse_pathÚreverse_api)	Úselfr   r   r	   r
   r   r   r   r   ©Ú	__class__© úO/var/www/html/loop/nvenv/lib/python3.10/site-packages/geopy/geocoders/pelias.pyr      s   )ú	ÿÿzPelias.__init__T)Úexactly_oner	   Úboundary_rectÚ	countriesÚcountry_biasÚlanguagec                C   sÚ   d|i}| j r| d| j i¡ |r.|  |d¡ d¡\}	}
}}|	|d< |
|d< ||d< ||d< |r<tjd	td
d� ||d< |rEd |¡|d< |rK||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 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Úcallbackr   r   r   ÚgeocodeU   s<   5ÿÿ
ÿúzPelias.geocode)r   r	   r"   c          
      C   s    z|   |¡ d¡\}}W n ty   tdƒ‚w ||dœ}|r#||d< | jr.| d| ji¡ d | jt|ƒf¡}t 	d| j
j|¡ t| j|d�}	| j||	|d	�S )
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_stringr-   Ú
ValueErrorr   r+   r1   r   r   r   r2   r   r3   r   r4   r5   )
r   r6   r   r	   r"   ÚlatÚlonr7   r<   r=   r   r   r   Úreverse¯   s$   !ÿþÿzPelias.reversec                 C   sR   |  di ¡  dg ¡d }|  di ¡  dg ¡d }|  di ¡  d¡}t|||f|ƒS )NÚgeometryÚcoordinatesé   r   Ú
propertiesÚname)Úgetr   )r   ÚfeatureÚlatitudeÚ	longitudeÚ	placenamer   r   r   Ú_parse_codeæ   s   zPelias._parse_codec                    sD   |d u rd S |d }t |ƒsd S |rˆ  |d ¡S ‡ fdd„|D ƒS )NÚfeaturesr   c                    s   g | ]}ˆ   |¡‘qS r   )rN   )Ú.0rJ   ©r   r   r   Ú
<listcomp>ö   s    z&Pelias._parse_json.<locals>.<listcomp>)ÚlenrN   )r   Úresponser   rO   r   rQ   r   r4   í   s   zPelias._parse_json)N)r3   Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r>   rC   rN   r4   Ú__classcell__r   r   r   r   r      s4    	ýö@÷^ú7r   )r.   Ú	functoolsr   Úurllib.parser   Úgeopy.geocoders.baser   r   Úgeopy.locationr   Ú
geopy.utilr   Ú__all__r   r   r   r   r   Ú<module>   s    