
    g                     z    d dl mZ d dlmZ d dlmZmZmZ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)GeocoderAuthenticationFailureGeocoderQueryErrorGeocoderQuotaExceededGeocoderServiceErrorGeocoderUnavailable)DEFAULT_SENTINELGeocoder)Location)logger)Geokeoc                   h     e Zd ZdZdZdZddeededd fd
Zdded	d
ZdeddZ	ddZ
d Z xZS )r   zGeocoder using the geokeo API.

    Documentation at:
        https://geokeo.com/documentation.php

    .. versionadded:: 2.4
    z/geocode/v1/search.phpz/geocode/v1/reverse.phpz
geokeo.comN)domainschemetimeoutproxies
user_agentssl_contextadapter_factoryc                   t         	|   ||||||       || _        |j                  d      | _        | j
                  d| j                  | j                  | _        | j
                  d| j                  | j                  | _	        y)a  

        :param str api_key: The API key required by Geokeo.com
            to perform geocoding requests. You can get your key here:
            https://geokeo.com/

        :param str domain: Domain where the target Geokeo service
            is hosted.

        :param str scheme:
            See :attr:`geopy.geocoders.options.default_scheme`.

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

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

        )r   r   r   r   r   r   /z://N)
super__init__api_keystripr   r   geocode_pathapireverse_pathreverse_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/geokeo.pyr   zGeokeo.__init__   s|    R 	!#+ 	 	
 ll3'"&++t{{D<M<MN*.++t{{DDUDUV    T)countryexactly_oner   c                &   | j                   |d}|r||d<   dj                  | j                  t        |      f      }t	        j
                  d| j                  j                  |       t        | j                  |      }| j                  |||      S )aJ  
        Return a location point by address.

        :param str query: The address or query you wish to geocode.

        :param str country: Restricts the results to the specified
            country. The country code is a 2 character code as
            defined by the ISO 3166-1 Alpha 2 standard (e.g. ``us``).

        :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``.
        )r   qr%   ?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#   geocodezGeokeo.geocodeU   s    : <<

  'F9hh)F"345%t~~'>'>D4++E""3'"BBr$   )r&   r   c                   	 | j                  |      j                  d      \  }}| j                  ||d}dj	                  | j
                  t        |      f      }t        j                  d| j                  j                  |       t        | j                  |      }| j                  |||      S # 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)r   latlngr)   z%s.reverse: %sr*   r+   )_coerce_point_to_stringsplit
ValueErrorr   r,   r    r   r   r-   r"   r.   r   r/   r0   )	r!   r1   r&   r   r8   r9   r2   r3   r4   s	            r#   reversezGeokeo.reverse   s    6	C33E:@@EHC
 <<
 hh(()F*;<=%t~~'>'>D4++E""3'"BB  	CABB	Cs   #B1 1Cc                     |j                  dg       }| j                  |       |sy d }|r ||d         S |D cg c]
  } ||       c}S c c}w )Nresultsc                 n    | j                  d      }| d   d   d   }| d   d   d   }t        |||f|       S )z4Get the location, lat, lng from a single json place.formatted_addressgeometrylocationr8   r9   )getr   )placerC   latitude	longitudes       r#   parse_placez'Geokeo._parse_json.<locals>.parse_place   sM    yy!45HZ(4U;Hj)*5e<IHx&;UCCr$   r   )rD   _check_status)r!   pager&   placesrH   rE   s         r#   r/   zGeokeo._parse_json   s]    )R(4 	D vay))4:;F5K&F;;;s   Ac                     |j                  d      xs dj                         }|dk(  ry |dk(  ry |dk(  rt        d      |dk(  rt        d      |d	k(  rt	        d
      |dk(  rt        d      t        d      )Nstatus OKZERO_RESULTSINVALID_REQUESTzInvalid request parametersACCESS_DENIEDzAccess deniedOVER_QUERY_LIMITzOver query limitINTERNAL_SERVER_ERRORzInternal server errorzUnknown error)rD   upperr   r   r   r	   r   )r!   rJ   rM   s      r#   rI   zGeokeo._check_status   s    ((8$*113 T>^#&&$%ABB&/@@))'(:;;..%&=>> '77r$   )T)r.   
__module____qualname____doc__r   r   r
   r   r5   r=   r/   rI   __classcell__)r"   s   @r#   r   r      s]     ,L,L  $$( 5Wv $(C\ $*CX<$8r$   r   N)	functoolsr   urllib.parser   	geopy.excr   r   r   r   r	   geopy.geocoders.baser
   r   geopy.locationr   
geopy.utilr   __all__r    r$   r#   <module>rb      s3     "  < # 
~8X ~8r$   