a
    }cC                     @   s   d dl Z d dlZd dlZd dlZd dlmZ d dlmZmZm	Z	m
Z
mZmZ d dlmZmZmZmZmZmZmZmZ d dlmZ d dlmZmZ dZde Zed	d
 e
efD ZG dd dZe de!fddd i Z"eeeeeeeeeeeeedZ#e! Z$G dd dZ%dd Z&dd Z'dS )    N)compat)AdapterHTTPErrorBaseAsyncAdapterBaseSyncAdapterRequestsAdapterURLLibAdapterget_retry_after)ConfigurationErrorGeocoderAuthenticationFailureGeocoderInsufficientPrivilegesGeocoderQueryErrorGeocoderQuotaExceededGeocoderRateLimitedGeocoderServiceErrorGeocoderTimedOut)Point)__version__logger)Geocoderoptionszgeopy/%sc                 c   s   | ]}|j r|V  qd S N)Zis_available).0Zadapter_cls r   P/var/www/html/django/DPS/env/lib/python3.9/site-packages/geopy/geocoders/base.py	<genexpr>#   s   r   c                   @   s(   e Zd ZdZeZdZdZdZdZ	e
ZdS )r   a  The `options` object contains default configuration values for
    geocoders, e.g. `timeout` and `User-Agent`.
    Instead of passing a custom value to each geocoder individually, you can
    override a default value in this object.

    Please note that not all geocoders use all attributes of this object.
    For example, some geocoders don't respect the ``default_scheme``
    attribute. Refer to the specific geocoder's initializer doc for a list
    of parameters which that geocoder accepts.

    Example for overriding default ``timeout`` and ``user_agent``::

        >>> import geopy.geocoders
        >>> from geopy.geocoders import Nominatim
        >>> geopy.geocoders.options.default_user_agent = 'my_app/1'
        >>> geopy.geocoders.options.default_timeout = 7
        >>> geolocator = Nominatim()
        >>> print(geolocator.headers)
        {'User-Agent': 'my_app/1'}
        >>> print(geolocator.timeout)
        7

    Attributes:
        default_adapter_factory
            A callable which returns a :class:`geopy.adapters.BaseAdapter`
            instance. Adapters are different implementations of HTTP clients.
            See :mod:`geopy.adapters` for more info.

            This callable accepts two keyword args: ``proxies`` and ``ssl_context``.
            A class might be specified as this callable as well.

            Example::

                import geopy.geocoders
                geopy.geocoders.options.default_adapter_factory = geopy.adapters.URLLibAdapter

                geopy.geocoders.options.default_adapter_factory = (
                    lambda proxies, ssl_context: MyAdapter(
                        proxies=proxies, ssl_context=ssl_context, my_custom_arg=42
                    )
                )

            If `requests <https://requests.readthedocs.io>`_ package is
            installed, the default adapter is
            :class:`geopy.adapters.RequestsAdapter`. Otherwise it is
            :class:`geopy.adapters.URLLibAdapter`.

            .. versionadded:: 2.0

        default_proxies
            Tunnel requests through HTTP proxy.

            By default the system proxies are respected (e.g.
            `HTTP_PROXY` and `HTTPS_PROXY` env vars or platform-specific
            proxy settings, such as macOS or Windows native
            preferences -- see :func:`urllib.request.getproxies` for
            more details). The `proxies` value for using system proxies
            is ``None``.

            To disable system proxies and issue requests directly,
            explicitly pass an empty dict as a value for `proxies`: ``{}``.

            To use a custom HTTP proxy location, pass a string.
            Valid examples are:

            - ``"192.0.2.0:8080"``
            - ``"john:passw0rd@192.0.2.0:8080"``
            - ``"http://john:passw0rd@192.0.2.0:8080"``

            Please note:

            - Scheme part (``http://``) of the proxy is ignored.
            - Only `http` proxy is supported. Even if the proxy scheme
              is `https`, it will be ignored, and the connection between
              client and proxy would still be unencrypted.
              However, `https` requests via `http` proxy are still
              supported (via `HTTP CONNECT` method).


            Raw urllib-style `proxies` dict might be provided instead of
            a string:

            - ``{"https": "192.0.2.0:8080"}`` -- means that HTTP proxy
              would be used only for requests having `https` scheme.
              String `proxies` value is automatically used for both
              schemes, and is provided as a shorthand for the urllib-style
              `proxies` dict.

            For more information, see
            documentation on :func:`urllib.request.getproxies`.

        default_scheme
            Use ``'https'`` or ``'http'`` as the API URL's scheme.

        default_ssl_context
            An :class:`ssl.SSLContext` instance with custom TLS
            verification settings. Pass ``None`` to use the interpreter's
            defaults (that is to use the system's trusted CA certificates).

            To use the CA bundle used by `requests` library::

                import ssl
                import certifi
                import geopy.geocoders
                ctx = ssl.create_default_context(cafile=certifi.where())
                geopy.geocoders.options.default_ssl_context = ctx

            To disable TLS certificate verification completely::

                import ssl
                import geopy.geocoders
                ctx = ssl.create_default_context()
                ctx.check_hostname = False
                ctx.verify_mode = ssl.CERT_NONE
                geopy.geocoders.options.default_ssl_context = ctx

            See docs for the :class:`ssl.SSLContext` class for more examples.

        default_timeout
            Time, in seconds, to wait for the geocoding service to respond
            before raising a :class:`geopy.exc.GeocoderTimedOut` exception.
            Pass `None` to disable timeout.

        default_user_agent
            User-Agent header to send with the requests to geocoder API.
    Nhttps   )__name__
__module____qualname____doc___DEFAULT_ADAPTER_CLASSdefault_adapter_factorydefault_proxiesdefault_schemedefault_ssl_contextdefault_timeout_DEFAULT_USER_AGENTdefault_user_agentr   r   r   r   r   *   s    r   object__repr__c                 C   s   dS )NDEFAULT_SENTINELr   )selfr   r   r   <lambda>       r-   )i  i  i  i  i  i  i  i  i  i  i  i  i  c                   @   s~   e Zd ZdZdeededdddZdd Zdd	 Zd
d Zdd Z	dddZ
dddZdd ZedddddZdd ZdS )r   z(
    Template object for geocoders.
    N)schemetimeoutproxies
