
    N}bgS0                         d dl Z d dlm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mZ d dlmZ d dlmZ d	Zd
Z G d de          ZdS )    N)partial)time)	urlencode)ConfigurationErrorGeocoderAuthenticationFailureGeocoderServiceError)DEFAULT_SENTINELGeocoder_synchronized)Location)logger)ArcGISi  c                        e Zd ZdZdZdZdZdZ	 	 ddddeededdd	d

 fdZ	dedddZ
d ZdedddZd ZeddZed             Z xZS )r   zGeocoder using the ERSI ArcGIS API.

    Documentation at:
        https://developers.arcgis.com/rest/geocode/api-reference/overview-world-geocoding-service.htm
    i  z/sharing/generateTokenz?/arcgis/rest/services/World/GeocodeServer/findAddressCandidatesz8/arcgis/rest/services/World/GeocodeServer/reverseGeocodeN<   zwww.arcgis.comzgeocode.arcgis.com)
referertoken_lifetimeschemetimeoutproxies
user_agentssl_contextadapter_factoryauth_domaindomainc       
         0   t                                          |||||	|
           |s|s|r/|r|r|st          d          | j        dk    rt          d          || _        || _        || _        |                    d          | _        | j        d| j        | j	        | _
        |dz  | _        |                    d          | _        | j        d| j        | j        | _        | j        d| j        | j        | _        d| _        d| _        dS )	a  

        :param str username: ArcGIS username. Required if authenticated
            mode is desired.

        :param str password: ArcGIS password. Required if authenticated
            mode is desired.

        :param str referer: Required if authenticated mode is desired.
            `Referer` HTTP header to send with each request,
            e.g., ``'http://www.example.com'``. This is tied to an issued token,
            so fielding queries for multiple referrers should be handled by
            having multiple ArcGIS geocoder instances.

        :param int token_lifetime: Desired lifetime, in minutes, of an
            ArcGIS-issued token.

        :param str scheme:
            See :attr:`geopy.geocoders.options.default_scheme`.
            If authenticated mode is in use, it must be ``'https'``.

        :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 auth_domain: Domain where the target ArcGIS auth service
            is hosted. Used only in authenticated mode (i.e. username,
            password and referer are set).

        :param str domain: Domain where the target ArcGIS service
            is hosted.
        )r   r   r   r   r   r   z;Authenticated mode requires username, password, and refererhttpsz-Authenticated mode requires scheme of 'https'/z://r   N)super__init__r   r   usernamepasswordr   stripr   	auth_pathauth_apir   r   geocode_pathapireverse_pathreverse_apitokentoken_expiry)selfr    r!   r   r   r   r   r   r   r   r   r   r   	__class__s                i/home/e360mart.nyusoft.in/public_html/e360mart_env/lib/python3.11/site-packages/geopy/geocoders/arcgis.pyr   zArcGIS.__init__!   sn   | 	!#+ 	 	
 	
 	
  		x 		7 		  g (-   {g%%(C   ! &,,S11;;;(8(8$..I 	 -r1ll3'';;;T5F5FG 	  ;;;T5F5FG 	
 
     T)exactly_oner   
out_fieldsc                r   |dd}|rd|d<   |3t          |t                    r||d<   nd                    |          |d<   d                    | j        t	          |          f          }t          j        d	| j        j        |           t          | j
        |
          }|                     |||          S )am  
        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 out_fields: A list of output fields to be returned in the
            attributes field of the raw data. This can be either a python
            list/tuple of fields or a comma-separated string. See
            https://developers.arcgis.com/rest/geocode/api-reference/geocoding-service-output.htm
            for a list of supported output fields. If you want to return all
            supported output fields, set ``out_fields="*"``.
        :type out_fields: str or iterable

        :rtype: ``None``, :class:`geopy.location.Location` or a list of them, if
            ``exactly_one=False``.
        json)
singleLinef   maxLocationsN	outFields,?z%s.geocode: %sr/   r   )
isinstancestrjoinr&   r   r   debugr,   __name__r   _parse_geocode_authenticated_call_geocoder)r+   queryr/   r   r0   paramsurlcallbacks           r-   geocodezArcGIS.geocode   s    4 !&F33 	'%&F>"!*c** ;&0{##&)hhz&:&:{#hh)F"3"3455%t~'>DDD4.KHHH00h0PPPr.   c           	      .   d|v r"t          t          |d                             t          |d                   sd S g }|d         D ]B}|d         }|                    t	          |d         |d         |d         f|                     C|r|d         S |S )Nerror
candidateslocationaddressyxr   )r   r=   lenappendr   )r+   responser/   geocodedresourcegeometrys         r-   rA   zArcGIS._parse_geocode   s    h&s8G+<'='=>>> 8L)** 	4 . 	 	H
+HOOY'(3-#)G    
  	A;r.   )r/   r   distancec                D   |                      |d          }t          }|d|d}|||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.

        :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 int distance: Distance from the query location, in meters,
            within which to search. ArcGIS has a default of 100 meters, if not
            specified.

        :rtype: ``None``, :class:`geopy.location.Location` or a list of them, if
            ``exactly_one=False``.
        z%(lon)s,%(lat)sr2   )rK   r4   outSRNrU   r9   z%s.reverse: %sr:   r;   )_coerce_point_to_stringDEFAULT_WKIDr>   r(   r   r   r?   r,   r@   r   _parse_reverserB   )
