
    N}bg$                         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dS )    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        | _        dS )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
            g/home/e360mart.nyusoft.in/public_html/e360mart_env/lib/python3.11/site-packages/geopy/geocoders/bing.pyr    zBing.__init__%   s    T 	!#+ 	 	
 	
 	
 *.+++vvt?P?PQ*.+++vvt?P?PQ    TF)exactly_oneuser_locationr   cultureinclude_neighborhoodinclude_country_codec                    t          |t          j        j                  r+ fd|                                D             } j        |d<   n
| j        d}|r                     |          |d<   |rd|d<   |r||d<   |||d	<   |rd
|d<   d                     j        t          |          f          }	t          j        d j        j        |	           t           j        |          }
                     |	|
|          S )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``.
        c                 .    i | ]\  }}|j         v ||S  )structured_query_params).0keyvalr&   s      r(   
<dictcomp>z Bing.geocode.<locals>.<dictcomp>   s9       C$666 S 766r)   r4   )queryr4   userLocation   
maxResultsr,   NincludeNeighborhoodciso2include?z%s.geocode: %sr*   r   )
isinstancecollectionsabcMappingitemsr!   _coerce_point_to_stringjoinr#   r   r   debugr'   __name__r   _parse_json_call_geocoder)r&   r7   r*   r+   r   r,   r-   r.   paramsurlcallbacks   `          r(   geocodezBing.geocode[   sI   \ e[_455 	    ;;==  F !LF5MM | F  	Q%)%A%A-%P%PF>" 	%#$F<  	( 'F9+,@F() 	( 'F9hh()F*;*;<==%t~'>DDD4+EEE""3'"BBBr)   )r*   r   r,   r.   c                   |                      |          }d| j        i}|r||d<   |rd|d<   t          |                    d                    }d                    | j        t          |          z  t          |          f          }	t          j	        d| j
        j        |	           t          | 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``.
        r4   r,   r<   r=   zutf-8r>   )pointz%s.reverse: %sr?   r@   )rF   r!   r   encoderG   r%   dictr   r   rH   r'   rI   r   rJ   rK   )r&   r7   r*   r   r,   r.   rQ   rL   quoted_pointrM   rN   s              r(   reversezBing.reverse   s    F ,,U33& 	( 'F9 	( 'F9U\\'2233hh(4l+C+C+CC!&))+ , , 	%t~'>DDD4+EEE""3'"BBBr)   c                    |                     dd          }|dk    ry|                     dd          }|dk    rt          |          |dk    rt          |          |dk    rt          |          |dk    rt	          |          t          |          |d	         d
         d         }|t          |          sdS d |r |d
                   S fd|D             S )zW
        Parse a location name, latitude, and longitude from an JSON response.
        
statusCode   errorDetails i  i  i  i  resourceSetsr   	resourcesNc                    d}| d         }|                     dd                              |          }|                     dd                              |          }|                     dd                              |          }|                     dd                              |          }|                     dd                              |          }t          d	||g          }t          d
||g          }	t          d	||	|g          }
| d         d         d         pd}| d         d         d         pd}|r |rt          |          }t          |          }t	          |
||f|           S )z3
            Parse each return object.
            z, 
addressr   rZ   r   r   r   r   z,  rQ   coordinatesr   Nr9   )getstripr   floatr   )resource
stripcharsaddrr^   citystatezipcodecountry
city_stateplacelocationlatitude	longitudes                r(   parse_resourcez(Bing._parse_json.<locals>.parse_resource   se     JI&Dhh}b1177
CCG88J++11*==DHH_b1177
CCEhh|R0066zBBGhh3399*EEG$TD%=99Jj'%:;;E"4'5')BCCH(7:BdH )-8;CtI -I - ??!),,	Hx&;XFFFr)   c                 &    g | ]} |          S r1   r1   )r3   rd   rp   s     r(   
<listcomp>z$Bing._parse_json.<locals>.<listcomp>
  s#    GGGNN8,,GGGr)   )ra   r   r   r   r
   r	   len)r&   docr*   status_codeerrr\   rp   s         @r(   rJ   zBing._parse_json   s    gglC00#''."--Cc!!3C888##4S999##)#...##)#...*3///'*;7	C	NN4	G 	G 	G2  	H!>)A,///GGGGYGGGGr)   )T)rI   
__module____qualname____doc__r2   r"   r$   r   r    rO   rU   rJ   __classcell__)r'   s   @r(   r   r      s
           (L1L $$( )4R 4R 4R 4R 4R 4R 4Rt $!%!&IC IC IC IC IC^ $!&0C 0C 0C 0C 0Cd2H 2H 2H 2H 2H 2H 2H 2Hr)   r   )collections.abcrB   	functoolsr   urllib.parser   r   	geopy.excr   r   r   r	   r
   geopy.geocoders.baser   r   geopy.locationr   
geopy.utilr   r   __all__r   r1   r)   r(   <module>r      s             ) ) ) ) ) ) ) )              < ; ; ; ; ; ; ; # # # # # # * * * * * * * *
wH wH wH wH wH8 wH wH wH wH wHr)   