
    gc1                         d dl mZ d dlmZ d dlmZmZmZmZm	Z	 d dl
mZmZ d dlmZ d dlmZmZmZ d dlmZ dZ G d	 d
e      Zy)    )partial)	urlencode)GeocoderAuthenticationFailureGeocoderInsufficientPrivilegesGeocoderQueryErrorGeocoderQuotaExceededGeocoderServiceError)DEFAULT_SENTINELGeocoder)Location)ensure_pytz_is_installedfrom_fixed_gmt_offsetfrom_timezone_name)logger)GeoNamesc                        e Zd ZdZdZdZdZdZeededddd	 fd

Z	deddddZ
dedddddZd Zd ZeddZd Zd Zd Z xZS )r   zGeoNames geocoder.

    Documentation at:
        http://www.geonames.org/export/geonames-search.html

    Reverse geocoding documentation at:
        http://www.geonames.org/export/web-services.html#findNearbyPlaceName
    z/searchJSONz/findNearbyPlaceNameJSONz/findNearbyJSONz/timezoneJSONNhttpzapi.geonames.org)timeoutproxies
user_agentssl_contextadapter_factoryschemedomainc                N   t         	|   ||||||       || _        | j                  d|| j                  | _        | j                  d|| j                  | _        | j                  d|| j                  | _	        | j                  d|| j                  | _        y)a  

        :param str username: GeoNames username, required. Sign up here:
            http://www.geonames.org/login

        :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

        :param str scheme:
            See :attr:`geopy.geocoders.options.default_scheme`. Note that
            at the time of writing GeoNames doesn't support `https`, so
            the default scheme is `http`. The value of
            :attr:`geopy.geocoders.options.default_scheme` is not respected.
            This parameter is present to make it possible to switch to
            `https` once GeoNames adds support for it.

        :param str domain: base api domain

            .. versionadded:: 2.4
        )r   r   r   r   r   r   z://N)super__init__usernamer   geocode_pathapireverse_pathapi_reversereverse_nearby_pathapi_reverse_nearbytimezone_pathapi_timezone)
selfr   r   r   r   r   r   r   r   	__class__s
            X/var/www/api/v1/venv_getwork_v1/lib/python3.12/site-packages/geopy/geocoders/geonames.pyr   zGeoNames.__init__&   s    ^ 	!#+ 	 	
 !  ;;0A0AB 	  ;;0A0AB 	  ;;0H0HI 	  ;;0B0BC 	    T)exactly_oner   countrycountry_biasc                   d|fd| j                   fg}|r|j                  d|f       |sg }t        |t              r|g}|D ]  }|j                  d|f        |r|j                  d       dj	                  | j
                  t        |      f      }t        j                  d| j                  j                  |       t        | j                  |      }	| j                  ||	|	      S )
a  
        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 country: Limit records to the specified countries.
            Two letter country code ISO-3166 (e.g. ``FR``). Might be
            a single string or a list of strings.
        :type country: str or list

        :param str country_bias: Records from the country_bias are listed first.
            Two letter country code ISO-3166.

        :rtype: ``None``, :class:`geopy.location.Location` or a list of them, if
            ``exactly_one=False``.
        qr   countryBiasr,   )maxRows   ?z%s.geocode: %sr+   r   )r   append
isinstancestrjoinr    r   r   debugr(   __name__r   _parse_json_call_geocoder)
r'   queryr+   r   r,   r-   paramscountry_itemurlcallbacks
             r)   geocodezGeoNames.geocodel   s    D %L'

 MM=,78Ggs#iG#LMM9l34 $ MM.)hh)F"345%t~~'>'>D4++E""3'"BBr*   findNearbyPlaceName)r+   r   feature_codelangfind_nearby_typec                v   	 | j                  |      j                  d      \  }}|dk(  rH|rt        d      | j                  |||      }	dj	                  | j
                  t        |	      f      }
n[|dk(  rH|rt        d      | j                  |||	      }	dj	                  | j                  t        |	      f      }
nt        d
|z        t        j                  d| j                  j                  |
       t        | j                  |      }| j!                  |
||      S # t        $ r t        d      w xY w)a  
        Return an address by location point.

        :param query: The coordinates for which you wish to obtain the
            closest human-readable addresses.
        :type query: :class:`geopy.point.Point`, list or tuple of ``(latitude,
            longitude)``, or string as ``"%(latitude)s, %(longitude)s"``.

        :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 str feature_code: A GeoNames feature code

        :param str lang: language of the returned ``name`` element (the pseudo
            language code 'local' will return it in local language)
            Full list of supported languages can be found here:
            https://www.geonames.org/countries/

        :param str find_nearby_type: A flag to switch between different
            GeoNames API endpoints. The default value is ``findNearbyPlaceName``
            which returns the closest populated place. Another currently
            implemented option is ``findNearby`` which returns
            the closest toponym for the lat/lng query.

        :rtype: ``None``, :class:`geopy.location.Location` or a list of them, if
            ``exactly_one=False``.

        ,"Must be a coordinate pair or PointrD   zMfind_nearby_type=findNearbyPlaceName doesn't support the `feature_code` param)latlngrF   r3   
