a
    }cu!                     @   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                       st   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   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          	         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__ R/var/www/html/django/DPS/env/lib/python3.9/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< |rxtjd	td
d ||d< |rd||d< |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 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   updateZ_format_bounding_boxsplitwarningswarnDeprecationWarningjoinr   r   r   debugr   __name__r   _parse_json_call_geocoder)r   queryr   r	   r   r    r!   r"   paramsZlon1Zlat1Zlon2Zlat2urlcallbackr   r   r   geocodeU   s<    5zPelias.geocode)r   r	   r"   c          
      C   s   z|  |d\}}W n ty2   tdY n0 ||d}|rJ||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*   )Z_coerce_point_to_stringr,   
ValueErrorr   r+   r0   r   r   r   r1   r   r2   r   r3   r4   )
r   r5   r   r	   r"   ZlatZlonr6   r7   r8   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 )NZgeometryZcoordinates   r   
propertiesname)getr   )r   featureZlatitudeZ	longitudeZ	placenamer   r   r   _parse_code   s    zPelias._parse_codec                    sH   |d u rd S |d }t |s d S |r2 |d S  fdd|D S d S )Nfeaturesr   c                    s   g | ]}  |qS r   )rA   ).0r@   r   r   r   
<listcomp>       z&Pelias._parse_json.<locals>.<listcomp>)lenrA   )r   responser   rB   r   rD   r   r3      s    zPelias._parse_json)N)r2   
__module____qualname____doc__r   r   r   r   r9   r;   rA   r3   __classcell__r   r   r   r   r      s2   	 @^7r   )r-   	functoolsr   urllib.parser   Zgeopy.geocoders.baser   r   Zgeopy.locationr   Z
geopy.utilr   __all__r   r   r   r   r   <module>   s   