user_agentssl_contextadapter_factoryc                C   s   |pt j| _| jdvrtd|tur*|nt j| _|tur>|nt j| _d|pPt j	i| _
|turb|nt j| _t| jtr| j| jd| _|d u rt j}|| j| jd| _t| jtrd| _n(t| jtrd| _ntdt| jf d S )N)httpr   z)Supported schemes are `http` and `https`.z
User-Agent)r1   r3   FTzAAdapter %r must extend either BaseSyncAdapter or BaseAsyncAdapter)r   r$   r/   r	   r+   r&   r0   r#   r1   r(   headersr%   r3   
isinstancestrr"   adapterr   _Geocoder__run_asyncr   type)r,   r/   r0   r1   r2   r3   r4   r   r   r   __init__   s@    


zGeocoder.__init__c                 C   s.   | j rtd| j }|| ju s*J d| S )zContext manager for synchronous adapters. At exit all
        open connections will be closed.

        In synchronous mode context manager usage is not required,
        and connections will be automatically closed by garbage collection.
        z-`async with` must be used with async adapters&adapter's __enter__ must return `self`)r:   	TypeErrorr9   	__enter__r,   resr   r   r   r?     s
    
zGeocoder.__enter__c                 C   s   | j ||| d S r   )r9   __exit__r,   exc_typeexc_valexc_tbr   r   r   rB     s    zGeocoder.__exit__c                    s4   | j std| j I dH }|| ju s0J d| S )a  Context manager for asynchronous adapters. At exit all
        open connections will be closed.

        In asynchronous mode context manager usage is not required,
        however, it is strongly advised to avoid warnings about
        resources leaks.
        z.`async with` cannot be used with sync adaptersNr=   )r:   r>   r9   