r+   rC   r/   r   rU   rK   wkidrD   rE   rF   s
             r-   reversezArcGIS.reverse   s    2 //7HII&VdCC!)F:hh()F*;*;<==%t~'>DDD4.KHHH00h0PPPr.   c                    t          |          sd S d|v re|d         d         dk    r1	 d|d         d         d         v rd S n# t          t          f$ r Y nw xY wt          t	          |d                             |d                             d          rd	|d         z  }n|d         d
         }t          ||d         d         |d         d         f|d                   }|r|S |gS )NrI   codei  zUnable to finddetailsr   rL   Addressz=%(Address)s, %(City)s, %(Region)s %(Postal)s, %(CountryCode)s	LongLabelrK   rM   rN   )rO   KeyError
IndexErrorr   r=   getr   )r+   rQ   r/   rL   rK   s        r-   rZ   zArcGIS._parse_reverse   s1   8}} 	4h (C//'8G+<Y+G+JJJ#t K *-   D&s8G+<'='=>>>I""9-- 	7#%-i%89 G
 y)+6Gj!#&(<S(ABY
 

  	O:s   A AAr;   c                      j         s                               S  fd} fd fd j        $t          t	                                 j        k    r                     | j                  S  |            S )Nr;   c                      d                     t          dj        i          f          } dj        i}                    | t          j                  |          S )N&r)   Referer)
from_tokenr   headers)r>   r   r)   r   _call_geocoderr   )call_urlrk   maybe_reauthenticate_callbackr+   r   rE   s     r-   query_callbackz;ArcGIS._authenticated_call_geocoder.<locals>.query_callback  sm    xxi$*0E&F&F GHHH $,/G&&5$*MMM	 '   r.   c                    d| v r/| d         d         j         k    r                    |          S  |           S )NrI   r^   r   ri   )_TOKEN_EXPIRED_refresh_authentication_token)rQ   ri   parse_callbackquery_retry_callbackr+   r   s     r-   rn   zJArcGIS._authenticated_call_geocoder.<locals>.maybe_reauthenticate_callback  s\    (""G$V,0CCC==,g* >    ">(+++r.   c                      d                     t          dj        i          f          } dj        i}                    | |          S )Nrg   r)   rh   rj   )r>   r   r)   r   rl   )rm   rk   rt   r+   r   rE   s     r-   ru   zAArcGIS._authenticated_call_geocoder.<locals>.query_retry_callback  sZ    xxi$*0E&F&F GHHH $,/G&&.'7 '   r.   rq   )r    rl   r)   intr   r*   rs   )r+   rE   rt   r   ro   rn   ru   s   ```` @@r-   rB   z#ArcGIS._authenticated_call_geocoder  s     } 	M&&sNG&LLL	 	 	 	 	 	 	 		, 	, 	, 	, 	, 	, 	, 	,	 	 	 	 	 	 	 	 :TVVt/@!@!@55DJ 6    ">###r.   c                :    | j         k    r
             S  j         j         j         j        dd}d                     j        t          |          f          t          j	        d j
        j                    fd}                     ||          S )Nr2   )r    r!   r   
expirationr4   r9   z$%s._refresh_authentication_token: %sc                     d| vr't          ddt          j        |                     | d         _        t	          t                                j        z   _                     S )Nr)   z+Missing token in auth request.Request URL: z; response JSON: )r   r2   dumpsr)   rw   r   r   r*   )rQ   callback_successr+   rE   s    r-   cbz0ArcGIS._refresh_authentication_token.<locals>.cb>  sv    h&&33<?CCHAUAUAUW   "'*DJ #DFFd.A AD##%%%r.   r;   )r)   r    r!   r   r   r>   r$   r   r   r?   r,   r@   rl   )r+   r|   r   ri   token_request_argumentsr}   rE   s   ``    @r-   rs   z$ArcGIS._refresh_authentication_token+  s    ####%%% |-#
 #
 hhy1H'I'IJKK2N#S	
 	
 	

	& 	& 	& 	& 	& 	& 	& ""3G"<<<r.   )NN)r@   
__module____qualname____doc__rr   r#   r%   r'   r	   r   rG   rA   r\   rZ   rB   r   rs   __classcell__)r,   s   @r-   r   r      sE         N(ITLML e!
 $$( ('e! e! e! e! e! e! e!N -1:J%Q %Q %Q %Q %QN  & -1:J!Q !Q !Q !Q !QF  B /?$$ $$ $$ $$ $$L = = ]= = = = =r.   r   )r2   	functoolsr   r   urllib.parser   	geopy.excr   r   r   geopy.geocoders.baser	   r
   r   geopy.locationr   
geopy.utilr   __all__rY   r    r.   r-   <module>r      s                " " " " " "         
 K J J J J J J J J J # # # # # #      
t= t= t= t= t=X t= t= t= t= t=r.   