
    N}bg                     z    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d
S )    )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   zGeocoder 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        | _        dS )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
            n/home/e360mart.nyusoft.in/public_html/e360mart_env/lib/python3.11/site-packages/geopy/geocoders/geocodefarm.pyr   zGeocodeFarm.__init__   s    J 	!#+ 	 	
 	
 	
 #;;;0A0AB 	  ;;;0A0AB 	    T)exactly_oner   c                   d|i}| j         r
| j         |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.

        :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
 < 	) LF5Mhh)F"3"3455%t~'>DDD4+EEE""3'"BBBr    c                   	 |                      |                              d          \  }}n# t          $ r t          d          w xY w||d}| j        r
| j        |d<   d                    | j        t          |          f          }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. 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3E::@@EEHC 	C 	C 	CABBB	C 
 
 < 	) LF5Mhh()F*;*;<==%t~'>DDD4+EEE""3'"BBBs	   +. Ac                    g }|                     d          D ]}|                     di           }|                     di           }|                     dd           }|                     dd           }|                     dd           }||                     dd           }||                     dd           }|r |rt          |          }t          |          }|                    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	   kk),, 	N 	NF **]B77KjjB//G"z488H#T::I$6==I #KK	488	 "JJ':DAA	 -I - ??!),,	MM(9x.CVLLMMMMr    c                     |d S |d         }|                      |           d|                    di                               dd          v rd S |                     |          }|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   s    4&':;""#4555,002>>BB8RPPPP4!!"344 	!9Mr    c                 2   |                     di           }d|                     dd          v rdS |                     dd          dk    }|sJ|                     d          }t          t          d}|                     |t                    } ||          dS )	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;;=,,Xr::::F(,,Xr::iG 		.(,,X66L#@$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      s          'L&L 4
 %$( 4
 4
 4
 4
 4
 4
 4
l -1:J C C C C C6 -1:J "C "C "C "C "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      s          " " " " " "         
 < ; ; ; ; ; ; ; # # # # # #      
s. s. s. s. s.( s. s. s. s. s.r    