a
    }c                     @   sp   d dl mZ d dlmZ 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)AdapterHTTPError)GeocoderQuotaExceeded)DEFAULT_SENTINELGeocoder)Location)logger)LiveAddressc                       s^   e Zd ZdZdZeededd fdd
Zdedd	d
dZdd ZdddZ	dd Z
  ZS )r
   zGeocoder using the LiveAddress API provided by SmartyStreets.

    Documentation at:
        https://smartystreets.com/docs/cloud/us-street-api
    z/street-addressN)timeoutproxies
user_agentssl_contextadapter_factoryc          	         s@   t  jd|||||d || _|| _d}d| j|| jf | _dS )a  

        :param str auth_id: Valid `Auth ID` from SmartyStreets.

        :param str auth_token: Valid `Auth Token` from SmartyStreets.

        :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
        https)schemer   r   r   r   r   zapi.smartystreets.comz	%s://%s%sN)super__init__auth_id
auth_tokenr   geocode_pathapi)	selfr   r   r   r   r   r   r   domain	__class__ Y/var/www/html/django/DPS/env/lib/python3.9/site-packages/geopy/geocoders/smartystreets.pyr      s    #zLiveAddress.__init__T   )exactly_oner   
candidatesc                C   st   d|  krdksn t d| j| j||d}dj| jt|d}td| jj	| t
| j|d}| j|||d	S )
a3  
        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 candidates: An integer between 1 and 10 indicating the max
            number of candidate addresses to return if a valid address
            could be found.

        :rtype: ``None``, :class:`geopy.location.Location` or a list of them, if
            ``exactly_one=False``.
        r   
   z#candidates must be between 1 and 10)zauth-idz
auth-tokenZstreetr    z{url}?{query})urlqueryz%s.geocode: %s)r   )r   )
ValueErrorr   r   formatr   r   r	   debugr   __name__r   _parse_jsonZ_call_geocoder)r   r#   r   r   r    r"   callbackr   r   r   geocodeG   s    zLiveAddress.geocodec                 C   sN   d}t |trJ|t| v r,tt||||jp6d v rJt|j|d S )Nzno active subscriptions found )
isinstancer   strlowerr   text)r   errorsearchr   r   r   _geocoder_exception_handlers   s    
z'LiveAddress._geocoder_exception_handlerc                    s4   t |sdS |r |d S  fdd|D S dS )z2
        Parse responses as JSON objects.
        Nr   c                    s   g | ]}  |qS r   )_format_structured_address).0cr   r   r   
<listcomp>       z+LiveAddress._parse_json.<locals>.<listcomp>)lenr3   )r   responser   r   r6   r   r(   {   s
    zLiveAddress._parse_jsonc                 C   sJ   |d  d}|d  d}td|d |d f|rB|rB||fnd|S )zA
        Pretty-print address and return lat, lon tuple.
        metadatalatitude	longitudez, Zdelivery_line_1	last_lineN)getr   join)r   addressr<   r=   r   r   r   r3      s    z&LiveAddress._format_structured_address)T)r'   
__module____qualname____doc__r   r   r   r*   r2   r(   r3   __classcell__r   r   r   r   r
      s   5,
r
   N)	functoolsr   urllib.parser   Zgeopy.adaptersr   Z	geopy.excr   Zgeopy.geocoders.baser   r   Zgeopy.locationr   Z
geopy.utilr	   __all__r
   r   r   r   r   <module>   s   