
    .h$                         S SK rS SKJr  S SKJr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r " S	 S
\5      rg)    N)partial)quote	urlencode)GeocoderAuthenticationFailureGeocoderInsufficientPrivilegesGeocoderRateLimitedGeocoderServiceErrorGeocoderUnavailable)DEFAULT_SENTINELGeocoder)Location)join_filterlogger)Bingc                      ^  \ rS rSrSr1 SkrSrSrS\\S\SSS.U 4S	 jjr	S
S\SSSS.S jr
S
\SSS.S jrSS jrSrU =r$ )r      zzGeocoder using the Bing Maps Locations API.

Documentation at:
    https://msdn.microsoft.com/en-us/library/ff701715.aspx
>   locality
postalCodeaddressLineadminDistrictcountryRegionz/REST/v1/Locationsz/REST/v1/Locations/%(point)sNzdev.virtualearth.net)schemetimeoutproxies
user_agentssl_contextadapter_factorydomainc          	         > [         T	U ]  UUUUUUS9  Xl        U R                  < SU< U R                  < 3U l        U R                  < SU< U R                  < 3U l        g)a  

:param str api_key: Should be a valid Bing Maps API key
    (https://www.microsoft.com/en-us/maps/create-a-bing-maps-key).

: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

:param str domain: base api domain

    .. versionadded:: 2.4
)r   r   r   r   r   r   z://N)super__init__api_keyr   geocode_pathgeocode_apireverse_pathreverse_api)
selfr"   r   r   r   r   r   r   r   	__class__s
            gC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\geopy/geocoders/bing.pyr!   Bing.__init__%   sc    T 	!#+ 	 	
 *.++vt?P?PQ*.++vt?P?PQ    TF)exactly_oneuser_locationr   cultureinclude_neighborhoodinclude_country_codec                ~   [        U[        R                  R                  5      (       aE  UR	                  5        VV	s0 s H  u  pXR
                  ;   d  M  X_M     n
nn	U R                  U
S'   OUU R                  S.n
U(       a  U R                  U5      U
S'   U(       a  SU
S'   U(       a  XZS'   Ub  XjS'   U(       a  SU
S	'   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$ s  sn	nf )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: `addressLine`, `locality` (city),
    `adminDistrict` (state), `countryRegion`, or `postalCode`.
:type query: str or dict

:param bool exactly_one: Return one result or a list of results, if
    available.

:param user_location: Prioritize results closer to
    this location.
:type user_location: :class:`geopy.point.Point`

: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 culture: Affects the language of the response,
    must be a two-letter country code.

:param bool include_neighborhood: Sets whether to include the
    neighborhood field in the response.

:param bool include_country_code: Sets whether to include the
    two-letter ISO code of the country in the response (field name
    'countryRegionIso2').

:rtype: ``None``, :class:`geopy.location.Location` or a list of them, if
    ``exactly_one=False``.
key)queryr2   userLocation   
maxResultsr.   includeNeighborhoodciso2include?z%s.geocode: %sr,   r   )
isinstancecollectionsabcMappingitemsstructured_query_paramsr"   _coerce_point_to_stringjoinr$   r   r   debugr(   __name__r   _parse_json_call_geocoder)r'   r3   r,   r-   r   r.   r/   r0   r2   valparamsurlcallbacks                r)   geocodeBing.geocode[   s1   \ e[__4455 ;;= ! C666     !LLF5M ||F %)%A%A-%PF>"#$F<  '9+,@() 'F9hh(()F*;<=%t~~'>'>D4++E""3'"BB5s   D9D9)r,   r   r.   r0   c                   U R                  U5      nSU R                  0nU(       a  XGS'   U(       a  SUS'   [        UR                  S5      5      nSR	                  U R
                  [        US9-  [        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 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 culture: Affects the language of the response,
    must be a two-letter country code.

:param bool include_country_code: Sets whether to include the
    two-letter ISO code of the country in the response (field name
    'countryRegionIso2').

:rtype: ``None``, :class:`geopy.location.Location` or a list of them, if
    ``exactly_one=False``.
r2   r.   r8   r9   zutf-8r:   )pointz%s.reverse: %sr;   r<   )rC   r"   r   encoderD   r&   dictr   r   rE   r(   rF   r   rG   rH   )r'   r3   r,   r   r.   r0   rP   rJ   quoted_pointrK   rL   s              r)   reverseBing.reverse   s    F ,,U3& '9 'F9U\\'23hh((4l+CC!&)+ , 	%t~~'>'>D4++E""3'"BBr+   c                    UR                  SS5      nUS:w  aa  UR                  SS5      nUS:X  a  [        U5      eUS:X  a  [        U5      eUS:X  a  [        U5      eUS:X  a  [	        U5      e[        U5      eUS	   S
   S   nUb  [        U5      (       d  gS nU(       a  U" US
   5      $ U Vs/ s H
  ov" U5      PM     sn$ s  snf )zG
Parse a location name, latitude, and longitude from an JSON response.

statusCode   errorDetails i  i  i  i  resourceSetsr   	resourcesNc                 ^   SnU S   nUR                  SS5      R                  U5      nUR                  SS5      R                  U5      nUR                  SS5      R                  U5      nUR                  SS5      R                  U5      nUR                  SS5      R                  U5      n[        S	XE/5      n[        S
X/5      n	[        S	X9U/5      n
U S   S   S   =(       d    SnU S   S   S   =(       d    SnU(       a  U(       a  [        U5      n[        U5      n[	        XU4U 5      $ )z
Parse each return object.
z, 
addressr   rZ   r   r   r   r   z,  rP   coordinatesr   Nr5   )getstripr   floatr   )resource
stripcharsaddrr^   citystatezipcodecountry
city_stateplacelocationlatitude	longitudes                r)   parse_resource(Bing._parse_json.<locals>.parse_resource   s$     JI&Dhh}b177
CG88J+11*=DHH_b177
CEhh|R066zBGhh399*EG$TD=9Jj%:;E"4'')BCH(7:BdH )-8;CtII ?!),	H&;XFFr+   )ra   r   r   r   r
   r	   len)r'   docr,   status_codeerrr\   rp   rd   s           r)   rG   Bing._parse_json   s     gglC0#''."-Cc!3C88#4S99#)#..#)#..*3//'*;7	C	NN	G2 !)A,//=FGYN8,YGGGs   2C)r"   r$   r&   )T)rF   
__module____qualname____firstlineno____doc__rB   r#   r%   r   r!   rM   rT   rG   __static_attributes____classcell__)r(   s   @r)   r   r      s}     (L1L $$( )4R 4Rt $!%!&IC^ $!&0Cd2H 2Hr+   r   )collections.abcr>   	functoolsr   urllib.parser   r   	geopy.excr   r   r   r	   r
   geopy.geocoders.baser   r   geopy.locationr   
geopy.utilr   r   __all__r    r+   r)   <module>r      s8      )  < # *
wH8 wHr+   