o
    ÔèFhÂ  ã                   @   sd   d dl Zd dlmZ d dlmZ d dlmZmZ d dl	m
Z
 d dlmZmZ dZG dd	„ d	eƒZdS )
é    N)Úpartial)Ú	urlencode)ÚDEFAULT_SENTINELÚGeocoder)ÚLocation)Újoin_filterÚlogger)ÚGeolakec                       s`   e Zd ZdZh d£ZdZddeededdœ‡ fdd„
Zdd	ed
œdd„Zdd„ Z	dd„ Z
‡  ZS )r	   z£Geocoder using the Geolake API.

    Documentation at:
        https://geolake.com/docs/api

    Terms of Service at:
        https://geolake.com/terms-of-use
    >   ÚcityÚstateÚstreetÚaddressÚcountryÚzipcodeÚ	subNumberÚhouseNumberz/v1/geocodezapi.geolake.comN)ÚdomainÚschemeÚtimeoutÚproxiesÚ
user_agentÚssl_contextÚadapter_factoryc          	         sD   t ƒ j||||||d� || _| d¡| _d| j| j| jf | _dS )aÊ  

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

        :param str domain: Currently it is ``'api.geolake.com'``, can
            be changed for testing purposes.

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

            .. versionadded:: 2.0

        )r   r   r   r   r   r   ú/z	%s://%s%sN)ÚsuperÚ__init__Úapi_keyÚstripr   r   Úapi_pathÚapi)	Úselfr   r   r   r   r   r   r   r   ©Ú	__class__© úP/var/www/html/loop/nvenv/lib/python3.10/site-packages/geopy/geocoders/geolake.pyr   #   s   +ú	zGeolake.__init__T)Úcountry_codesÚexactly_oner   c                   sª   t |tjjƒr‡ fdd„| ¡ D ƒ}ˆ j|d< nˆ j|dœ}|s"g }t |tƒr*|g}|r3d |¡|d< d ˆ jt	|ƒf¡}t
 dˆ jj|¡ tˆ j|d	�}ˆ j|||d
�S )aû  
        Return a location point by address.

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

            For a structured query, provide a dictionary whose keys
            are one of: `country`, `state`, `city`, `zipcode`, `street`, `address`,
            `houseNumber` or `subNumber`.
        :type query: str or dict

        :param country_codes: Provides the geocoder with a list
            of country codes that the query may reside in. This value will
            limit the geocoder to the supplied countries. The country code
            is a 2 character code as defined by the ISO-3166-1 alpha-2
            standard (e.g. ``FR``). Multiple countries can be specified with
            a Python list.

        :type country_codes: str or list

        :param bool exactly_one: Return one result or a list of one result.

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

        c                    s    i | ]\}}|ˆ j v r||“qS r#   )Ústructured_query_params)Ú.0ÚkeyÚval©r    r#   r$   Ú
<dictcomp>ƒ   s
    
ýz#Geolake.geocode.<locals>.<dictcomp>r   )r   Úqú,ÚcountryCodesú?z%s.geocode: %s)r&   )r   )Ú
isinstanceÚcollectionsÚabcÚMappingÚitemsr   ÚstrÚjoinr   r   r   Údebugr"   Ú__name__r   Ú_parse_jsonÚ_call_geocoder)r    Úqueryr%   r&   r   ÚparamsÚurlÚcallbackr#   r+   r$   Úgeocode[   s$   '
ýþ
zGeolake.geocodec                 C   sF   |  d¡sdS |d }|d }|  |¡}t|||f|ƒ}|r |S |gS )z7Returns location, (latitude, longitude) from json feed.ÚsuccessNÚlatitudeÚ	longitude)ÚgetÚ_get_addressr   )r    Úpager&   rB   rC   r   Úresultr#   r#   r$   r:   �   s   

zGeolake._parse_jsonc                 C   s0   |  d¡}|  d¡}|  d¡}td||gƒ}|S )zl
        Returns address string from page dictionary
        :param page: dict
        :return: str
        Úplacer
   ÚcountryCodez, )rD   r   )r    rF   rH   Úaddress_cityÚaddress_country_coder   r#   r#   r$   rE   ­   s
   


zGeolake._get_address)r9   Ú
__module__Ú__qualname__Ú__doc__r'   r   r   r   r@   r:   rE   Ú__classcell__r#   r#   r!   r$   r	      s$    	ö<úBr	   )Úcollections.abcr2   Ú	functoolsr   Úurllib.parser   Úgeopy.geocoders.baser   r   Úgeopy.locationr   Ú
geopy.utilr   r   Ú__all__r	   r#   r#   r#   r$   Ú<module>   s    