
    gm                         d Z ddlZddlmZ ddlmZmZmZ ddlm	Z	m
Z
mZ ddlmZ ddlmZ ddlmZmZ d	Z G d
 de	      Zy)z"
:class:`GeocoderDotUS` geocoder.
    N)	b64encode)	urlencodepy3kRequest)GeocoderDEFAULT_FORMAT_STRINGDEFAULT_TIMEOUT)Location)ConfigurationError)loggerjoin_filter)GeocoderDotUSc                   N     e Zd ZdZddeeddf fd	ZddZed        Z	d Z
 xZS )r   z
    GeocoderDotUS geocoder, documentation at:
        http://geocoder.us/

    Note that GeocoderDotUS does not support SSL.
    Nc                     t         t        |   ||||       |s|r|r|st        d      d| _        d| _        nd| _        d| _        || _        || _        y)a  
        :param str username:

        :param str password:

        :param str format_string: String containing '%s' where the
            string to geocode should be interpolated before querying the
            geocoder. For example: '%s, Mountain View, CA'. The default
            is just '%s'.

        :param int timeout: Time, in seconds, to wait for the geocoding service
            to respond before raising an :class:`geopy.exc.GeocoderTimedOut`
            exception.

            .. versionadded:: 0.97

        :param dict proxies: If specified, routes this geocoder's requests
            through the specified proxy. E.g., {"https": "192.0.2.0"}. For
            more information, see documentation on
            :class:`urllib2.ProxyHandler`.

            .. versionadded:: 0.96

        :param str user_agent: Use a custom User-Agent header.

            .. versionadded:: 1.12.0
        )format_stringtimeoutproxies
user_agentz)Username and password must both specifiedTz*http://geocoder.us/member/service/namedcsvFz#http://geocoder.us/service/namedcsvN)superr   __init__r   authenticatedapiusernamepassword)selfr   r   r   r   r   r   	__class__s          V/var/www/api/v1/venv_getwork_v1/lib/python3.12/site-packages/geopy/geocoders/dot_us.pyr   zGeocoderDotUS.__init__   sn    H 	mT+''V` 	, 	
 x(?  "&DCDH!&D<DH      c                    | j                   |z  }dj                  | j                  t        d|i      f      }t	        j
                  d| j                  j                  |       t        || j                               }| j                  ||d      }t        r|j                         j                  d      n|j                         }t        j                  t!        |t"              s|gn|      D cg c]  }| }	}t%        |	      sy|r| j'                  |	d	         S |	D 
cg c]  }
| j'                  |
       }}
d|v ry|S c c}w c c}
w )
a&  
        Geocode a location query.

        :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.

            .. versionadded:: 0.97
        ?addressz%s.geocode: %s)headersT)r   rawutf-8Nr   )r   joinr   r   r   debugr   __name__r   _get_headers_call_geocoderr   readdecodecsvreader
isinstancelistlen_parse_result)r   queryexactly_oner   	query_strurlpagecontentrplacesresresults               r   geocodezGeocoderDotUS.geocodeQ   s4     &&.	hh)Yy,A"BCD%t~~'>'>Dc4#4#4#67""3T"B15$))+$$W-499;zz#-gt#<
!A  	 
 6{%%fQi009?@#d((-F@v~M
 As   1	E"Ec           
         t        | D cg c]1  }t        |j                  d            dkD  s!|j                  d      3 c}      }d|v rd|d   v ry|j                  dd      |j                  dd      |j                  dd      |j                  d	d      |j                  d
d      g}|j                  dd      }|j                  dd      }|j                  dd      }t	        dt	        d|      |t	        d||g      g      }|j                  dd      }|j                  dd      }	|r|	rt        |      t        |	      f}
nyt        ||
|      S c c}w )zS
        Parse individual results. Different, but lazy actually, so... ok.
        =   errorzcouldn't findNnumberprefixstreettypesuffixcitystatezipz,  latlong)dictr0   splitgetr   floatr
   )r;   xplacer!   rF   rG   zip_codenamelatitude	longitudelatlons              r   r1   zGeocoderDotUS._parse_resultx   sU    #)C6aS->-BQWWS\6C
 e%.0 IIh%IIh%IIh%IIfd#IIh%
 yy&		'4(99UD)4W%eX./"
  99UD)IIfd+		8_eI&66Ffe,,; Ds
   "EEc                     i }| j                   rfdj                  | j                  | j                  f      }dj                  dt	        |j                  d            j                  d      f      }||d<   |S )N:rI   Basicr$   Authorization)r   r%   r   r   r   encoder+   )r   r"   username_passwordauths       r   r(   zGeocoderDotUS._get_headers   sr     #$--)G H88+227;<CCGL D (,GO$r   )TN)r'   
__module____qualname____doc__r   r	   r   r<   staticmethodr1   r(   __classcell__)r   s   @r   r   r      sB     /#2!h%N $- $-L	r   r   )r`   r,   base64r   geopy.compatr   r   r   geopy.geocoders.baser   r   r	   geopy.locationr
   	geopy.excr   
geopy.utilr   r   __all__r    r   r   <module>rk      sB      1 1 
 $ ( * SH Sr   