Ë
    Ï.fˆ  ã                   ór   — d dl mZ d dlmZ d dlmZmZmZ d dlm	Z	m
Z
 d dlmZ d dlmZ dZ G d„ d	e
«      Zy
)é    )Úpartial)Ú	urlencode)ÚGeocoderAuthenticationFailureÚGeocoderQuotaExceededÚGeocoderServiceError)ÚDEFAULT_SENTINELÚGeocoder)ÚLocation)Úlogger)ÚGeocodeFarmc                   ól   ‡ — e Zd ZdZdZdZ	 deededddœˆ fd„Zdedœd	„Zdedœd
„Z	d„ Z
d„ Zd„ Zˆ xZS )r   z‚Geocoder using the GeocodeFarm API.

    Documentation at:
        https://www.geocode.farm/geocoding/free-api-documentation/
    z/v3/json/forward/z/v3/json/reverse/N)ÚtimeoutÚproxiesÚ
user_agentÚssl_contextÚadapter_factoryÚschemec                óÊ   •— t         ‰	| �  ||||||¬«       || _        d}| j                  ›d|›| j                  ›�| _        | j                  ›d|›| j                  ›�| _        y)a(  

        :param str api_key: (optional) The API key required by GeocodeFarm
            to perform geocoding requests.

        :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`.
        )r   r   r   r   r   r   zwww.geocode.farmz://N)ÚsuperÚ__init__Úapi_keyr   Úgeocode_pathÚapiÚreverse_pathÚreverse_api)
Úselfr   r   r   r   r   r   r   ÚdomainÚ	__class__s
            €úZC:\Users\user\Documents\project_loop\venv\Lib\site-packages\geopy/geocoders/geocodefarm.pyr   zGeocodeFarm.__init__   sq   ø€ ôJ 	‰ÑØØØØ!Ø#Ø+ð 	ô 	
ð ˆŒØ#ˆàŸ;›;©°×0AÒ0AÐBð 	Œð  Ÿ;›;©°×0AÒ0AÐBð 	Õó    T)Úexactly_oner   c                ó8  — d|i}| j                   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.

        :rtype: ``None``, :class:`geopy.location.Location` or a list of them, if
            ``exactly_one=False``.
        ÚaddrÚkeyú?z%s.geocode: %s©r!   ©r   )r   Újoinr   r   r   Údebugr   Ú__name__r   Ú_parse_jsonÚ_call_geocoder)r   Úqueryr!   r   ÚparamsÚurlÚcallbacks          r   ÚgeocodezGeocodeFarm.geocodeP   s‡   € ð$ �Eð
ˆð �<Š<Ø ŸL™LˆF�5‰MØ�h‰h˜Ÿ™¤)¨FÓ"3Ð4Ó5ˆÜ�‰Ð% t§~¡~×'>Ñ'>ÀÔDÜ˜4×+Ñ+¸ÔEˆØ×"Ñ" 3¨¸'Ð"ÓBÐBr    c                ó²  — 	 | j                  |«      j                  d«      \  }}||dœ}| j                  r| j                  |d<   dj	                  | j
                  t        |«      f«      }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. GeocodeFarm's API will always return at most one
            result.

        :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: ``None``, :class:`geopy.location.Location` or a list of them, if
            ``exactly_one=False``.
        ú,z"Must be a coordinate pair or Point)ÚlatÚlonr$   r%   z%s.reverse: %sr&   r'   )Ú_coerce_point_to_stringÚsplitÚ
ValueErrorr   r(   r   r   r   r)   r   r*   r   r+   r,   )	r   r-   r!   r   r4   r5   r.   r/   r0   s	            r   ÚreversezGeocodeFarm.reversek   sÎ   € ð*	CØ×3Ñ3°EÓ:×@Ñ@ÀÓE‰HˆC�ð Øñ
ˆð �<Š<Ø ŸL™LˆF�5‰MØ�h‰h˜×(Ñ(¬)°FÓ*;Ð<Ó=ˆÜ�‰Ð% t§~¡~×'>Ñ'>ÀÔDÜ˜4×+Ñ+¸ÔEˆØ×"Ñ" 3¨¸'Ð"ÓBÐBøô ò 	CÜÐAÓBÐBð	Cús   ‚#C ÃCc                 óª  — g }|j                  d«      D ]¼  }|j                  di «      }|j                  di «      }|j                  dd «      }|j                  dd «      }|j                  dd «      }|€|j                  dd «      }|€|j                  dd «      }|r|rt        |«      }t        |«      }|j                  t        |||f|«      «       Œ¾ |S )	NÚRESULTSÚCOORDINATESÚADDRESSÚlatitudeÚ	longitudeÚaddress_returnedÚaddressÚformatted_address)ÚgetÚfloatÚappendr
   )	r   ÚresultsÚplacesÚresultÚcoordinatesrA   r>   r?   Ú	placenames	            r   Ú_parse_codezGeocodeFarm._parse_code�   sØ   € àˆØ—k‘k )Ó,ò 	NˆFØ Ÿ*™* ]°BÓ7ˆKØ—j‘j ¨BÓ/ˆGØ"—‘ z°4Ó8ˆHØ#Ÿ™¨°TÓ:ˆIØŸ™Ð$6¸Ó=ˆIØÐ Ø#ŸK™K¨	°4Ó8�	ØÐ Ø"ŸJ™JÐ':¸DÓA�	Ù™IÜ  ›?�Ü! )Ó,�	Ø�M‰Mœ( 9¨x¸Ð.CÀVÓLÕMð	Nð ˆr    c                 ó²   — |€y |d   }| j                  |«       d|j                  di «      j                  dd«      v ry | j                  |«      }|r|d   S |S )NÚgeocoding_resultsÚ
NO_RESULTSÚSTATUSÚstatusÚ r   )Ú_check_for_api_errorsrC   rK   )r   Ú
api_resultr!   rM   rG   s        r   r+   zGeocodeFarm._parse_json¢   so   € ØÐØØ&Ð':Ñ;ÐØ×"Ñ"Ð#4Ô5àÐ,×0Ñ0°¸2Ó>×BÑBÀ8ÈRÓPÑPØà×!Ñ!Ð"3Ó4ˆÙØ˜!‘9ÐàˆMr    c                 óø   — |j                  di «      }d|j                  dd«      v ry|j                  dd«      dk(  }|s<|j                  d«      }t        t        dœ}|j                  |t        «      } ||«      ‚y)	zc
        Raise any exceptions if there were problems reported
        in the api response.
        rO   rN   rP   rQ   NÚSUCCESSÚaccess)ÚAPI_KEY_INVALIDÚOVER_QUERY_LIMIT)rC   r   r   r   )r   rM   Ústatus_resultÚapi_call_successÚaccess_errorÚaccess_error_to_exceptionÚexception_clss          r   rR   z!GeocodeFarm._check_for_api_errors±   s‘   € ð
 *×-Ñ-¨h¸Ó;ˆØ˜=×,Ñ,¨X°rÓ:Ñ:ØØ(×,Ñ,¨X°rÓ:¸iÑGÐÙØ(×,Ñ,¨XÓ6ˆLä#@Ü$9ñ)Ð%ð 6×9Ñ9ØÔ2óˆMñ   Ó-Ð-ð  r    )N)r*   Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r1   r9   rK   r+   rR   Ú__classcell__)r   s   @r   r   r      sd   ø„ ñð '€LØ&€Lð ð4
ð %Ø$ØØ(Ø Øö4
ðl -1Ð:Jô Cð6 -1Ð:Jô "CòHò&ö.r    r   N)Ú	functoolsr   Úurllib.parser   Ú	geopy.excr   r   r   Úgeopy.geocoders.baser   r	   Úgeopy.locationr
   Ú
geopy.utilr   Ú__all__r   © r    r   ú<module>rj      s3   ðÝ Ý "÷ñ ÷
 <Ý #Ý à
€ôs.�(õ s.r    