o
    e                     @   st   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	 d	eZd
S )    )partial)	urlencode)GeocoderAuthenticationFailureGeocoderQueryErrorGeocoderQuotaExceededGeocoderServiceErrorGeocoderUnavailable)DEFAULT_SENTINELGeocoder)Location)logger)Geokeoc                       sn   e Zd ZdZdZdZddeededd fdd
Zdd	ed
ddZd	edddZ	dddZ
dd Z  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          	         sZ   t  j||||||d || _|d| _d| j| j| jf | _d| j| j| jf | _	dS )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	%s://%s%sN)
super__init__api_keystripr   r   geocode_pathapireverse_pathreverse_api)	selfr   r   r   r   r   r   r   r   	__class__ I/var/www/html/venv/lib/python3.10/site-packages/geopy/geocoders/geokeo.pyr      s   )	zGeokeo.__init__T)countryexactly_oner   c                C   s\   | j |d}|r||d< d| jt|f}td| jj| t| j	|d}| j
|||d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callbackr!   r!   r"   geocodeU   s   zGeokeo.geocode)r$   r   c          	      C   s   z|  |d\}}W n ty   tdw | j||d}d| jt|f}td| j	j
| t| j|d}| 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``.
        ,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,   r-   )	r   r.   r$   r   r4   r5   r/   r0   r1   r!   r!   r"   reverse   s   zGeokeo.reversec                    sH   | dg }| | |sd S dd  |r |d S  fdd|D S )Nresultsc                 S   s:   |  d}| d d d }| d d d }t|||f| S )z4Get the location, lat, lng from a single json place.formatted_addressgeometrylocationr4   r5   )getr   )placer=   latitude	longituder!   r!   r"   parse_place   s   
z'Geokeo._parse_json.<locals>.parse_placer   c                    s   g | ]} |qS r!   r!   ).0r?   rB   r!   r"   
<listcomp>   s    z&Geokeo._parse_json.<locals>.<listcomp>)r>   _check_status)r   pager$   placesr!   rD   r"   r,      s   
zGeokeo._parse_jsonc                 C   sr   | dpd }|dkrd S |dkrd S |dkrtd|dkr%td|d	kr-td
|dkr5t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)r>   upperr   r   r   r   r   )r   rG   rI   r!   r!   r"   rF      s   zGeokeo._check_status)T)r+   
__module____qualname____doc__r   r   r	   r   r2   r9   r,   rF   __classcell__r!   r!   r   r"   r      s*    ;.
,r   N)	functoolsr   urllib.parser   	geopy.excr   r   r   r   r   geopy.geocoders.baser	   r
   geopy.locationr   
geopy.utilr   __all__r   r!   r!   r!   r"   <module>   s    