
    g                     n    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	e	      Zy
)    )partial)	urlencode)GeocoderParseErrorGeocoderServiceError)DEFAULT_SENTINELGeocoder)Location)logger)Yandexc                   `     e Zd ZdZdZeeddeddd fd
Zdeddd	Zdeddd
dZd Z	 xZ
S )r   zYandex geocoder.

    Documentation at:
        https://tech.yandex.com/maps/doc/geocoder/desc/concepts/input_params-docpage/
    z/1.x/Nzgeocode-maps.yandex.ru)timeoutproxies
user_agentschemessl_contextadapter_factorydomainc                    t         	|   ||||||       || _        | j                  d|| j                  | _        y)a  

        :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

        :param str domain: base api domain

            .. versionadded:: 2.4
        )r   r   r   r   r   r   z://N)super__init__api_keyr   api_pathapi)
selfr   r   r   r   r   r   r   r   	__class__s
            V/var/www/api/v1/venv_getwork_v1/lib/python3.12/site-packages/geopy/geocoders/yandex.pyr   zYandex.__init__   sI    T 	!#+ 	 	
 "&++vt}}E    T)exactly_oner   langc                >   |dd}| j                   |d<   |r||d<   |rd|d<   dj                  | j                  t        |      f      }t	        j
                  d| j                  j                  |       t        | j                  |	      }| j                  |||
      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callbacks           r   r#   zYandex.geocodeJ   s    F 
  <<x!F6N !F9hh)F"345%t~~'>'>D4++E""3'"BBr   )r   r   kindr   c                   	 | j                  |d      }|dd}| j                  |d<   |r||d<   |r||d<   dj                  | j                  t        |      f      }t        j                  d	| j                  j                  |       t        | j                  |
      }	| j                  ||	|      S # t        $ r t        d      w xY w)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   r4   r(   z%s.reverse: %sr)   r*   )_coerce_point_to_string
ValueErrorr   r+   r   r   r
   r,   r   r-   r   r.   r/   )
r   r0   r   r   r4   r   pointr1   r2   r3   s
             r   reversezYandex.reversez   s    T	C008IJE 
  <<x!F6N!F6Nhh)F"345%t~~'>'>D4++E""3'"BB  	CABB	Cs   B2 2Cc                    |j                  d      rt        |d   d         	 |d   d   d   }d }|r	  ||d         S |D cg c]
  } ||       c}S # t        $ r t        d      w xY w# t        $ r Y y	w xY wc c}w )
z+
        Parse JSON response body.
        errormessageresponseGeoObjectCollectionfeatureMemberFailed to parse server responsec                    	 | d   } d | d   d   j                  d      D        \  }}ddg}d	j                  |D cg c]  }| j	                  |      s| |    c}      }t        |||f|       S # t         $ r t        d      w xY wc c}w )
z,
            Parse each record.
            	GeoObjectr@   c              3   2   K   | ]  }t        |        y w)N)float).0_s     r   	<genexpr>z9Yandex._parse_json.<locals>.parse_code.<locals>.<genexpr>   s      #"BQa"Bs   Pointpos namedescriptionz, )KeyErrorr   splitr+   getr	   )place	longitudelatitudename_elementsklocations         r   
parse_codez&Yandex._parse_json.<locals>.parse_code   s    Lk*#"'."7"="=c"B#Ix $]3MyyM!RMqUYYq\%(M!RSHHx&;UCC  L()JKKL "Ss   A/ BB/Br   N)rO   r   rM   r   
IndexError)r   docr   placesrV   rP   s         r   r.   zYandex._parse_json   s     777&s7|I'>??	H_%:;OLF	D$ !&),, 4::6%Ju%6::7  	H$%FGG	H0   ;s"   A 
A. A=A+.	A:9A:)r-   
__module____qualname____doc__r   r   r   r#   r9   r.   __classcell__)r   s   @r   r   r      sY     H %$( +3Fr $.Ch $:Cx$;r   r   N)	functoolsr   urllib.parser   	geopy.excr   r   geopy.geocoders.baser   r   geopy.locationr	   
geopy.utilr
   __all__r    r   r   <module>rf      s*     " > ; # 
N;X N;r   