
    .h@@                         S SK r S SKr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  S SKJrJrJrJrJr  S SKJrJr  S SKJr  S S	KJrJr  S S
KJr  Sr " S S\5      rg)    N)timegm)datetime)partial)	urlencode)ConfigurationErrorGeocoderQueryErrorGeocoderQuotaExceededGeocoderServiceErrorGeocoderUnavailable)DEFAULT_SENTINELGeocoder)Location)ensure_pytz_is_installedfrom_timezone_name)logger)GoogleV3c                      ^  \ rS rSrSrSrSr SSSSS\\S\SSS.
U 4S	 jjjrS
 r	S r
 SS\SSSSSSS.S jjrS\SSS.S jrS\S.S jrS rS rSS jrS rSrU =r$ )r      zGeocoder using the Google Maps v3 API.

Documentation at:
    https://developers.google.com/maps/documentation/geocoding/

Pricing details:
    https://developers.google.com/maps/documentation/geocoding/usage-and-billing
z/maps/api/geocode/jsonz/maps/api/timezone/jsonNzmaps.googleapis.com )
domainscheme	client_id
secret_keytimeoutproxies
user_agentssl_contextadapter_factorychannelc       
   	        > [         TU ]  UUUUU	U
S9  U(       a  U(       d  [        S5      eU(       a  U(       d  [        S5      e[        U=(       a    U5      U l        X@l        XPl        U R                  (       d  U(       d  [        S5      eXl        UR                  S5      U l	        Xl
        U R                  < SU R                  < U R                  < 3U l        U R                  < SU R                  < U R                  < 3U l        g)aW  

:param str api_key: The API key required by Google to perform
    geocoding requests, mandatory (unless premier is used,
    then both ``client_id`` and ``secret_key`` must be specified
    instead).
    API keys are managed through
    the Google APIs console (https://code.google.com/apis/console).
    Make sure to have both ``Geocoding API`` and ``Time Zone API``
    services enabled for this API key.

    .. versionchanged:: 2.1
       Previously a warning has been emitted when neither ``api_key``
       nor premier were specified. Now a :class:`geopy.exc.ConfigurationError`
       is raised.

:param str domain: Should be the localized Google Maps domain to
    connect to. The default is 'maps.googleapis.com', but if you're
    geocoding address in the UK (for example), you may want to set it
    to 'maps.google.co.uk' to properly bias results.

:param str scheme:
    See :attr:`geopy.geocoders.options.default_scheme`.

:param str client_id: If using premier, the account client id.

:param str secret_key: If using premier, the account secret key.

: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

:param str channel: If using premier, the channel identifier.
)r   r   r   r   r   r   z'Must provide secret_key with client_id.z'Must provide client_id with secret_key.zSince July 2018 Google requires each request to have an API key. Pass a valid `api_key` to GoogleV3 geocoder to fix this error. See https://developers.google.com/maps/documentation/geocoding/usage-and-billing/://N)super__init__r   boolpremierr   r   api_keystripr   r   r   api_pathapitimezone_pathtz_api)selfr'   r   r   r   r   r   r   r   r   r   r   	__class__s               iC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\geopy/geocoders/google.pyr$   GoogleV3.__init__&   s    ~ 	!#+ 	 	
 Z$%NOOi$%NOOI4*5"$||G$c  ll3'"&++t{{DMMJ%)[[$++t?Q?QR    c                     U R                   US'   U R                  (       a  U R                  US'   SR                  U R                  [	        U5      45      n[
        R                  " [        R                  " U R                  5      UR                  S5      [        R                  5      n[        R                  " UR                  5       5      R                  S5      nU R                   < SU R"                  < U< SU< 3$ )z
Returns a Premier account signed url. Docs on signature:
    https://developers.google.com/maps/documentation/business/webservices/auth#digital_signatures
clientr   ?zutf-8r"   z&signature=)r   r   joinr)   r   hmacnewbase64urlsafe_b64decoder   encodehashlibsha1urlsafe_b64encodedigestdecoder   r   )r-   paramspath	signatures       r/   _get_signed_urlGoogleV3._get_signed_url   s    
  >>x<< $F9xx	&(9:;HH$$T__5KK LL
	
 ,,

&/ 	 KKdI
 	
r1   c                 N   / n[        U[        R                  R                  5      (       a  UR	                  5       nOR[        U[        R                  R
                  5      (       a  [        U[        [        45      (       d  UnO[        S5      eSR                  S U 5       5      $ )Nz7`components` parameter must be of type `dict` or `list`|c              3   D   #    U  H  nS R                  U5      v   M     g7f):N)r5   ).0items     r/   	<genexpr>4GoogleV3._format_components_param.<locals>.<genexpr>   s      
'6tCHHTNNs    )

isinstancecollectionsabcMappingitemsSequencestrbytes
ValueErrorr5   )r-   
componentscomponent_itemss      r/   _format_components_param!GoogleV3._format_components_param   s    j+//"9"9::(..0Oz;??#;#;<<zC<88(OIK K xx 
'6
 
 	
r1   TF)exactly_oner   boundsregionrV   place_idlanguagesensorc                   S[        U	5      R                  5       0n
U(       a  U(       d  U(       a  [        S5      eUb  XzS'   Ub  XS'   Uc  Uc  U(       d  [        S5      eU R                  (       a  U R                  U
S'   U(       a  U R	                  US5      U
S'   U(       a  XZS	'   U(       a  U R                  U5      U
S
'   U(       a  XS'   U R                  (       a  U R                  U
5      nO&SR                  U R                  [        U
5      45      n[        R                  " SU R                  R                  U5        [        U R                   US9nU R#                  XUS9$ )a-  
Return a location point by address.

:param str query: The address or query you wish to geocode. Optional,
    if ``components`` param is set::

        >>> g.geocode(components={"city": "Paris", "country": "FR"})
        Location(France, (46.227638, 2.213749, 0.0))

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

:type bounds: list or tuple of 2 items of :class:`geopy.point.Point` or
    ``(latitude, longitude)`` or ``"%(latitude)s, %(longitude)s"``.
:param bounds: The bounding box of the viewport within which
    to bias geocode results more prominently.
    Example: ``[Point(22, 180), Point(-22, -180)]``.

:param str region: The region code, specified as a ccTLD
    ("top-level domain") two-character value.

:type components: dict or list
:param components: Restricts to an area. Can use any combination of:
    `route`, `locality`, `administrative_area`, `postal_code`,
    `country`.

    Pass a list of tuples if you want to specify multiple components of
    the same type, e.g.:

        >>> [('administrative_area', 'VA'), ('administrative_area', 'Arlington')]

:param str place_id: Retrieve a Location using a Place ID.
    Cannot be not used with ``query`` or ``bounds`` parameters.

        >>> g.geocode(place_id='ChIJOcfP0Iq2j4ARDrXUa7ZWs34')

:param str language: The language in which to return results.

:param bool sensor: Whether the geocoding request comes from a
    device with a location sensor.

:rtype: ``None``, :class:`geopy.location.Location` or a list of them, if
    ``exactly_one=False``.
r_   zNOnly one of the `query` or `place id` or `bounds`  parameters must be entered.r]   addressz9Either `query` or `components` or `place_id` must be set.keyz#%(lat1)s,%(lon1)s|%(lat2)s,%(lon2)sr[   r\   rV   r^   r4   z%s.geocode: %srZ   r   )rS   lowerrU   r'   _format_bounding_boxrX   r&   rC   r5   r*   r   r   debugr.   __name__r   _parse_json_call_geocoder)r-   queryrZ   r   r[   r\   rV   r]   r^   r_   r@   urlcallbacks                r/   geocodeGoogleV3.geocode   sM   ~ c&k'')
 5/0 0 !): %9=X-j , - - << LLF5M#88= ?F8%8#'#@#@#LF< !):<<&&v.C((DHHi&789C%t~~'>'>D4++E""3'"BBr1   )rZ   r   r^   r_   c                   U R                  U5      [        U5      R                  5       S.nU(       a  XFS'   U R                  (       a  U R                  US'   U R                  (       d'  SR                  U R                  [        U5      45      nOU R                  U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 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.

:param str language: The language in which to return results.

:param bool sensor: Whether the geocoding request comes from a
    device with a location sensor.

:rtype: ``None``, :class:`geopy.location.Location` or a list of them, if
    ``exactly_one=False``.
)latlngr_   r^   rb   r4   z%s.reverse: %src   rd   )_coerce_point_to_stringrS   re   r'   r&   r5   r*   r   rC   r   rg   r.   rh   r   ri   rj   )	r-   rk   rZ   r   r^   r_   r@   rl   rm   s	            r/   reverseGoogleV3.reverse  s    F 2259&k'')
 !):<< LLF5M||((DHHi&789C&&v.C%t~~'>'>D4++E""3'"BBr1   )at_timer   c                |   [        5         U R                  U5      nU R                  U5      nUUS.nU R                  (       a  U R                  US'   SR	                  U R
                  [        U5      45      n[        R                  " SU R                  R                  U5        U R                  XpR                  US9$ )a  
Find the timezone a point in `query` was in for a specified `at_time`.

`None` will be returned for points without an assigned
Olson timezone id (e.g. for Antarctica).

:param query: The coordinates for which you want a timezone.
:type query: :class:`geopy.point.Point`, list or tuple of (latitude,
    longitude), or string as "%(latitude)s, %(longitude)s"

:param at_time: The time at which you want the timezone of this
    location. This is optional, and defaults to the time that the
    function is called in UTC. Timezone-aware datetimes are correctly
    handled and naive datetimes are silently treated as UTC.
:type at_time: :class:`datetime.datetime` or None

: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`` or :class:`geopy.timezone.Timezone`.
)location	timestamprb   r4   z%s.reverse_timezone: %srd   )r   rr   _normalize_timezone_at_timer'   r5   r,   r   r   rg   r.   rh   rj   _parse_json_timezone)r-   rk   ru   r   rw   rx   r@   rl   s           r/   reverse_timezoneGoogleV3.reverse_timezoneG  s    0 	!"//644W=	 !"
 << LLF5MhhYv%678.0G0GM""3(A(A7"SSr1   c                 `    U R                  U5        UR                  S5      nUc  g [        X!S9$ )N
timeZoneId)raw)_check_statusgetr   )r-   responsetimezone_ids      r/   rz   GoogleV3._parse_json_timezonep  s4    8$ll<0
 !+<<r1   c                     Uc.  [        [        R                  " 5       R                  5       5      nU$ [	        U[        5      (       a  [        UR                  5       5      nU$ [        S5      e)Nz4`at_time` must be an instance of `datetime.datetime`)r   r   utcnowutctimetuplerM   r   )r-   ru   rx   s      r/   ry   $GoogleV3._normalize_timezone_at_time|  sg    ?x0==?@I  ** w3356I
  %F r1   c                     UR                  S/ 5      nU R                  U5        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 )Nresultsc                 l    U R                  S5      nU S   S   S   nU S   S   S   n[        XU4U 5      $ )z4Get the location, lat, lng from a single json place.formatted_addressgeometryrw   latlng)r   r   )placerw   latitude	longitudes       r/   parse_place)GoogleV3._parse_json.<locals>.parse_place  sK    yy!45HZ(4U;Hj)*5e<IH&;UCCr1   r   )r   r   )r-   pagerZ   placesr   r   s         r/   ri   GoogleV3._parse_json  s]    )R(4 	D vay))4:;F5K&F;;;s   Ac                 Z   UR                  S5      nUS:X  a  g US:X  a  g UR                  S5      nUS;   a  [        U=(       d    S5      eUS:X  a  [        U=(       d    S5      eUS	:X  a  [        U=(       d    S
5      eUS:X  a  [        U=(       d    S5      e[	        U=(       d    S5      e)NstatusOKZERO_RESULTSerror_message)OVER_QUERY_LIMITOVER_DAILY_LIMITzThe given key has gone over the requests limit in the 24 hour period or has submitted too many requests in too short a period of timeREQUEST_DENIEDzYour request was deniedINVALID_REQUESTz"Probably missing address or latlngUNKNOWN_ERRORzServer errorzUnknown error)r   r	   r   r   r
   )r-   r   r   r   s       r/   r   GoogleV3._check_status  s    h'T>^# _5 ==' **  ''$]%O6OPP(($E!E  &%m&E~FF '}'GHHr1   )r*   r'   r   r   r   r&   r   r,   )N)T)rh   
__module____qualname____firstlineno____doc__r)   r+   r   r$   rC   rX   rn   rs   r{   rz   ry   ri   r   __static_attributes____classcell__)r.   s   @r/   r   r      s     (H-M ]S )$$( ]S ]S~
.
( cC $cCR $2Ch 26?O 'TR
=<$I Ir1   r   )r8   collections.abcrN   r;   r6   calendarr   r   	functoolsr   urllib.parser   	geopy.excr   r   r	   r
   r   geopy.geocoders.baser   r   geopy.locationr   geopy.timezoner   r   
geopy.utilr   __all__r    r1   r/   <module>r      sJ           "  < # G 
aIx aIr1   