
    N}bg                         d dl Zd dlZd dlmZ d dlmZ d dlmZ d dl	m
Z
mZ d dlmZmZmZ d dlmZ d dlmZ d	Z G d
 de          ZdS )    N)partial)	urlencode)AdapterHTTPError)GeocoderQueryErrorGeocoderQuotaExceeded)DEFAULT_SENTINELNONE_RESULTGeocoder)Location)logger)Geocodioc                   |     e Zd ZdZh dZdZdZdZdeededdd fd
Z	dd	ed
dZ
d	edddZddZd Zd Z xZS )r   zGeocoder using the Geocod.io API.

    Documentation at:
        https://www.geocod.io/docs/

    Pricing details:
        https://www.geocod.io/pricing/

    .. versionadded:: 2.2
    >   citystatestreetcountrypostal_codezapi.geocod.ioz/v1.6/geocodez/v1.6/reverseN)schemetimeoutproxies
user_agentssl_contextadapter_factorydomainc                z    t                                          ||||||           || _        |r	|| _        dS dS )aG  
        :param str api_key:
            A valid Geocod.io API key. (https://dash.geocod.io/apikey/create)

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

        :param str domain: base api domain

            .. versionadded:: 2.4
        )r   r   r   r   r   r   N)super__init__api_keyr   )
selfr   r   r   r   r   r   r   r   	__class__s
            k/home/e360mart.nyusoft.in/public_html/e360mart_env/lib/python3.11/site-packages/geopy/geocoders/geocodio.pyr   zGeocodio.__init__'   s_    N 	!#+ 	 	
 	
 	
  	! DKKK	! 	!    T)limitexactly_oner   c                    t          |t          j        j                  r! fd|                                D             }nd|i} j        |d<   |r||d<   |rd|d<    j        d j         j        }d	                    |t          |          f          }t          j        d j        j        |           t           j        |	          }                     |||
          S )a  
        Return a location point by address.

        :param query: The address, query or a structured query
            you wish to geocode.

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

        :param int limit: The maximum number of matches to return. This will be reset
            to 1 if ``exactly_one`` is ``True``.

        :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``.
        c                 .    i | ]\  }}|j         v ||S  )structured_query_params).0keyvalr   s      r!   
<dictcomp>z$Geocodio.geocode.<locals>.<dictcomp>|   s9       C$666 S 766r"   qr   r#      ://?z%s.geocode: %sr$   r   )
isinstancecollectionsabcMappingitemsr   r   r   geocode_pathjoinr   r   debugr    __name__r   _parse_json_call_geocoder)	r   queryr#   r$   r   paramsapiurlcallbacks	   `        r!   geocodezGeocodio.geocodeZ   s   B e[_455 	"    ;;==  FF 5\F Ly 	$#F7O 	 F7O![[[$++t7H7HIhhYv../00%t~'>DDD4+EEE""3'"BBBr"   )r$   r   r#   c                f   |                      |          | j        d}|rd}|||d<   | j        d| j        | j        }d                    |t          |          f          }t          j        d| j	        j
        |           t          | j        |          }|                     |||	          S )
a5  Return an address by location point.

        :param str query: The coordinates for which you wish to obtain the
            closest human-readable addresses

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

        :param int limit: The maximum number of matches to return. This will be reset
            to 1 if ``exactly_one`` is ``True``.

        :rtype: ``None``, :class:`geopy.location.Location` or a list of them, if
            ``exactly_one=False``.
        )r-   r   r.   Nr#   r/   r0   z%s.reverse: %sr1   r2   )_coerce_point_to_stringr   r   r   reverse_pathr9   r   r   r:   r    r;   r   r<   r=   )	r   r>   r$   r   r#   r?   r@   rA   rB   s	            r!   reversezGeocodio.reverse   s    8 --e44|
 
  	E#F7O![[[$++t7H7HIhhYv../00%t~'>DDD4+EEE""3'"BBBr"   c                     |                     dg           }|sdS d |r |d                   S fd|D             S )z7Returns location, (latitude, longitude) from json feed.resultsNc                     |                      d          }| d         d         }| d         d         }t          |||f|           S )z4Get the location, lat, lng from a single json place.formatted_addresslocationlatlng)getr   )placerL   latitude	longitudes       r!   parse_placez)Geocodio._parse_json.<locals>.parse_place   sI    yy!455HZ(/Hj)%0IHx&;UCCCr"   r   c                 &    g | ]} |          S r'   r'   )r)   rP   rS   s     r!   
<listcomp>z(Geocodio._parse_json.<locals>.<listcomp>   s#    ;;;5KK&&;;;r"   )rO   )r   pager$   placesrS   s       @r!   r<   zGeocodio._parse_json   so     )R(( 	4	D 	D 	D  	<;vay)));;;;F;;;;r"   c                    t          |t                    sdS |j        |j        dS |j        dk    rX|                     |          }d|                                v rd|                                v rt          S t          |          ||j        dk    r+|                     |          }d}||v rt          |          |dS dS )a  Custom exception handling for invalid queries and exceeded quotas.

        Geocod.io returns a ``422`` status code for invalid queries, which is not mapped
        in :const:`~geopy.geocoders.base.ERROR_CODE_MAP`. The service also returns a
        ``403`` status code for exceeded quotas instead of the ``429`` code mapped in
        :const:`~geopy.geocoders.base.ERROR_CODE_MAP`
        Ni  zcould not geocode addresszpostal code or city requiredi  z>You can't make this request as it is above your daily maximum.)	r3   r   status_codetext_get_error_messagelowerr	   r   r   )r   errorerror_messagequota_exceeded_snippets       r!   _geocoder_exception_handlerz$Geocodio._geocoder_exception_handler   s     %!122 	F$
(:F## 33E::M+}/B/B/D/DDD2m6I6I6K6KKK""$]33>## 33E::M&A"%66+M::E $# 76r"   c                     	 t          j        |j                                      d          }n# t          $ r d}Y nw xY w|p|j        S )zVTry to extract an error message from the 'error' property of a JSON response.
        r]   N)jsonloadsrZ   rO   
ValueError)r   r]   r^   s      r!   r[   zGeocodio._get_error_message   sY    	! Juz2266w??MM 	! 	! 	! MMM	!*
*s   ,/ >>)T)r;   
__module____qualname____doc__r(   r   r8   rF   r   r   rC   rG   r<   r`   r[   __classcell__)r    s   @r!   r   r      s       	 	   F"L"L   $1! 1! 1! 1! 1! 1! 1!n  7C 7C 7C 7C 7Cz  )C )C )C )C )CV< < < <&F F F6+ + + + + + +r"   r   )collections.abcr4   rb   	functoolsr   urllib.parser   geopy.adaptersr   	geopy.excr   r   geopy.geocoders.baser   r	   r
   geopy.locationr   
geopy.utilr   __all__r   r'   r"   r!   <module>rr      s               " " " " " " + + + + + + ? ? ? ? ? ? ? ? H H H H H H H H H H # # # # # #      
d+ d+ d+ d+ d+x d+ d+ d+ d+ d+r"   