
    N}bgc1                         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dS )    )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                $   t                                          ||||||           || _        | j        d|| j        | _        | j        d|| j        | _        | j        d|| j        | _	        | j        d|| j
        | _        dS )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
            k/home/e360mart.nyusoft.in/public_html/e360mart_env/lib/python3.11/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|                    d|f           |sg }t          |t                    r|g}|D ]}|                    d|f           |r|                    d           d                    | j        t          |          f          }t          j        d| j	        j
        |           t          | 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'

  	9MM=,7888 	Ggs## 	 iG# 	5 	5LMM9l34444 	*MM.)))hh)F"3"3455%t~'>DDD4+EEE""3'"BBBr*   findNearbyPlaceName)r+   r   feature_codelangfind_nearby_typec                   	 |                      |                              d          \  }}n# t          $ r t          d          w xY w|dk    rS|rt          d          |                     |||          }	d                    | j        t          |	          f          }
nk|dk    rS|rt          d          |                     |||	          }	d                    | j        t          |	          f          }
nt          d
|z            t          j        d| j        j        |
           t          | j        |          }|                     |
||          S )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   s   X	C33E::@@EEHC 	C 	C 	CABBB	C 444  /   @@ A  F
 ((D,i.?.?@AACC--  R   55) 6  F
 ((D3Yv5F5FGHHCC$ADTT   	%t~'>DDD4+EEE""3'"BBBs	   +. Ac                 *    ||| 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   s2    
 

  	1$0F=!r*   c                 *    ||| j         d}|r||d<   |S )NrU   rF   rW   )r'   rK   rL   rF   r?   s        r)   rQ   z/GeoNames._reverse_find_nearby_place_name_params   s1    
 

  	"!F6Nr*   r5   c                   t                       	 |                     |                              d          \  }}n# t          $ r t          d          w xY w||| j        d}d                    | j        t          |          f          }t          j	        d| j
        j        |           |                     || j        |          S )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::@@EEHC 	C 	C 	CABBB	C 
 
 hh)9V+<+<=>>.0GMMM""3(A7"SSSs	   +< Ac                 
   |                     d          }|rk|d         }|d         }|                    d          rt          |          |dk    rt          |          |dv rt	          |          t          |          d S )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-  s    hhx   
	0w<D)nG!!"CDD >4W===rzz3G<<<|##+G444&w///
	0 
	0r*   c                     |                      |           |                    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;  s_    h'''ll<00
 "+.J(BBBB%kx@@@@r*   c                     |                     dg           }|                     |           t          |          sdS d |r |d                   S fd|D             S )z+
        Parse JSON response body.
        geonamesNc                    |                      dd          }|                      dd          }|r!|rt          |          }t          |          }ndS |                      d          }|                      dd          }|                      dd          }d                    d |||fD                       }t          |||f|           S )	z,
            Parse each record.
            rK   NrL   name
adminName1countryNamez, c                     g | ]}||S  rx   ).0xs     r)   
<listcomp>z<GeoNames._parse_json.<locals>.parse_code.<locals>.<listcomp>c  s    ===q1====r*   )rd   floatr9   r   )placelatitude	longitude	placenamestater,   locations          r)   
parse_codez(GeoNames._parse_json.<locals>.parse_codeR  s     yy--H		%..I I  ??!),,		t		&))IIIlD11Eiit44Gyy==Yw7=== H Hx&;UCCCr*   r   c                 &    g | ]} |          S rx   rx   )ry   r}   r   s     r)   r{   z(GeoNames._parse_json.<locals>.<listcomp>k  s#    :::%JJu%%:::r*   )rd   ri   len)r'   docr+   placesr   s       @r)   r<   zGeoNames._parse_jsonI  s     R((c"""6{{ 	4	D 	D 	D,  	;:fQi(((::::6::::r*   )r;   
__module____qualname____doc__r   r!   r#   r%   r
   r   rC   rS   rR   rQ   r[   ri   rZ   r<   __classcell__)r(   s   @r)   r   r      sW         !L-L+#M %$( %D
 D
 D
 D
 D
 D
 D
T $5C 5C 5C 5C 5Cv $2OC OC OC OC OCb     2B #T #T #T #T #TJ0 0 0A A 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   rx   r*   r)   <module>r      s$         " " " " " "              < ; ; ; ; ; ; ; # # # # # #         
      
T; T; T; T; T;x T; T; T; T; T;r*   