Ë
    Ï.fc1  ã                   óŽ   — 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   zàGeoNames 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
            €úWC:\Users\user\Documents\project_loop\venv\Lib\site-packages\geopy/geocoders/geonames.pyr   zGeoNames.__init__&   sª   ø€ ô^ 	‰ÑØØØØ!Ø#Ø+ð 	ô 	
ð !ˆŒð  Ÿ;›;©°×0AÒ0AÐBð 	Œð  Ÿ;›;©°×0AÒ0AÐBð 	Ôð  Ÿ;›;©°×0HÒ0HÐIð 	Ôð  Ÿ;›;©°×0BÒ0BÐ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Ø˜Ÿ™Ð'ð
ˆñ
 Ø�M‰M˜=¨,Ð7Ô8áØˆGÜ�gœsÔ#Ø�iˆGØ#ò 	5ˆLØ�M‰M˜9 lÐ3Õ4ð	5ñ Ø�M‰M˜.Ô)Ø�h‰h˜Ÿ™¤)¨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Ñ3°EÓ:×@Ñ@ÀÓE‰HˆC�ð Ð4Ò4ÙÜ ð/óð ð ×@Ñ@ØØØð Aó ˆFð
 —(‘(˜D×,Ñ,¬i¸Ó.?Ð@ÓA‰CØ Ò-ÙÜ ØRóð ð ×5Ñ5ØØØ)ð 6ó ˆFð
 —(‘(˜D×3Ñ3´Y¸vÓ5FÐGÓH‰Cä$ØAÐDTÑTóð ô 	�‰Ð% t§~¡~×'>Ñ'>ÀÔDÜ˜4×+Ñ+¸ÔEˆØ×"Ñ" 3¨¸'Ð"ÓBÐBøôC ò 	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*   € àØØŸ™ñ
ˆñ
 Ø$0ˆF�=Ñ!Øˆ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)   € àØØŸ™ñ
ˆñ
 Ø!ˆF�6‰NØˆ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Ñ3°EÓ:×@Ñ@ÀÓE‰HˆC�ð
 ØØŸ™ñ
ˆð �h‰h˜×)Ñ)¬9°VÓ+<Ð=Ó>ˆä�‰Ð.°·±×0GÑ0GÈÔMØ×"Ñ" 3¨×(AÑ(AÈ7Ð"Ó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   € Ø�h‰h�xÓ ˆÙØ�w‘<ˆDØ˜)‘nˆGà×!Ñ!Ð"CÔDÜ4°WÓ=Ð=Ø�rŠzÜ3°GÓ<Ð<Ø�|Ñ#Ü+¨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Ô'à—l‘l <Ó0ˆØÐð
 " +Ñ.ˆJÜ(¨¸ÔBÐBä% k°xÔ@Ð@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­   € ð —y‘y ¨Ó-ˆHØŸ	™	 %¨Ó.ˆIÙ™IÜ  ›?�Ü! )Ó,‘	ààŸ	™	 &Ó)ˆIØ—I‘I˜l¨DÓ1ˆEØ—i‘i ¨tÓ4ˆGà—y‘yØ&¨¨wÐ7Ö=�qº1’Ò=óˆHô ˜H x°Ð&;¸UÓCÐCùò >s   ÂB*ÂB*r   )rd   ri   Úlen)r'   Údocr+   Úplacesr   rx   s         r)   r<   zGeoNames._parse_jsonI  s_   € ð —‘˜ RÓ(ˆØ×Ñ˜cÔ"Ü�6Œ{Øò	Dñ, Ù˜f Q™iÓ(Ð(à39Ö:¨%‘J˜uÕ%Ò:Ð:ùÒ: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*   