o
    ÔèFhª  ã                   @   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   z‚Geocoder 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__© úO/var/www/html/loop/nvenv/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    