
    g$                         d dl Zd dlmZ d dlmZmZ d dlmZm	Z	m
Z
mZ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
e      Zy)    N)partial)quote	urlencode)GeocoderAuthenticationFailureGeocoderInsufficientPrivilegesGeocoderRateLimitedGeocoderServiceErrorGeocoderUnavailable)DEFAULT_SENTINELGeocoder)Location)join_filterlogger)Bingc                   t     e Zd ZdZh dZdZdZdeededdd fd
Zd	deddd
ddZ	d	edd
ddZ
ddZ xZS )r   zGeocoder 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         	|   ||||||       || _        | j                  d|| j                  | _        | j                  d|| j                  | _        y)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
            T/var/www/api/v1/venv_getwork_v1/lib/python3.12/site-packages/geopy/geocoders/bing.pyr    zBing.__init__%   se    T 	!#+ 	 	
 *.++vt?P?PQ*.++vt?P?PQ    TF)exactly_oneuser_locationr   cultureinclude_neighborhoodinclude_country_codec                R   t        |t        j                  j                        rA|j	                         D 	ci c]  \  }}	|| j
                  v r||	 }
}}	| j                  |
d<   n|| j                  d}
|r| j                  |      |
d<   |rd|
d<   |r||
d<   |||
d<   |rd|
d	<   d
j                  | j                  t        |
      f      }t        j                  d| j                  j                  |       t        | j                   |      }| j#                  |||      S c c}	}w )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)queryr0   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&   r1   r*   r+   r   r,   r-   r.   r0   valparamsurlcallbacks                r(   geocodezBing.geocode[   s8   \ e[__445 ;;= ! C$666 S    !LLF5M ||F %)%A%A-%PF>"#$F<  'F9+,@F() 'F9hh(()F*;<=%t~~'>'>D4++E""3'"BB5s   D#)r*   r   r,   r.   c                   | j                  |      }d| j                  i}|r||d<   |rd|d<   t        |j                  d            }dj	                  | j
                  t        |      z  t        |      f      }	t        j                  d| j                  j                  |	       t        | j                  |	      }
| j                  |	|
|
      S )ar  
        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``.
        r0   r,   r6   r7   zutf-8r8   )pointz%s.reverse: %sr9   r:   )rA   r!   r   encoderB   r%   dictr   r   rC   r'   rD   r   rE   rF   )r&   r1   r*   r   r,   r.   rM   rH   quoted_pointrI   rJ   s              r(   reversezBing.reverse   s    F ,,U3& 'F9 'F9U\\'23hh((4l+CC!&)+ , 	%t~~'>'>D4++E""3'"BBr)   c                 r   |j                  dd      }|dk7  r]|j                  dd      }|dk(  rt        |      |dk(  rt        |      |dk(  rt        |      |dk(  rt	        |      t        |      |d	   d
   d   }|t        |      syd }|r ||d
         S |D cg c]
  } ||       c}S c c}w )zW
        Parse a location name, latitude, and longitude from an JSON response.
        
statusCode   errorDetails i  i  i  i  resourceSetsr   	resourcesNc                 >   d}| d   }|j                  dd      j                  |      }|j                  dd      j                  |      }|j                  dd      j                  |      }|j                  dd      j                  |      }|j                  dd      j                  |      }t        d	||g      }t        d
||g      }	t        d	||	|g      }
| d   d   d   xs d}| d   d   d   xs d}|r|rt        |      }t        |      }t	        |
||f|       S )z3
            Parse each return object.
            z, 
addressr   rV   r   r   r   r   z,  rM   coordinatesr   Nr3   )getstripr   floatr   )resource
stripcharsaddrrZ   citystatezipcodecountry
city_stateplacelocationlatitude	longitudes                r(   parse_resourcez(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'5')BCH(7:BdH )-8;CtII ?!),	Hx&;XFFr)   )r]   r   r   r   r
   r	   len)r&   docr*   status_codeerrrX   rl   r`   s           r(   rE   zBing._parse_json   s     gglC0#''."-Cc!3C88#4S99#)#..#)#..*3//'*;7	C	N	G2 !)A,//=FGYN8,YGGGs   "B4)T)rD   
__module____qualname____doc__r@   r"   r$   r   r    rK   rQ   rE   __classcell__)r'   s   @r(   r   r      sq     (L1L $$( )4Rt $!%!&IC^ $!&0Cd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)   