a
    }c"                     @   s`   d dl Zd dlmZ d dlmZ d dlmZmZ d dl	m
Z
 d dlmZ dZG dd	 d	eZdS )
    N)partial)	urlencode)DEFAULT_SENTINELGeocoder)Location)logger)Photonc                       sz   e Zd ZdZdZdZdeeddedd fdd
Zd	edd
ddddddZd	ed
ddddZ	dddZ
dd Z  ZS )r   a  Geocoder using Photon geocoding service (data based on OpenStreetMap
    and service provided by Komoot on https://photon.komoot.io).

    Documentation at:
        https://github.com/komoot/photon

    Photon/Komoot geocoder aims to let you `search as you type with
    OpenStreetMap`. No API Key is needed by this platform.

    .. versionchanged:: 2.2
        Changed default domain from ``photon.komoot.de``
        to ``photon.komoot.io``.
    z/apiz/reverseNzphoton.komoot.io)schemetimeoutproxiesdomain
user_agentssl_contextadapter_factoryc                   sT   t  j||||||d |d| _d| j| j| jf | _d| j| j| jf | _dS )ap  

        :param str scheme:
            See :attr:`geopy.geocoders.options.default_scheme`.

        :param int timeout:
            See :attr:`geopy.geocoders.options.default_timeout`.

        :param dict proxies:
            See :attr:`geopy.geocoders.options.default_proxies`.

        :param str domain: Should be the localized Photon domain to
            connect to. The default is ``'photon.komoot.io'``, but you
            can change it to a domain of your own.

        :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
        )r	   r
   r   r   r   r   /z	%s://%s%sN)	super__init__stripr   r	   geocode_pathapireverse_pathreverse_api)selfr	   r
   r   r   r   r   r   	__class__ R/var/www/html/django/DPS/env/lib/python3.9/site-packages/geopy/geocoders/photon.pyr      s    &zPhoton.__init__TF)exactly_oner
   location_biaslanguagelimitosm_tagbboxc                C   s  d|i}	|rt ||	d< |r$d|	d< |r0||	d< |rxz(| |d\}
}||	d< |
|	d< W n tyv   tdY n0 |r| |d	|	d
< |rt|tr|g|	d< n"t|tjj	stdt
||	d< d| jt|	ddf}td| jj| t| j|d}| j|||d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.

        :param location_bias: The coordinates to use as location bias.
        :type location_bias: :class:`geopy.point.Point`, list or tuple of
            ``(latitude, longitude)``, or string
            as ``"%(latitude)s, %(longitude)s"``.

        :param str language: Preferred language in which to return results.

        :param int limit: Limit the number of returned results, defaults to no
            limit.

        :param osm_tag: The expression to filter (include/exclude) by key and/
            or value, str as ``'key:value'`` or list/set of str if multiple
            filters are required as ``['key:!val', '!key', ':!value']``.
        :type osm_tag: str or list or set

        :param bbox: The bounding box of the viewport within which
            to bias geocode results more prominently.
            Example: ``[Point(22, 180), Point(-22, -180)]``.

            .. versionadded:: 2.2
        :type bbox: list or tuple of 2 items of :class:`geopy.point.Point` or
            ``(latitude, longitude)`` or ``"%(latitude)s, %(longitude)s"``.

        :rtype: ``None``, :class:`geopy.location.Location` or a list of them, if
            ``exactly_one=False``.

        qr       lang,lonlatz0Location bias must be a coordinate pair or Pointz#%(lon1)s,%(lat1)s,%(lon2)s,%(lat2)sr"   r!   z2osm_tag must be a string or an iterable of strings?T)doseqz%s.geocode: %sr   r
   )int_coerce_point_to_stringsplit
ValueErrorZ_format_bounding_box
isinstancestrcollectionsabcIterablelistjoinr   r   r   debugr   __name__r   _parse_json_call_geocoder)r   queryr   r
   r   r   r    r!   r"   paramsr(   r'   urlcallbackr   r   r   geocodeP   s>    5
zPhoton.geocode)r   r
   r   r    c                C   s   z|  |d\}}W n ty2   tdY n0 ||d}|rNt||d< |rZd|d< |rf||d< d| jt|f}	td| j	j
|	 t| j|d	}
| j|	|
|d
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 str language: Preferred language in which to return results.

        :param int limit: Limit the number of returned results, defaults to no
            limit.

        :rtype: ``None``, :class:`geopy.location.Location` or a list of them, if
            ``exactly_one=False``.
        r&   z"Must be a coordinate pair or Point)r(   r'   r    r$   r%   r)   z%s.reverse: %sr+   r,   )r.   r/   r0   r-   r7   r   r   r   r8   r   r9   r   r:   r;   )r   r<   r   r
   r   r    r(   r'   r=   r>   r?   r   r   r   reverse   s"    !zPhoton.reversec                    s@   t |d sdS |r& |d d S  fdd|d D S dS )zS
        Parse display name, latitude, and longitude from a JSON response.
        featuresNr   c                    s   g | ]}  |qS r   )_parse_resource).0resourcer   r   r   
<listcomp>       z&Photon._parse_json.<locals>.<listcomp>)lenrC   )r   	resourcesr   r   rF   r   r:      s    
zPhoton._parse_jsonc                    sl   g d} fdd|D }d |} d d d } d d d }|r\|r\t|}t|}t|||f S )	N)nameZhousenumberstreetZpostcoderL   ZcitystateZcountryc                    s(   g | ] } d   |r d   |qS )
properties)get)rD   krE   r   r   rG      s   z*Photon._parse_resource.<locals>.<listcomp>z, ZgeometryZcoordinatesr$   r   )r7   floatr   )r   rE   Zname_elementsrK   locationZlatitudeZ	longituder   rQ   r   rC      s    

zPhoton._parse_resource)T)r9   
__module____qualname____doc__r   r   r   r   r@   rA   r:   rC   __classcell__r   r   r   r   r      s4   6\4
r   )collections.abcr3   	functoolsr   urllib.parser   Zgeopy.geocoders.baser   r   Zgeopy.locationr   Z
geopy.utilr   __all__r   r   r   r   r   <module>   s   