a
    }c                     @   sX   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 deZd	S )
    )partial)	urlencode)DEFAULT_SENTINELGeocoderLocation)logger)MapQuestc                       sh   e Zd ZdZdZdZdeededdd fdd
Zdd
dZd	edddddZ	d	edddZ
  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          	         sZ   t  j||||||d || _|d| _d| j| j| jf | _d| j| j| jf | _	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	%s://%s%sN)
super__init__api_keystripr   r
   geocode_pathgeocode_apireverse_pathreverse_api)	selfr   r
   r   r   r   r   r   r   	__class__ T/var/www/html/django/DPS/env/lib/python3.9/site-packages/geopy/geocoders/mapquest.pyr      s    (	zMapQuest.__init__Tc                    sV   |d d d }|g krdS dd fdd |r@ |d S  fd	d
|D S dS )z7Returns location, (latitude, longitude) from json feed.resultsr   	locationsNc                    s$   g d} fdd|D }d |S )N)ZstreetZ
adminArea6Z
adminArea5Z
adminArea4Z
adminArea3Z
adminArea2Z
adminArea1Z
postalCodec                    s   g | ]}  |r | qS r   )get).0kfeaturer   r   
<listcomp>j       z@MapQuest._parse_json.<locals>.parse_location.<locals>.<listcomp>z, )join)r%   Z	addr_keyslocationr   r$   r   parse_location^   s    z,MapQuest._parse_json.<locals>.parse_locationc                    s0    | }| d d }| d d }t |||f| S )NZlatLngZlngZlatr   )r%   r)   Z	longitudeZlatitude)r*   r   r   parse_featurem   s    z+MapQuest._parse_json.<locals>.parse_featurec                    s   g | ]} |qS r   r   )r"   r%   )r+   r   r   r&   v   r'   z(MapQuest._parse_json.<locals>.<listcomp>r   )r   jsonexactly_onefeaturesr   )r+   r*   r   _parse_jsonW   s    zMapQuest._parse_json)r-   r   limitboundsc          	      C   s   i }| j |d< ||d< |dur&||d< |r2d|d< |rF| |d|d< d| jt|f}td	| jj| t	| j
|d
}| j|||d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``.
        keyr)   NZ
maxResults   z#%(lat2)s,%(lon1)s,%(lat1)s,%(lon2)sZboundingBox?z%s.geocode: %sr-   r   )r   Z_format_bounding_boxr(   r   r   r   debugr   __name__r   r/   _call_geocoder)	r   queryr-   r   r0   r1   paramsurlcallbackr   r   r   geocodex   s    "
zMapQuest.geocode)r-   r   c                C   sf   i }| j |d< | |d}||d< d| jt|f}td| jj| t	| j
|d}| j|||d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``.
        r2   z%(lat)s,%(lon)sr)   r4   z%s.reverse: %sr5   r6   )r   Z_coerce_point_to_stringr(   r   r   r   r7   r   r8   r   r/   r9   )r   r:   r-   r   r;   pointr<   r=   r   r   r   reverse   s    
zMapQuest.reverse)T)r8   
__module____qualname____doc__r   r   r   r   r/   r>   r@   __classcell__r   r   r   r   r	      s(   ;
%;r	   N)	functoolsr   urllib.parser   Zgeopy.geocoders.baser   r   Zgeopy.locationr   Z
geopy.utilr   __all__r	   r   r   r   r   <module>   s   