o
    4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__ S/var/www/html/gps/gps/lib/python3.10/site-packages/geopy/geocoders/smartystreets.pyr      s   #zLiveAddress.__init__T   )exactly_oner   
candidatesc                C   sz   d|  krdkst d 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-tokenstreetr    z{url}?{query})urlqueryz%s.geocode: %s)r   )r   )
ValueErrorr   r   formatr   r   r	   debugr   __name__r   _parse_json_call_geocoder)r   r$   r   r   r    r#   callbackr   r   r   geocodeG   s   zLiveAddress.geocodec                 C   sR   d}t |tr%|t| v rtt||||jpd v r't|j|d S 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                    s0   t |sdS |r |d S  fdd|D S )z2
        Parse responses as JSON objects.
        Nr   c                    s   g | ]}  |qS r   )_format_structured_address).0cr   r   r   
<listcomp>   s    z+LiveAddress._parse_json.<locals>.<listcomp>)lenr5   )r   responser   r   r8   r   r)   {   s
   zLiveAddress._parse_jsonc                 C   sN   |d  d}|d  d}td|d |d f|r#|r#||f|S d|S )zA
        Pretty-print address and return lat, lon tuple.
        metadatalatitude	longitudez, delivery_line_1	last_lineN)getr   join)r   addressr=   r>   r   r   r   r5      s   z&LiveAddress._format_structured_address)T)r(   
__module____qualname____doc__r   r   r   r,   r4   r)   r5   __classcell__r   r   r   r   r
      s     5,
r
   N)	functoolsr   urllib.parser   geopy.adaptersr   	geopy.excr   geopy.geocoders.baser   r   geopy.locationr   
geopy.utilr	   __all__r
   r   r   r   r   <module>   s    