__aenter__r@   r   r   r   rG     s
    zGeocoder.__aenter__c                    s   | j |||I d H  d S r   )r9   	__aexit__rC   r   r   r   rH   #  s    zGeocoder.__aexit__%(lat)s,%(lon)sc                 C   s.   t |tst|}|tt|jt|jd S )zb
        Do the right thing on "point" input. For geocoders with reverse
        methods.
        )ZlatZlon)r7   r   dict_format_coordinatelatitude	longitude)r,   pointoutput_formatr   r   r   _coerce_point_to_string&  s
    
	z Geocoder._coerce_point_to_string#%(lat1)s,%(lon1)s,%(lat2)s,%(lon2)sc                 C   sj   t |dkrtd|\}}t|t| }}|tt|j|jt|j|jt|j|jt|j|jd S )aD  
        Transform bounding box boundaries to a string matching
        `output_format` from the following formats:

            - [Point(lat1, lon1), Point(lat2, lon2)]
            - [[lat1, lon1], [lat2, lon2]]
            - ["lat1,lon1", "lat2,lon2"]

        It is guaranteed that lat1 <= lat2 and lon1 <= lon2.
           z%Unsupported format for a bounding box)Zlat1Zlon1Zlat2Zlon2)lenr   r   rJ   minrL   rM   max)r,   ZbboxrO   p1p2r   r   r   _format_bounding_box8  s    zGeocoder._format_bounding_boxc                 C   s   dS )au  
        Geocoder-specific exceptions handler.
        Override if custom exceptions processing is needed.
        For example, raising an appropriate GeocoderQuotaExceeded on non-200
        response with a textual message in the body about the exceeded quota.

        Return `NONE_RESULT` to have the geocoding call return `None` (meaning
        empty result).
        Nr   )r,   errorr   r   r   _geocoder_exception_handlerN  s    
z$Geocoder._geocoder_exception_handlerT)r0   is_jsonr6   c          
   
      s   j  }|r|| |tur$|nj}zV|rDjj|||dnjj|||djrt fdd}| W S  W S W nF t	y } z.
|}	|	tu rW Y d}~dS  W Y d}~n
d}~0 0 dS )z=
        For a generated query URL, get the results.
        )r0   r6   c               
      st   z( I d H } t | r$| I d H } | W S  tyn } z.|} | tu rXW Y d }~d S  W Y d }~n
d }~0 0 d S r   )inspectisawaitable	Exception_adapter_error_handlerNONE_RESULT)rA   rY   callbackresultr,   r   r   futt  s    


z$Geocoder._call_geocoder.<locals>.futN)r6   copyupdater+   r0   r9   Zget_jsonZget_textr:   r^   r_   r`   )
r,   urlrb   r0   r[   r6   Zreq_headersrd   rY   rA   r   ra   r   _call_geocoderZ  s&    


zGeocoder._call_geocoderc                 C   s   t |tr~|jr&tjd|j|jdd | |}|tu r<tS t	|jt
}t|trn|t|t|jd|q|t||n| |}|tu rtS d S )NzReceived an HTTP error (%s): %sF)exc_info)retry_after)r7   r   textr   infostatus_coderZ   r`   ERROR_CODE_MAPgetr   
issubclassr   r8   r   r6   )r,   rY   rA   Zexc_clsr   r   r   r_     s,    



zGeocoder._adapter_error_handler)rI   )rQ   )r   r   r   r    r+   r<   r?   rB   rG   rH   rP   rX   rZ   rh   r_   r   r   r   r   r      s*   *
 
/r   c                 C   s   t | dkr| S | dS )Nr   z.7f)abs)Z
coordinater   r   r   rK     s    rK   c                    sJ   t  fddd d fddtfdd}|S )zA decorator for geocoder methods which makes the method always run
    under a lock. The lock is reentrant.

    This decorator transparently handles sync and async working modes.
    c                    s>   &  | g|R i |W  d    S 1 s00    Y  d S r   r   )r,   argskwargs)func	sync_lockr   r   locked_sync  s    z"_synchronized.<locals>.locked_syncNc              	      s    d u rt     r^d us$J t u r^| g|R i |}t|rZ|I d H }|S  4 I d H n t zH| g|R i |}t|r|I d H }|W d W  d   I d H  S d 0 W d   I d H  q1 I d H s0    Y  d S r   )asyncioLocklockedr   current_taskr\   r]   )r,   rr   rs   rA   )
async_lockasync_lock_taskrt   r   r   locked_async  s&    



z#_synchronized.<locals>.locked_asyncc                    s@   t | jt}|r& | g|R i |S | g|R i |S d S r   )r7   r9   r   )r,   rr   rs   Z	run_async)r}   rv   r   r   f  s    z_synchronized.<locals>.f)	threadingRLock	functoolswraps)rt   r~   r   )r{   r|   rt   r}   rv   ru   r   _synchronized  s    r   )(rw   r   r\   r   Zgeopyr   Zgeopy.adaptersr   r   r   r   r   r   Z	geopy.excr	   r
   r   r   r   r   r   r   Zgeopy.pointr   Z
geopy.utilr   r   __all__r'   nextr!   r   r;   r)   r+   rn   r`   r   rK   r   r   r   r   r   <module>   sJ    (
 
 S