findNearbyz<find_nearby_type=findNearby doesn't support the `lang` param)rK   rL   rE   z/`%s` find_nearby_type is not supported by geopyz%s.reverse: %sr4   r5   )_coerce_point_to_stringsplit
ValueError&_reverse_find_nearby_place_name_paramsr9   r"   r   _reverse_find_nearby_paramsr$   r   r   r:   r(   r;   r   r<   r=   )r'   r>   r+   r   rE   rF   rG   rK   rL   r?   rA   rB   s               r)   reversezGeoNames.reverse   sa   X	C33E:@@EHC 44 /  @@ A F
 ((D,,i.?@AC- R  55) 6 F
 ((D33Yv5FGHC$ADTT  	%t~~'>'>D4++E""3'"BBC  	CABB	Cs   #D# #D8c                 4    ||| j                   d}|r||d<   |S )NrK   rL   r   featureCoder   )r'   rK   rL   rE   r?   s        r)   rR   z$GeoNames._reverse_find_nearby_params   s*    

 $0F=!r*   c                 4    ||| j                   d}|r||d<   |S )NrU   rF   rW   )r'   rK   rL   rF   r?   s        r)   rQ   z/GeoNames._reverse_find_nearby_place_name_params   s)    

 !F6Nr*   r5   c                   t                	 | j                  |      j                  d      \  }}||| j                  d}dj                  | j                  t        |      f      }t        j                  d| j                  j                  |       | j                  || j                  |      S # t        $ r t        d      w xY w)aO  
        Find the timezone for a point in `query`.

        GeoNames always returns a timezone: if the point being queried
        doesn't have an assigned Olson timezone id, a ``pytz.FixedOffset``
        timezone is used to produce the :class:`geopy.timezone.Timezone`.

        :param query: The coordinates for which you want a timezone.
        :type query: :class:`geopy.point.Point`, list or tuple of (latitude,
            longitude), or string as "%(latitude)s, %(longitude)s"

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

        :rtype: :class:`geopy.timezone.Timezone`.
        rI   rJ   rU   r3   z%s.reverse_timezone: %sr5   )r   rN   rO   rP   r   r9   r&   r   r   r:   r(   r;   r=   _parse_json_timezone)r'   r>   r   rK   rL   r?   rA   s          r)   reverse_timezonezGeoNames.reverse_timezone  s    & 	!"	C33E:@@EHC
 
 hh))9V+<=>.0G0GM""3(A(A7"SS  	CABB	Cs   #B. .Cc                     |j                  d      }|rP|d   }|d   }|j                  d      rt        |      |dk(  rt        |      |dv rt	        |      t        |      y )Nstatusvaluemessagezuser account not enabled to use
   )         )get
startswithr   r   r   r	   )r'   bodyerrcoder_   s        r)   _raise_for_errorzGeoNames._raise_for_error-  st    hhx w<D)nG!!"CD4W==rz3G<<|#+G44&w// r*   c                     | j                  |       |j                  d      }||d   }t        ||      S t        ||      S )N
timezoneId	rawOffset)raw)ri   rd   r   r   )r'   responsetimezone_id
raw_offsets       r)   rZ   zGeoNames._parse_json_timezone;  sJ    h'll<0
 "+.J(BB%kx@@r*   c                     |j                  dg       }| j                  |       t        |      syd }|r ||d         S |D cg c]
  } ||       c}S c c}w )z+
        Parse JSON response body.
        geonamesNc                 ^   | j                  dd      }| j                  dd      }|r|rt        |      }t        |      }ny| j                  d      }| j                  dd      }| j                  dd      }dj                  |||fD cg c]  }|s|	 c}      }t        |||f|       S c c}w )z,
            Parse each record.
            rK   NrL   name
adminName1countryNamez, )rd   floatr9   r   )placelatitude	longitude	placenamestater,   xlocations           r)   
parse_codez(GeoNames._parse_json.<locals>.parse_codeR  s     yy-H		%.II ?!),			&)IIIlD1Eiit4Gyy&w7=7q17=H Hx&;UCC >s   B*B*r   )rd   ri   len)r'   docr+   placesr   rx   s         r)   r<   zGeoNames._parse_jsonI  sc     R(c"6{	D, fQi((39:6%Ju%6:::s   A)r;   
__module____qualname____doc__r   r!   r#   r%   r
   r   rC   rS   rR   rQ   r[   ri   rZ   r<   __classcell__)r(   s   @r)   r   r      s     !L-L+#M %$( %D
T $5Cv $2OCb 2B #TJ0A";r*   r   N)	functoolsr   urllib.parser   	geopy.excr   r   r   r   r	   geopy.geocoders.baser
   r   geopy.locationr   geopy.timezoner   r   r   
geopy.utilr   __all__r    r*   r)   <module>r      s?     "  < # 
 
T;x T;r*   