
    g                     ^    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y	)
    )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         	|   ||||||       || _        |j                  d      | _        | j
                  d| j                  | j                  | _        | j
                  d| j                  | j                  | _	        y)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
            X/var/www/api/v1/venv_getwork_v1/lib/python3.12/site-packages/geopy/geocoders/mapquest.pyr   zMapQuest.__init__   s    P 	!#+ 	 	
 ll3'  ;;T5F5FG 	  ;;T5F5FG 	    Tc                     |d   d   d   }|g k(  ryd fd}|r ||d         S |D cg c]
  } ||       c}S c c}w )z7Returns location, (latitude, longitude) from json feed.resultsr   	locationsNc                 ~    g d}|D cg c]  }| j                  |      s| |    }}dj                  |      S c c}w )N)street
adminArea6
adminArea5
adminArea4
adminArea3
adminArea2
adminArea1
postalCodez, )getjoin)feature	addr_keysklocations       r   parse_locationz,MapQuest._parse_json.<locals>.parse_location^   sB    	I -6HIqQ
IHH99X&& Is   ::c                 R     |       }| d   d   }| d   d   }t        |||f|       S )NlatLnglnglatr   )r/   r2   	longitudelatituder3   s       r   parse_featurez+MapQuest._parse_json.<locals>.parse_featurem   s?    %g.H)%0Ix(/HHx&;WEEr     )r   jsonexactly_onefeaturesr:   r/   r3   s         @r   _parse_jsonzMapQuest._parse_jsonW   s\    	?1%k2r>	'	F  !--:BC(wM'*(CCCs   >)r=   r   limitboundsc                p   i }| j                   |d<   ||d<   |||d<   |rd|d<   |r| j                  |d      |d<   dj                  | j                  t	        |      f      }t        j                  d| j                  j                  |       t        | j                  |	      }| 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``.
        keyr2   
maxResults   z#%(lat2)s,%(lon1)s,%(lat1)s,%(lon2)sboundingBox?z%s.geocode: %sr=   r   )r   _format_bounding_boxr.   r   r   r	   debugr   __name__r   r?   _call_geocoder)	r   queryr=   r   r@   rA   paramsurlcallbacks	            r   geocodezMapQuest.geocodex   s    D u"z#(F< #$F< $($=$==%F=! hh(()F*;<=%t~~'>'>D4++E""3'"BBr    )r=   r   c                J   i }| j                   |d<   | j                  |d      }||d<   dj                  | j                  t	        |      f      }t        j                  d| j                  j                  |       t        | j                  |      }| 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``.
        rC   z%(lat)s,%(lon)sr2   rG   z%s.reverse: %srH   rI   )r   _coerce_point_to_stringr.   r   r   r	   rK   r   rL   r   r?   rM   )r   rN   r=   r   rO   pointrP   rQ   s           r   reversezMapQuest.reverse   s    4 u,,U4EF"zhh(()F*;<=%t~~'>'>D4++E""3'"BBr    )T)rL   
__module____qualname____doc__r   r   r   r   r?   rR   rV   __classcell__)r   s   @r   r
   r
      sa     +L*L $$( (9
vDJ $5Cv $$C $Cr    r
   N)	functoolsr   urllib.parser   geopy.geocoders.baser   r   geopy.locationr   
geopy.utilr	   __all__r
   r;   r    r   <module>ra      s)     " ; # 
HCx HCr    