
    .hS0                         S SK r S SKJr  S SKJr  S SKJr  S SKJrJrJ	r	  S SK
JrJrJr  S SKJr  S SKJr  S	rS
r " S S\5      rg)    N)partial)time)	urlencode)ConfigurationErrorGeocoderAuthenticationFailureGeocoderServiceError)DEFAULT_SENTINELGeocoder_synchronized)Location)logger)ArcGISi  c                      ^  \ rS rSrSrSrSrSrSr  SSSS\	\	S\	SS	S
S.
U 4S jjjr
S\	SS.S jrS rS\	SS.S jrS r\	S.S jr\S 5       rSrU =r$ )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       
   	        > [         TU ]  UUUUU	U
S9  U(       d  U(       d  U(       a;  U(       a  U(       a  U(       d  [        S5      eU R                  S:w  a  [        S5      eXl        X l        X0l        UR                  S5      U l        U R                  < SU R                  < U R                  < 3U l
        US-  U l        UR                  S5      U l        U R                  < SU R                  < U R                  < 3U l        U R                  < SU R                  < U R                  < 3U l        SU l        SU l        g)	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                iC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\geopy/geocoders/arcgis.pyr    ArcGIS.__init__!   s   | 	!#+ 	 	
 x7g(-  {{g%(C  ! &,,S1;;(8(8$..I 	 -r1ll3';;T5F5FG 	  ;;T5F5FG 	
 
     T)exactly_oner   
out_fieldsc                r   USS.nU(       a  SUS'   Ub.  [        U[        5      (       a  XES'   OSR                  U5      US'   SR                  U R                  [	        U5      45      n[
        R                  " SU R                  R                  U5        [        U R                  US	9nU R                  XgUS
9$ )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 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   maxLocations	outFields,?z%s.geocode: %sr1   r   )
isinstancestrjoinr'   r   r   debugr-   __name__r   _parse_geocode_authenticated_call_geocoder)r,   queryr1   r   r2   paramsurlcallbacks           r.   geocodeArcGIS.geocode   s    4 !&F3%&F>"!*c**&0{#&)hhz&:{#hh)F"345%t~~'>'>D4..KH000PPr0   c           	          SU;   a  [        [        US   5      5      e[        US   5      (       d  g / nUS    H/  nUS   nUR                  [	        US   US   US   4U5      5        M1     U(       a  US   $ U$ )Nerror
candidateslocationaddressyxr   )r   r?   lenappendr   )r,   responser1   geocodedresourcegeometrys         r.   rC   ArcGIS._parse_geocode   s    h&s8G+<'=>> 8L)** .H
+HOOY'(3-#)G / A;r0   )r1   r   distancec                8   U R                  US5      n[        nUSUS.nUb  XGS'   SR                  U R                  [	        U5      45      n[
        R                  " SU R                  R                  U5        [        U R                  US9n	U R                  XUS9$ )	au  
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)sr4   )rN   r6   outSRrY   r;   z%s.reverse: %sr<   r=   )_coerce_point_to_stringDEFAULT_WKIDr@   r)   r   r   rA   r-   rB   r   _parse_reverserD   )
r,   rE   r1   r   rY   rN   wkidrF   rG   rH   s
             r.   reverseArcGIS.reverse   s    2 //7HI&VdC!):hh(()F*;<=%t~~'>'>D4..KH000PPr0   c                 n   [        U5      (       d  g SU;   a5  US   S   S:X  a   SUS   S   S   ;   a  g  [        [	        US   5      5      eUS   R                  S5      (       a	  S	US   -  nOUS   S
   n[        UUS   S   US   S   4US   5      nU(       a  U$ U/$ ! [        [        4 a     N}f = f)NrL   codei  zUnable to finddetailsr   rO   Addressz=%(Address)s, %(City)s, %(Region)s %(Postal)s, %(CountryCode)s	LongLabelrN   rP   rQ   )rR   KeyError
IndexErrorr   r?   getr   )r,   rT   r1   rO   rN   s        r.   r^   ArcGIS._parse_reverse   s    8}}h (C/'8G+<Y+G+JJ# K 's8G+<'=>>I""9--#%-i%89 
 y)+6Gj!#&(<S(ABY

 O:) !*- s   B! !B43B4r=   c                (  ^ ^^^^^ T R                   (       d  T R                  TTTS9$ UU UU4S jnUUU U4S jmUU UU4S jmT R                  b!  [        [	        5       5      T R
                  :  a  T R                  UTT R                  S9$ U" 5       $ )Nr=   c                     > SR                  T[        STR                  05      45      n STR                  0nTR	                  U [        TTR                  S9TUS9$ )N&r*   Referer)
from_tokenr   headers)r@   r   r*   r   _call_geocoderr   )call_urlrq   maybe_reauthenticate_callbackr,   r   rG   s     r.   query_callback;ArcGIS._authenticated_call_geocoder.<locals>.query_callback  sb    xxi$**0E&F GHH $,,/G&&5$**M	 '  r0   c                n   > SU ;   a'  U S   S   TR                   :X  a  TR                  TTUS9$ T" U 5      $ )NrL   rc   r   ro   )_TOKEN_EXPIRED_refresh_authentication_token)rT   ro   parse_callbackquery_retry_callbackr,   r   s     r.   rt   JArcGIS._authenticated_call_geocoder.<locals>.maybe_reauthenticate_callback  sO    ("G$V,0C0CC==,g* >   "(++r0   c                     > SR                  T[        STR                  05      45      n STR                  0nTR	                  U TTUS9$ )Nrm   r*   rn   rp   )r@   r   r*   r   rr   )rs   rq   r{   r,   r   rG   s     r.   r|   AArcGIS._authenticated_call_geocoder.<locals>.query_retry_callback  sS    xxi$**0E&F GHH $,,/G&&.'7 '  r0   rx   )r!   rr   r*   intr   r+   rz   )r,   rG   r{   r   ru   rt   r|   s   ```` @@r.   rD   #ArcGIS._authenticated_call_geocoder  s     }}&&sNG&LL	 		, 	,	 	 ::TVt/@/@!@55DJJ 6   "##r0   c                j  ^ ^^ UT R                   :w  a  T" 5       $ T R                  T R                  T R                  T R                  SS.nSR                  T R                  [        U5      45      m[        R                  " ST R                  R                  T5        UU U4S jnT R                  TXRS9$ )Nr4   )r!   r"   r   
expirationr6   r;   z$%s._refresh_authentication_token: %sc                    > SU ;  a'  [        ST< S[        R                  " U 5      < 35      eU S   Tl        [	        [        5       5      TR                  -   Tl        T" 5       $ )Nr*   z+Missing token in auth request.Request URL: z; response JSON: )r   r4   dumpsr*   r   r   r   r+   )rT   callback_successr,   rG   s    r.   cb0ArcGIS._refresh_authentication_token.<locals>.cb>  s\    h&3<?HAUW  "'*DJ #DFd.A.A AD#%%r0   r=   )r*   r!   r"   r   r   r@   r%   r   r   rA   r-   rB   rr   )r,   r   r   ro   token_request_argumentsr   rG   s   ``    @r.   rz   $ArcGIS._refresh_authentication_token+  s    ##%% ||--#
 hhy1H'IJK2NN##S	

	& ""3"<<r0   )r'   r%   r   r   r"   r   r)   r*   r+   r   r!   )NN)rB   
__module____qualname____firstlineno____doc__ry   r$   r&   r(   r	   r    rI   rC   r`   r^   rD   r   rz   __static_attributes____classcell__)r-   s   @r.   r   r      s     N(ITLML e!
 $$( ('e! e!N -1:J%QN& -1:J!QFB /?$$L = =r0   r   )r4   	functoolsr   r   urllib.parser   	geopy.excr   r   r   geopy.geocoders.baser	   r
   r   geopy.locationr   
geopy.utilr   __all__r]   r    r0   r.   <module>r      sB       " 
 K J # 
t=X t=r0   