o
    ÔèFh«"  ã                   @   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__© úO/var/www/html/loop/nvenv/lib/python3.10/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< |r||	d< |r:z|  |¡ d¡\}
}||	d< |
|	d< W n ty9   tdƒ‚w |rD|  |d	¡|	d
< |rbt|tƒrQ|g|	d< nt|tjj	ƒs\t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Ú
ValueErrorÚ_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y   tdƒ‚w ||dœ}|r%t|ƒ|d< |r+d|d< |r1||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-   r8   r   r   r   r9   r   r:   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 )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>å   s    z&Photon._parse_json.<locals>.<listcomp>)ÚlenrD   )r   Ú	resourcesr   r   rG   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)ÚnameÚhousenumberÚstreetÚpostcoderM   ÚcityÚstateÚcountryc                    s(   g | ]}ˆ d    |¡rˆ d    |¡‘qS )Ú
properties)Úget)rE   Úk©rF   r   r   rH   í   s    ÿz*Photon._parse_resource.<locals>.<listcomp>z, ÚgeometryÚcoordinatesr$   r   )r8   Úfloatr   )r   rF   Úname_elementsrK   ÚlocationÚlatitudeÚ	longituder   rU   r   rD   è   s   
ÿ
zPhoton._parse_resource)T)r:   Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   rA   rB   r;   rD   Ú__classcell__r   r   r   r   r      s6    ÷6ö\ù
4r   )Úcollections.abcr4   Ú	functoolsr   Úurllib.parser   Úgeopy.geocoders.baser   r   Úgeopy.locationr   Ú
geopy.utilr   Ú__all__r   r   r   r   r   Ú<module>   s    