
    N}bg                     f    d dl mZ d dl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d	S )
    )partial)	urlencode)DEFAULT_SENTINELGeocoderLocation)logger)MapQuestc                   d     e Zd ZdZdZdZdeededdd fd
Zdd	Zdeddd
dZ	deddZ
 xZS )r
   a  Geocoder using the MapQuest API based on Licensed data.

    Documentation at:
        https://developer.mapquest.com/documentation/geocoding-api/

    MapQuest provides two Geocoding APIs:

    - :class:`geopy.geocoders.OpenMapQuest` Nominatim-alike API
      which is based on Open data from OpenStreetMap.
    - :class:`geopy.geocoders.MapQuest` (this class) MapQuest's own API
      which is based on Licensed data.
    z/geocoding/v1/addressz/geocoding/v1/reverseNzwww.mapquestapi.com)schemetimeoutproxies
user_agentssl_contextadapter_factorydomainc                   t                                          ||||||           || _        |                    d          | _        | j        d| j        | j        | _        | j        d| j        | j        | _	        dS )a  
        :param str api_key: The API key required by Mapquest to perform
            geocoding requests. API keys are managed through MapQuest's "Manage Keys"
            page (https://developer.mapquest.com/user/me/apps).

        :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 for mapquest
        )r   r   r   r   r   r   /z://N)
super__init__api_keystripr   r   geocode_pathgeocode_apireverse_pathreverse_api)
selfr   r   r   r   r   r   r   r   	__class__s
            k/home/e360mart.nyusoft.in/public_html/e360mart_env/lib/python3.11/site-packages/geopy/geocoders/mapquest.pyr   zMapQuest.__init__   s    P 	!#+ 	 	
 	
 	
 ll3''  ;;;T5F5FG 	  ;;;T5F5FG 	    Tc                     |d         d         d         }|g k    rdS d fd|r |d                   S fd|D             S )z7Returns location, (latitude, longitude) from json feed.resultsr   	locationsNc                 R     g d} fd|D             }d                     |          S )N)street
adminArea6
adminArea5
adminArea4
adminArea3
adminArea2
adminArea1
postalCodec                 J    g | ]}                     |          |          S  )get).0kfeatures     r   
<listcomp>z@MapQuest._parse_json.<locals>.parse_location.<locals>.<listcomp>j   s,    HHHqQH
HHHr    z, )join)r2   	addr_keyslocations   `  r   parse_locationz,MapQuest._parse_json.<locals>.parse_location^   sB    	 	 	I IHHHIHHHH99X&&&r    c                 x     |           }| d         d         }| d         d         }t          |||f|           S )NlatLnglnglatr   )r2   r6   	longitudelatituder7   s       r   parse_featurez+MapQuest._parse_json.<locals>.parse_featurem   sG    %~g..H)%0Ix(/HHx&;WEEEr    c                 &    g | ]} |          S r.   r.   )r0   r2   r>   s     r   r3   z(MapQuest._parse_json.<locals>.<listcomp>v   s#    CCCwMM'**CCCr    r.   )r   jsonexactly_onefeaturesr>   r7   s       @@r   _parse_jsonzMapQuest._parse_jsonW   s    	?1%k2r>>4	' 	' 	'	F 	F 	F 	F 	F  	D =!---CCCC(CCCCr    )rA   r   limitboundsc                d   i }| j         |d<   ||d<   |||d<   |rd|d<   |r|                     |d          |d<   d                    | j        t	          |          f          }t          j        d	| j        j        |           t          | j
        |
          }|                     |||          S )af  
        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.

        :param int limit: Limit the maximum number of items in the
            response. This will be reset to one if ``exactly_one`` is True.

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

        :rtype: ``None``, :class:`geopy.location.Location` or a list of them, if
            ``exactly_one=False``.
        keyr6   N
maxResults   z#%(lat2)s,%(lon1)s,%(lat1)s,%(lon2)sboundingBox?z%s.geocode: %srA   r   )r   _format_bounding_boxr4   r   r   r	   debugr   __name__r   rC   _call_geocoder)	r   queryrA   r   rD   rE   paramsurlcallbacks	            r   geocodezMapQuest.geocodex   s    D u"z#(F<  	%#$F<  	$($=$==% %F=! hh()F*;*;<==%t~'>DDD4+EEE""3'"BBBr    )rA   r   c                >   i }| j         |d<   |                     |d          }||d<   d                    | j        t	          |          f          }t          j        d| j        j        |           t          | j
        |          }|                     |||          S )aL  
        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.

        :rtype: ``None``, :class:`geopy.location.Location` or a list of them, if
            ``exactly_one=False``.
        rG   z%(lat)s,%(lon)sr6   rK   z%s.reverse: %srL   rM   )r   _coerce_point_to_stringr4   r   r   r	   rO   r   rP   r   rC   rQ   )r   rR   rA   r   rS   pointrT   rU   s           r   reversezMapQuest.reverse   s    4 u,,U4EFF"zhh()F*;*;<==%t~'>DDD4+EEE""3'"BBBr    )T)rP   
__module____qualname____doc__r   r   r   r   rC   rV   rZ   __classcell__)r   s   @r   r
   r
      s          +L*L $$( (9
 9
 9
 9
 9
 9
 9
vD D D DJ $5C 5C 5C 5C 5Cv $$C $C $C $C $C $C $C $C $Cr    r
   N)	functoolsr   urllib.parser   geopy.geocoders.baser   r   geopy.locationr   
geopy.utilr	   __all__r
   r.   r    r   <module>re      s          " " " " " " ; ; ; ; ; ; ; ; # # # # # #      
HC HC HC HC HCx HC HC HC HC HCr    