Ë
    Ï.fS0  ã                   óŽ   — 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y)é    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   z¥Geocoder 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       
         óL  •— t         ‰| �  |||||	|
¬«       |s|s|r+|r|r|st        d«      ‚| j                  dk7  rt        d«      ‚|| _        || _        || _        |j                  d«      | _        | j                  ›d| j                  ›| j                  ›�| _
        |dz  | _        |j                  d«      | _        | j                  ›d| j                  ›| j                  ›�| _        | j                  ›d| j                  ›| j                  ›�| _        d| _        d| _        y)	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                €úUC:\Users\user\Documents\project_loop\venv\Lib\site-packages\geopy/geocoders/arcgis.pyr   zArcGIS.__init__!   s$  ø€ ô| 	‰ÑØØØØ!Ø#Ø+ð 	ô 	
ñ ‘x¡7Ù¡©gÜ(ð-óð ð �{‰{˜gÒ%Ü(ØCóð ð !ˆŒØ ˆŒØˆŒØ&×,Ñ,¨SÓ1ˆÔàŸ;›;¨×(8Ò(8¸$¿.º.ÐIð 	Œð -¨rÑ1ˆÔà—l‘l 3Ó'ˆŒàŸ;›;¨¯ª°T×5FÒ5FÐGð 	Œð  Ÿ;›;¨¯ª°T×5FÒ5FÐGð 	Ôð
 ˆŒ
Ø ˆÕó    T)Úexactly_oner   Ú
out_fieldsc                ój  — |ddœ}|rd|d<   |�*t        |t        «      r||d<   ndj                  |«      |d<   dj                  | j                  t	        |«      f«      }t        j                  d| j                  j                  |«       t        | j                  |¬	«      }| 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é   ÚmaxLocationsÚ	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ˆÙØ%&ˆF�>Ñ"ØÐ!Ü˜*¤cÔ*Ø&0��{Ò#à&)§h¡h¨zÓ&:��{Ñ#Ø�h‰h˜Ÿ™¤)¨FÓ"3Ð4Ó5ˆÜ�‰Ð% t§~¡~×'>Ñ'>ÀÔDÜ˜4×.Ñ.¸KÔHˆØ×0Ñ0°°hÈÐ0ÓPÐPr.   c           	      óØ   — d|v rt        t        |d   «      «      ‚t        |d   «      sy g }|d   D ].  }|d   }|j                  t	        |d   |d   |d   f|«      «       Œ0 |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ÑÜ&¤s¨8°GÑ+<Ó'=Ó>Ð>ô �8˜LÑ)Ô*ØØˆØ  Ñ.ò 	ˆHØ 
Ñ+ˆHØ�O‰OÜØ˜YÑ'¨(°3©-¸À#¹Ð)GÈóõð	ñ Ø˜A‘;ÐØˆr.   )r/   r   Údistancec                óD  — | j                  |d«      }t        }|d|dœ}|�||d<   dj                  | j                  t	        |«      f«      }t        j                  d| j                  j                  |«       t        | j                  |¬«      }	| 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   ÚoutSRrU   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ˆÜˆØ&¨V¸dÑCˆØÐØ!)ˆF�:ÑØ�h‰h˜×(Ñ(¬)°FÓ*;Ð<Ó=ˆÜ�‰Ð% t§~¡~×'>Ñ'>ÀÔDÜ˜4×.Ñ.¸KÔHˆØ×0Ñ0°°hÈÐ0ÓPÐPr.   c                 óD  — t        |«      sy d|v r2|d   d   dk(  r	 d|d   d   d   v ry 	 t        t	        |d   «      «      ‚|d   j                  d«      r	d	|d   z  }n|d   d
   }t        ||d   d   |d   d   f|d   «      }|r|S |gS # t        t        f$ r Y Œrw xY w)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å   sù   € Ü�8Œ}ØØ�hÑà˜Ñ  Ñ(¨CÒ/ðØ'¨8°GÑ+<¸YÑ+GÈÑ+JÑJØ#ð Kô '¤s¨8°GÑ+<Ó'=Ó>Ð>à�IÑ×"Ñ" 9Ô-ð#Ø%-¨iÑ%8ñ9ñ ð
 ˜yÑ)¨+Ñ6ˆGäØØ�jÑ! #Ñ&¨°Ñ(<¸SÑ(AÐBØ�YÑó
ˆñ
 ØˆOà�:Ðøô) !¤*Ð-ò Ùðús   �B ÂBÂBr;   c                ó   ‡ ‡‡‡‡‡— ‰ j                   s‰ j                  ‰‰‰¬«      S ˆˆ ˆˆfd„}ˆˆˆ ˆfd„Šˆˆ ˆˆfd„Š‰ j                  � t        t	        «       «      ‰ j
                  kD  r‰ j                  |‰‰ j                  ¬«      S  |«       S )Nr;   c                  óÄ   •— dj                  ‰t        d‰j                  i«      f«      } d‰j                  i}‰j	                  | 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  sb   ø€ Ø—x‘x ¤i°¸$¿*¹*Ð0EÓ&FÐ GÓHˆHØ  $§,¡,Ð/ˆGØ×&Ñ&ØÜÐ5À$Ç*Á*ÔMØØð	 'ó ð r.   c                ón   •— d| v r)| d   d   ‰j                   k(  r‰j                  ‰‰|¬«      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  sO   ø€ Ø˜(Ñ"Ø˜GÑ$ VÑ,°×0CÑ0CÒCØ×=Ñ=Ø,°gÈ*ð >ó ð ñ " (Ó+Ð+r.   c                  óš   •— dj                  ‰t        d‰j                  i«      f«      } d‰j                  i}‰j	                  | ‰‰|¬«      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  sS   ø€ Ø—x‘x ¤i°¸$¿*¹*Ð0EÓ&FÐ GÓHˆHØ  $§,¡,Ð/ˆ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€   ý€ ð �}Š}Ø×&Ñ& s¨NÀGÐ&ÓLÐL÷	÷	,÷	ð �:‰:Ð¤¤T£V£¨t×/@Ñ/@Ò!@Ø×5Ñ5Ø¨¸D¿J¹Jð 6ó ð ñ "Ó#Ð#r.   c                ól  ‡ ‡‡— |‰ j                   k7  r ‰«       S ‰ j                  ‰ j                  ‰ j                  ‰ j                  ddœ}dj                  ‰ j                  t        |«      f«      Št        j                  d‰ j                  j                  ‰«       ˆˆ ˆfd„}‰ j                  ‰||¬«      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>  s\   ø€ Ø˜hÑ&Ý3â<?ÄÇÁÈHÔAUðWóð ð " 'Ñ*ˆDŒJÜ #¤D£F£¨d×.AÑ.AÑ AˆDÔÙ#Ó%Ð%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Ÿ   ú€ à˜Ÿ™Ò#á#Ó%Ð%ð Ÿ™ØŸ™Ø—|‘|Ø×-Ñ-Øñ#
Ðð �h‰h˜Ÿ™¤yÐ1HÓ'IÐJÓKˆÜ�‰Ø2Ø�N‰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      s¡   ø„ ñð €Nà(€IØT€LØM€Lð Øðe!ð
 ØØØ$Ø$ØØ(Ø Ø(Ø'öe!ðN -1Ð:JØô%QòNð& -1Ð:JØô!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‹      sB   ðÛ Ý Ý Ý "÷ñ ÷
 KÑ JÝ #Ý à
€à€ôt=ˆXõ t=r.   