a
    }c                     @   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	   zGeocoder using the Geolake API.

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

    Terms of Service at:
        https://geolake.com/terms-of-use
    >   ZstreetZ	subNumberZcountrystateZzipcodeZhouseNumbercityaddressz/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__ S/var/www/html/django/DPS/env/lib/python3.9/site-packages/geopy/geocoders/geolake.pyr   #   s    +	zGeolake.__init__T)country_codesexactly_oner   c                   s   t |tjjr0 fdd| D } j|d< n j|d}|sDg }t |trT|g}|rfd||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,ZcountryCodes?z%s.geocode: %s)r!   )r   )
isinstancecollectionsabcMappingitemsr   strjoinr   r   r   debugr   __name__r   _parse_jsonZ_call_geocoder)r   queryr    r!   r   paramsurlcallbackr   r&   r   geocode[   s$    '

zGeolake.geocodec                 C   sJ   | dsdS |d }|d }| |}t|||f|}|r@|S |gS dS )z7Returns location, (latitude, longitude) from json feed.successNlatitude	longitude)get_get_addressr   )r   pager!   r;   r<   r   resultr   r   r   r4      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   ZcountryCodez, )r=   r   )r   r?   rA   Zaddress_cityZaddress_country_coder   r   r   r   r>      s
    


zGeolake._get_address)r3   
__module____qualname____doc__r"   r   r   r   r9   r4   r>   __classcell__r   r   r   r   r	      s"   	<Br	   )collections.abcr,   	functoolsr   urllib.parser   Zgeopy.geocoders.baser   r   Zgeopy.locationr   Z
geopy.utilr   r   __all__r	   r   r   r   r   <module>   s   