
    .h                         S SK rS SKrS SKJr  S SKJr  S SKJr  S SK	J
r
Jr  S SKJrJrJr  S SKJr  S SKJr  S	r " S
 S\5      rg)    N)partial)	urlencode)AdapterHTTPError)GeocoderQueryErrorGeocoderQuotaExceeded)DEFAULT_SENTINELNONE_RESULTGeocoder)Location)logger)Geocodioc                      ^  \ rS rSrSr1 SkrSrSrSrS\	\	S\	SSS.U 4S	 jjr
SS
\	S.S jrS
\	SS.S jrSS jrS rS rSrU =r$ )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          	      R   > [         T	U ]  UUUUUUS9  Xl        U(       a  Xl        gg)a  
: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
            kC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\geopy/geocoders/geocodio.pyr   Geocodio.__init__'   s>    N 	!#+ 	 	
  K     T)limitexactly_oner   c                L   [        U[        R                  R                  5      (       a6  UR	                  5        VVs0 s H  u  pVXPR
                  ;   d  M  XV_M     nnnOSU0nU R                  US'   U(       a  X'S'   U(       a  SUS'   U R                  < SU R                  < U R                  < 3nSR                  U[        U5      45      n	[        R                  " SU R                  R                  U	5        [!        U R"                  US9n
U R%                  XUS	9$ s  snnf )
aR  
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``.
qr   r%      ://?z%s.geocode: %sr&   r   )
isinstancecollectionsabcMappingitemsstructured_query_paramsr   r   r   geocode_pathjoinr   r   debugr!   __name__r   _parse_json_call_geocoder)r    queryr%   r&   r   keyvalparamsapiurlcallbacks              r"   geocodeGeocodio.geocodeZ   s   B e[__4455 ;;= ! C666    F 5\F LLy#7OF7O![[$++t7H7HIhhYv./0%t~~'>'>D4++E""3'"BB+s   D D )r&   r   r%   c                   U R                  U5      U R                  S.nU(       a  SnUb  XES'   U R                  < SU R                  < U R                  < 3nSR                  U[        U5      45      n[        R                  " SU R                  R                  U5        [        U R                  US9nU R                  XxUS9$ )	a  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)   r%   r*   r+   z%s.reverse: %sr,   r-   )_coerce_point_to_stringr   r   r   reverse_pathr5   r   r   r6   r!   r7   r   r8   r9   )	r    r:   r&   r   r%   r=   r>   r?   r@   s	            r"   reverseGeocodio.reverse   s    8 --e4||
 E#7O![[$++t7H7HIhhYv./0%t~~'>'>D4++E""3'"BBr$   c                     UR                  S/ 5      nU(       d  gS nU(       a  U" US   5      $ U Vs/ s H
  oT" U5      PM     sn$ s  snf )z7Returns location, (latitude, longitude) from json feed.resultsNc                 `    U R                  S5      nU S   S   nU S   S   n[        XU4U 5      $ )z4Get the location, lat, lng from a single json place.formatted_addresslocationlatlng)getr   )placerL   latitude	longitudes       r"   parse_place)Geocodio._parse_json.<locals>.parse_place   sA    yy!45HZ(/Hj)%0IH&;UCCr$   r   )rO   )r    pager&   placesrS   rP   s         r"   r8   Geocodio._parse_json   sQ     )R(	D vay))4:;F5K&F;;;s   Ac                    [        U[        5      (       d  gUR                  b  UR                  c  gUR                  S:X  aK  U R	                  U5      nSUR                  5       ;   a  SUR                  5       ;   a  [        $ [        U5      UeUR                  S:X  a%  U R	                  U5      nSnX2;   a  [        U5      Uegg)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.)	r.   r   status_codetext_get_error_messagelowerr	   r   r   )r    errorerror_messagequota_exceeded_snippets       r"   _geocoder_exception_handler$Geocodio._geocoder_exception_handler   s     %!122$

(:# 33E:M+}/B/B/DD2m6I6I6KK""$]3># 33E:M&A"%6+M:E 7	 $r$   c                      [         R                  " UR                  5      R                  S5      nU=(       d    UR                  $ ! [         a    Sn N#f = f)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[   Geocodio._get_error_message   sK    	! JJuzz266w?M *

*  	! M	!s   /A AA)r   r   )T)r7   
__module____qualname____firstlineno____doc__r3   r   r4   rE   r   r   rA   rF   r8   r`   r[   __static_attributes____classcell__)r!   s   @r"   r   r      s|    	 F"L"L   $1! 1!n  7Cz  )CV<&F6+ +r$   r   )collections.abcr/   rc   	functoolsr   urllib.parser   geopy.adaptersr   	geopy.excr   r   geopy.geocoders.baser   r	   r
   geopy.locationr   
geopy.utilr   __all__r    r$   r"   <module>rw      s6       " + ? H H # 
d+x d+r$   