a
    î}cÇ  ã                   @   sP   d 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 )
z<
Mapzen geocoder, contributed by Michal Migurski of Mapzen.
é    )Ú	urlencode)ÚDEFAULT_SENTINELÚGeocoder)ÚLocation)Úlogger)ÚMapzenc                
       sf   e Zd ZdZddddeedddef
‡ fdd„	Zdefdd„Zdefd	d
„Zedd„ ƒZ	dd„ Z
‡  ZS )r   zðMapzen Search geocoder.

    Documentation at:
        https://mapzen.com/documentation/search/

    .. warning::
       Please note that Mapzen has shut down their API so this geocoder
       class might be removed in future releases.
    Nzsearch.mapzen.comc                    sb   t t| ƒj||	||||
d || _|| _|| _| d¡| _d| j| jf | _	d| j| jf | _
dS )a(  
        :param str api_key: Mapzen API key, optional.

        :param str format_string:
            See :attr:`geopy.geocoders.options.default_format_string`.

        :param tuple boundary_rect: Coordinates to restrict search within,
            given as (west, south, east, north) coordinate tuple.

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

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

            .. versionadded:: 1.12.0

        :param str domain: Specify a custom domain for Mapzen API.

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

            .. versionadded:: 1.14.0

        )Úformat_stringÚschemeÚtimeoutÚproxiesÚ
user_agentÚssl_contextú/z%s://%s/v1/searchz%s://%s/v1/reverseN)Úsuperr   Ú__init__Úcountry_biasÚboundary_rectÚapi_keyÚstripÚdomainr	   Úgeocode_apiÚreverse_api)Úselfr   r   r   r   r
   r   r   r   r	   r   ©Ú	__class__© úR/var/www/html/django/DPS/env/lib/python3.9/site-packages/geopy/geocoders/mapzen.pyr      s    /
úzMapzen.__init__Tc                 C   s®   d| j | i}| jr$| d| ji¡ | jrb| jd |d< | jd |d< | jd |d< | jd	 |d
< | jrr| j|d< d | jt|ƒf¡}t 	d| j
j|¡ |  | j||d|¡S )aª  
        Return a location point by address.

        :param str query: The address, query or structured query to geocode
            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.

        :rtype: ``None``, :class:`geopy.location.Location` or a list of them, if
            ``exactly_one=False``.
        Útextr   r   zboundary.rect.min_loné   zboundary.rect.min_laté   zboundary.rect.max_loné   zboundary.rect.max_latzboundary.countryú?z%s.geocode_api: %s©r
   )r   r   Úupdater   r   Újoinr   r   r   Údebugr   Ú__name__Ú_parse_jsonÚ_call_geocoder)r   ÚqueryÚexactly_oner
   ÚparamsÚurlr   r   r   ÚgeocodeW   s"    ÿ
ÿzMapzen.geocodec                 C   sš   z"dd„ |   |¡ d¡D ƒ\}}W n ty<   tdƒ‚Y n0 ||dœ}| jr^| d| ji¡ d | jt|ƒf¡}t 	d| j
j|¡ |  | j||d	|¡S )
aL  
        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``.
        c                 S   s   g | ]}|  ¡ ‘qS r   )r   )Ú.0Úxr   r   r   Ú
<listcomp>ž   s   z"Mapzen.reverse.<locals>.<listcomp>ú,z"Must be a coordinate pair or Point)z	point.latz	point.lonr   r!   z%s.reverse: %sr"   )Z_coerce_point_to_stringÚsplitÚ
ValueErrorr   r#   r$   r   r   r   r%   r   r&   r'   r(   )r   r)   r*   r
   ZlatZlonr+   r,   r   r   r   Úreverse„   s$    þþÿÿzMapzen.reversec                 C   sR   |   di ¡  dg ¡d }|   di ¡  dg ¡d }|   di ¡  d¡}t|||f| ƒS )NZgeometryZcoordinatesr   r   Ú
propertiesÚname)Úgetr   )ÚfeatureZlatitudeZ	longitudeZ	placenamer   r   r   Ú
parse_code´   s    zMapzen.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   )r9   )r.   r8   ©r   r   r   r0   Æ   ó    z&Mapzen._parse_json.<locals>.<listcomp>)Úlenr9   )r   Úresponser*   r:   r   r;   r   r'   ½   s    zMapzen._parse_json)r&   Ú
__module__Ú__qualname__Ú__doc__r   r   r-   r4   Ústaticmethodr9   r'   Ú__classcell__r   r   r   r   r      s*   õBü
0ü
0
r   N)rA   Zgeopy.compatr   Zgeopy.geocoders.baser   r   Zgeopy.locationr   Z
geopy.utilr   Ú__all__r   r   r   r   r   Ú<module>   s   