o
    4cm                     @   s   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 de	ZdS )z"
:class:`GeocoderDotUS` geocoder.
    N)	b64encode)	urlencodepy3kRequest)GeocoderDEFAULT_FORMAT_STRINGDEFAULT_TIMEOUT)Location)ConfigurationError)loggerjoin_filter)GeocoderDotUSc                       sL   e Zd ZdZddeeddf fdd	ZdddZedd	 Z	d
d Z
  ZS )r   z
    GeocoderDotUS geocoder, documentation at:
        http://geocoder.us/

    Note that GeocoderDotUS does not support SSL.
    Nc                    sZ   t t| j||||d |s|r|r|stdd| _d| _nd| _d| _|| _|| _dS )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__ L/var/www/html/gps/gps/lib/python3.10/site-packages/geopy/geocoders/dot_us.pyr      s   
$
zGeocoderDotUS.__init__Tc           
         s    j | }d jtd|if}td jj| t| 	 d} j
||dd}tr3| dn| }dd	 tt|tsD|gn|D }t|sOd
S |rX |d S  fdd	|D }	d
|	v rgd
S |	S )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-8c                 S   s   g | ]}|qS r   r   ).0rr   r   r   
<listcomp>h   s    z)GeocoderDotUS.geocode.<locals>.<listcomp>Nr   c                    s   g | ]}  |qS r   )_parse_result)r"   resr   r   r   r$   s   s    )r   joinr   r   r   debugr   __name__r   _get_headers_call_geocoderr   readdecodecsvreader
isinstancelistlenr%   )
r   queryexactly_oner   	query_strurlpagecontentplacesresultr   r'   r   geocodeQ   s(   
zGeocoderDotUS.geocodec           
      C   s   t dd | D }d|v rd|d v rdS |dd|dd|dd|d	d|d
dg}|dd}|dd}|dd}tdtd||td||gg}|dd}|dd}|rk|rkt|t|f}	ndS t||	|S )zS
        Parse individual results. Different, but lazy actually, so... ok.
        c                 S   s(   g | ]}t |d dkr|d qS )=   )r3   split)r"   xr   r   r   r$      s   ( z/GeocoderDotUS._parse_result.<locals>.<listcomp>errorzcouldn't findNnumberprefixstreettypesuffixcitystatezipz,  latlong)dictgetr   floatr	   )
r;   placer   rG   rH   zip_codenamelatitude	longitudelatlonr   r   r   r%   x   s4   




zGeocoderDotUS._parse_resultc                 C   sF   i }| j r!d| j| jf}ddt|ddf}||d< |S )N:rJ   Basicr!   Authorization)r   r(   r   r   r   encoder.   )r   r   username_passwordauthr   r   r   r+      s   zGeocoderDotUS._get_headers)TN)r*   
__module____qualname____doc__r   r   r   r<   staticmethodr%   r+   __classcell__r   r   r   r   r      s    	
4'
&r   )r^   r/   base64r   geopy.compatr   r   r   geopy.geocoders.baser   r   r   geopy.locationr	   	geopy.excr
   
geopy.utilr   r   __all__r   r   r   r   r   <module>   s    