o
    4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   zMapzen 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__ L/var/www/html/gps/gps/lib/python3.10/site-packages/geopy/geocoders/mapzen.pyr      s   
/zMapzen.__init__Tc                 C   s   d| j | i}| jr|d| ji | jr1| jd |d< | jd |d< | jd |d< | jd	 |d
< | jr9| 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w ||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"   )_coerce_point_to_stringsplit
ValueErrorr   r#   r$   r   r   r   r%   r   r&   r'   r(   )r   r)   r*   r
   lat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 )Ngeometrycoordinatesr   r   
propertiesname)getr   )featurelatitude	longitude	placenamer   r   r   
parse_code   s   zMapzen.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   )rA   )r.   r=   r   r   r   r0      s    z&Mapzen._parse_json.<locals>.<listcomp>)lenrA   )r   responser*   rB   r   rC   r   r'      s   zMapzen._parse_json)r&   
__module____qualname____doc__r   r   r-   r7   staticmethodrA   r'   __classcell__r   r   r   r   r      s,    B
0
0
r   N)rH   geopy.compatr   geopy.geocoders.baser   r   geopy.locationr   
geopy.utilr   __all__r   r   r   r   r   <module>   s    