
    N}bg2$                         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
 d dlmZmZ d dlmZ d dlmZ dZ G d	 d
e          Z G d de          ZdS )    N)partial)
quote_plus	urlencode)GeocoderAuthenticationFailureGeocoderQueryErrorGeocoderQuotaExceededGeocoderServiceError)DEFAULT_SENTINELGeocoder)Location)logger)BaiduBaiduV3c                   z     e Zd ZdZdZdZdeededdd fd
Zd Zdedd	Z	dedd
Z
ddZddZd Zd Z xZS )r   a  Geocoder using the Baidu Maps v2 API.

    Documentation at:
        http://lbsyun.baidu.com/index.php?title=webapi/guide/webservice-geocoding

    .. attention::
        Newly registered API keys will not work with v2 API,
        use :class:`.BaiduV3` instead.
    z/geocoder/v2/N)schemetimeoutproxies
user_agentssl_contextadapter_factorysecurity_keyc                    t                                          ||||||           || _        | j        d| j        | _        | j        d| j        | _        || _        dS )ag  

        :param str api_key: The API key (AK) required by Baidu Map to perform
            geocoding requests. API keys are managed through the Baidu APIs
            console (http://lbsyun.baidu.com/apiconsole/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 security_key: The security key (SK) to calculate
            the SN parameter in request if authentication setting requires
            (http://lbsyun.baidu.com/index.php?title=lbscloud/api/appendix).
        )r   r   r   r   r   r   z://api.map.baidu.comN)	super__init__api_keyr   api_pathapireverse_pathreverse_apir   )
selfr   r   r   r   r   r   r   r   	__class__s
            h/home/e360mart.nyusoft.in/public_html/e360mart_env/lib/python3.11/site-packages/geopy/geocoders/baidu.pyr   zBaidu.__init__    s    V 	!#+ 	 	
 	
 	
 15dmmL9=dFWFWX(    c                 d    d                     d |                                D                       S )zL
        Format the components dict to something Baidu understands.
        |c              3   @   K   | ]}d                      |          V  dS ):N)join).0items     r"   	<genexpr>z1Baidu._format_components_param.<locals>.<genexpr>]   s,      ;;SXXd^^;;;;;;r#   )r(   items)r    
componentss     r"   _format_components_paramzBaidu._format_components_paramX   s7     xx;;
(8(8(:(:;;;
 
 	
r#   T)exactly_oner   c                    | j         d|d}|                     | j        | j        |          }t	          j        d| j        j        |           t          | j	        |          }| 
                    |||          S )a  
        Return a location point by address.

        :param str query: The address or query you wish to geocode.

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

        json)akoutputaddressz%s.geocode: %sr/   r   )r   _construct_urlr   r   r   debugr!   __name__r   _parse_json_call_geocoderr    queryr/   r   paramsurlcallbacks          r"   geocodezBaidu.geocode`   s    2 ,
 
 !!$(DM6BB%t~'>DDD4+EEE""3'"BBBr#   c                   | j         d|                     |          d}|                     | j        | j        |          }t          j        d| j        j        |           t          | j
        |          }|                     |||          S )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. Baidu's API will always return at most one result.

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

        r1   )r2   r3   locationz%s.reverse: %sr5   r6   )r   _coerce_point_to_stringr7   r   r   r   r8   r!   r9   r   _parse_reverse_jsonr;   r<   s          r"   reversezBaidu.reverse   s    , ,44U;;
 
 !!$"2D4EvNN%t~'>DDD43MMM""3'"BBBr#   c                 @   |                     d          }|s*|                     |                     d                     dS |                     d                              d          }|d         d         }|d         d         }t          |||f|          }|r|S |gS )	zJ
        Parses a location from a single-result reverse API call.
        resultstatusNformatted_addressutf-8rC   latlng)get_check_statusencoder   )r    pager/   placerC   latitude	longitudes          r"   rE   zBaidu._parse_reverse_json   s     "" 	txx1122249901188AA$U+*%e,	Hx&;UCC 	O:r#   c                     |                     d          }|s*|                     |                     d                     dS d |r |          S fd|D             S )zI
        Returns location, (latitude, longitude) from JSON feed.
        rH   rI   Nc                     |                      d          }| d         d         }| d         d         }t          |||f|           S )zN
            Get the location, lat, lng from a single JSON place.
            levelrC   rL   rM   )rN   r   )rR   rC   rS   rT   s       r"   parse_placez&Baidu._parse_json.<locals>.parse_place   sJ     yy))HZ(/Hj)%0IHx&;UCCCr#   c                 &    g | ]} |          S  rZ   )r)   r*   rX   s     r"   
<listcomp>z%Baidu._parse_json.<locals>.<listcomp>   s#    888$KK%%888r#   )rN   rO   )r    rQ   r/   rR   rX   s       @r"   r:   zBaidu._parse_json   s    
 "" 	txx112224	D 	D 	D  	9;u%%%8888%8888r#   c                 ,   |dk    rdS |dk    rt          d          |dk    rt          d          |dk    rt          d          |d	k    rt          d
          |dk    rt          d          |dk    rt          d          |dk    rt          d          |dk    rt          d          |dk    rt          d          d|cxk    rdk     rn nt          d          d|cxk    rdk     rn nt          d          t          d|z            )z+
        Validates error statuses.
        r   N   zInternal server error.   zInvalid request.   zAuthentication failure.   zQuota validate failure.   zAK Illegal or Not Exist.e   zNo AKf   zMCODE Error   z
Invalid AK   z
Invalid SNi,  zAuthentication Failurei  zQuota Error.zUnknown error. Status: %r)r	   r   r   r   )r    rI   s     r"   rO   zBaidu._check_status   s    Q;;FQ;;&(   q[[$"   q[[/)   q[[')   q[[$*   s]]/   s]]/   s]]/   s]]/   F    S     /(   F    S     '   %%@6%IJJJr#   c                     t          |          }| j        |d|S |d|| j        }t          j        t	          |                              d                                                    }|d|d|S )N?rK   z&sn=)r   r   hashlibmd5r   rP   	hexdigest)r    r?   pathr>   query_stringrawsns          r"   r7   zBaidu._construct_url  s     (($!cc<<00  $tt\\43D3DECZ__33G<<==GGIIB$'CCrr::r#   )T)r9   
__module____qualname____doc__r   r   r
   r   r.   rA   rF   rE   r:   rO   r7   __classcell__)r!   s   @r"   r   r      s         H"L $$( 6) 6) 6) 6) 6) 6) 6)p
 
 
 $"C "C "C "C "CH -1:J C C C C CB   (9 9 9 924K 4K 4Kl; ; ; ; ; ; ;r#   r   c                       e Zd ZdZdZdZdS )r   zGeocoder using the Baidu Maps v3 API.

    Documentation at:
        http://lbsyun.baidu.com/index.php?title=webapi/guide/webservice-geocoding
    z/geocoding/v3/z/reverse_geocoding/v3/N)r9   ro   rp   rq   r   r   rZ   r#   r"   r   r     s$           H+LLLr#   r   )rh   	functoolsr   urllib.parser   r   	geopy.excr   r   r   r	   geopy.geocoders.baser
   r   geopy.locationr   
geopy.utilr   __all__r   r   rZ   r#   r"   <module>r{      s          . . . . . . . .            < ; ; ; ; ; ; ; # # # # # #      
~; ~; ~; ~; ~;H ~; ~; ~;B, , , , ,e , , , , ,r#   