
    g                     v    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
e
      Zy)    )partial)	urlencode)AdapterHTTPError)GeocoderQuotaExceeded)DEFAULT_SENTINELGeocoder)Location)logger)LiveAddressc                   X     e Zd ZdZdZeededd fd
Zdeddd	Zd
 ZddZ	d Z
 x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                    t         	|   d|||||       || _        || _        d}| j                  d|| j
                  | _        y)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://N)super__init__auth_id
auth_tokenr   geocode_pathapi)
selfr   r   r   r   r   r   r   domain	__class__s
            ]/var/www/api/v1/venv_getwork_v1/lib/python3.12/site-packages/geopy/geocoders/smartystreets.pyr   zLiveAddress.__init__   sW    F 	!#+ 	 	
 $("&++vt7H7HI    T   )exactly_oner   
candidatesc                t   d|cxk  rdk  st        d       t        d      | j                  | j                  ||d}dj                  | j                  t        |            }t        j                  d| j                  j                  |       t        | j                  |      }| j                  |||	      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&   callbacks          r   geocodezLiveAddress.geocodeG   s    : Z%2%BCC &BCC ||//$	
 $$59I$J%t~~'>'>D4++E""3'"BBr   c                     d}t        |t              rg|t        |      j                         v rt	        t        |            |||j
                  xs dj                         v rt	        |j
                        |y y )Nzno active subscriptions found )
isinstancer   strlowerr   text)r   errorsearchs      r   _geocoder_exception_handlerz'LiveAddress._geocoder_exception_handlers   sm    0e-.U))+++CJ7UB%***1133+EJJ7UB 4 /r   c                     t        |      sy|r| j                  |d         S |D cg c]  }| j                  |       c}S c c}w )z2
        Parse responses as JSON objects.
        Nr   )len_format_structured_address)r   responser!   cs       r   r,   zLiveAddress._parse_json{   sI     8}228A;??@HI1D33A6IIIs   Ac                     |d   j                  d      }|d   j                  d      }t        dj                  |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@   rA   s       r   r;   z&LiveAddress._format_structured_address   sv     :&**:6J'++K8	IIw017;3GHI%-)Xy!
 	
AE
 	
r   )T)r+   
__module____qualname____doc__r   r   r   r/   r8   r,   r;   __classcell__)r   s   @r   r   r      sJ     %L %$( /Jj $*CXC	J

r   r   N)	functoolsr   urllib.parser   geopy.adaptersr   	geopy.excr   geopy.geocoders.baser   r   geopy.locationr	   
geopy.utilr
   __all__r    r   r   <module>rT      s-     " + + ; # 
C
( C
r   