o
    4c5                     @   sh   d dl mZ d dlmZ d dlmZ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 )    )partial)	urlencode)GeocoderParseErrorGeocoderServiceError)DEFAULT_SENTINELGeocoder)Location)logger)Yandexc                       sb   e Zd ZdZdZeeddedd fdd
Zdeddd	d
ZdedddddZdd Z	  Z
S )r
   zYandex geocoder.

    Documentation at:
        https://tech.yandex.com/maps/doc/geocoder/desc/concepts/input_params-docpage/
    z/1.x/N)timeoutproxies
user_agentschemessl_contextadapter_factoryc          	         s:   t  j||||||d || _d}d| j|| jf | _dS )a1  

        :param str api_key: Yandex API key, mandatory.
            The key can be created at https://developer.tech.yandex.ru/

        :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geocode-maps.yandex.ruz	%s://%s%sN)super__init__api_keyr   api_pathapi)	selfr   r   r   r   r   r   r   domain	__class__ L/var/www/html/gps/gps/lib/python3.10/site-packages/geopy/geocoders/yandex.pyr      s   %zYandex.__init__T)exactly_oner   langc                C   sp   |dd}| j |d< |r||d< |rd|d< d| jt|f}td| jj| t| j	|d	}| j
|||d
S )aC  
        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.

        :param str lang: Language of the response and regional settings
            of the map. List of supported values:

            - ``tr_TR`` -- Turkish (only for maps of Turkey);
            - ``en_RU`` -- response in English, Russian map features;
            - ``en_US`` -- response in English, American map features;
            - ``ru_RU`` -- Russian (default);
            - ``uk_UA`` -- Ukrainian;
            - ``be_BY`` -- Belarusian.

        :rtype: ``None``, :class:`geopy.location.Location` or a list of them, if
            ``exactly_one=False``.
        jsongeocodeformatapikeyr      results?z%s.geocode: %sr   r   )r   joinr   r   r	   debugr   __name__r   _parse_json_call_geocoder)r   queryr   r   r   paramsurlcallbackr   r   r   r    F   s   #
zYandex.geocode)r   r   kindr   c          
      C   s   z|  |d}W n ty   tdw |dd}| j|d< |r$||d< |r*||d< d| jt|f}td	| jj	| t
| j|d
}	| j||	|dS )a  
        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 kind: Type of toponym. Allowed values: `house`, `street`, `metro`,
            `district`, `locality`.

        :param str lang: Language of the response and regional settings
            of the map. List of supported values:

            - ``tr_TR`` -- Turkish (only for maps of Turkey);
            - ``en_RU`` -- response in English, Russian map features;
            - ``en_US`` -- response in English, American map features;
            - ``ru_RU`` -- Russian (default);
            - ``uk_UA`` -- Ukrainian;
            - ``be_BY`` -- Belarusian.

        :rtype: ``None``, :class:`geopy.location.Location` or a list of them, if
            ``exactly_one=False``.
        z%(lon)s,%(lat)sz"Must be a coordinate pair or Pointr   r   r"   r   r1   r%   z%s.reverse: %sr&   r'   )_coerce_point_to_string
ValueErrorr   r(   r   r   r	   r)   r   r*   r   r+   r,   )
r   r-   r   r   r1   r   pointr.   r/   r0   r   r   r   reversev   s"   *
zYandex.reversec                    s   | drt|d d z
|d d d }W n ty"   tdw dd  |r;z |d	 W S  ty:   Y d
S w  fdd|D S )z+
        Parse JSON response body.
        errormessageresponseGeoObjectCollectionfeatureMemberFailed to parse server responsec                    st   z d  W n t y   tdw dd  d d dD \}}dd	g}d
 fdd|D }t|||f S )z,
            Parse each record.
            	GeoObjectr;   c                 s   s    | ]}t |V  qd S )N)float).0_r   r   r   	<genexpr>   s    
z9Yandex._parse_json.<locals>.parse_code.<locals>.<genexpr>Pointpos namedescriptionz, c                    s   g | ]}  |r | qS r   )get)r>   kplacer   r   
<listcomp>   s    z:Yandex._parse_json.<locals>.parse_code.<locals>.<listcomp>)KeyErrorr   splitr(   r   )rI   	longitudelatitudename_elementslocationr   rH   r   
parse_code   s   
z&Yandex._parse_json.<locals>.parse_coder   Nc                    s   g | ]} |qS r   r   )r>   rI   rQ   r   r   rJ      s    z&Yandex._parse_json.<locals>.<listcomp>)rF   r   rK   r   
IndexError)r   docr   placesr   rR   r   r+      s   
zYandex._parse_json)r*   
__module____qualname____doc__r   r   r   r    r5   r+   __classcell__r   r   r   r   r
      s(    54<r
   N)	functoolsr   urllib.parser   	geopy.excr   r   geopy.geocoders.baser   r   geopy.locationr   
geopy.utilr	   __all__r
   r   r   r   r   <module>   s    