
    g                     V    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e      Zy	)
z<
Mapzen geocoder, contributed by Michal Migurski of Mapzen.
    )	urlencode)DEFAULT_SENTINELGeocoder)Location)logger)Mapzenc            
       f     e Zd ZdZddddeedddef
 fd	ZdefdZdefdZed        Z	d	 Z
 x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                    t         t        |   ||	||||
       || _        || _        || _        |j                  d      | _        | j                  d| j                  d| _	        | j                  d| j                  d| _
        y)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://z
/v1/searchz/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__s              V/var/www/api/v1/venv_getwork_v1/lib/python3.12/site-packages/geopy/geocoders/mapzen.pyr   zMapzen.__init__   s    ^ 	fd$'!# 	% 	
 )*ll3'26++t{{K37;;L    Tc                 <   d| j                   |z  i}| j                  r|j                  d| j                  i       | j                  rH| j                  d   |d<   | j                  d   |d<   | j                  d   |d<   | j                  d	   |d
<   | j                  r| j                  |d<   dj                  | j                  t        |      f      }t        j                  d| j                  j                  |       | j                  | j                  ||      |      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urls         r   geocodezMapzen.geocodeW   s   . $,,u45<<MM4<<  .2.@.@.CF*+.2.@.@.CF*+.2.@.@.CF*+.2.@.@.CF*+)-):):F%&hh(()F*;<=)4>>+B+BCHW5{
 	
r   c                     	 | j                  |      j                  d      D cg c]  }|j                          c}\  }}||d}| j                  r|j                  d| j                  i       dj                  | j                  t        |      f      }t        j                  d| j                  j                  |       | j                  | j                  ||      |      S c c}w # t        $ r t        d      w xY w)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``.
        ,z"Must be a coordinate pair or Point)z	point.latz	point.lonr   r$   z%s.reverse: %sr%   )_coerce_point_to_stringsplitr   
ValueErrorr   r&   r'   r   r   r   r(   r   r)   r*   r+   )	r   r,   r-   r   xlatlonr.   r/   s	            r   reversezMapzen.reverse   s    2	C ,,U399#>>  	>HC 

 <<MM4<<  hh(()F*;<=%t~~'>'>DW5{
 	
%  	CABB	Cs   "C( C#C( #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coordinatesr!   r   
propertiesname)getr   )featurelatitude	longitude	placenames       r   
parse_codezMapzen.parse_code   sw     ;;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   )lenrD   )r   responser-   rF   r@   s        r   r*   zMapzen._parse_json   sV    J'8}??8A;//<DEHDOOG,HEEEs   A
)r)   
__module____qualname____doc__r   r   r0   r9   staticmethodrD   r*   __classcell__)r   s   @r   r   r      sg     $$&(=MD $	+
` $	.
` C C	Fr   r   N)rK   geopy.compatr   geopy.geocoders.baser   r   geopy.locationr   
geopy.utilr   __all__r    r   r   <module>rT      s-    # ; # 
yFX yFr   