
    g"                     f    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	e      Zy)
    N)partial)	urlencode)DEFAULT_SENTINELGeocoder)Location)logger)Photonc                   t     e Zd ZdZdZdZdeeddedd fd
Zdedd	dddd
dZded	dddZ	ddZ
d Z x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                   t         |   ||||||       |j                  d      | _        | j                  d| j                  | j
                  | _        | j                  d| j                  | j                  | _        y)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://N)	super__init__stripr   r   geocode_pathapireverse_pathreverse_api)	selfr   r   r   r   r   r   r   	__class__s	           V/var/www/api/v1/venv_getwork_v1/lib/python3.12/site-packages/geopy/geocoders/photon.pyr   zPhoton.__init__   su    L 	!#+ 	 	
 ll3'"&++t{{D<M<MN*.++t{{DDUDUV    TF)exactly_oner   location_biaslanguagelimitosm_tagbboxc                   d|i}	|rt        |      |	d<   |rd|	d<   |r||	d<   |r.	 | j                  |      j                  d      \  }
}||	d<   |
|	d<   |r| j	                  |d	      |	d
<   |rTt        |t              r|g|	d<   n=t        |t        j                  j                        st        d      t        |      |	d<   dj                  | j                  t        |	d      f      }t        j                  d| j                   j"                  |       t%        | j&                  |      }| j)                  |||      S # t        $ r t        d      w xY w)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callbacks                 r   geocodezPhoton.geocodeP   sg   j 
 !%jF7OF7O%F6NU77FLLSQS #u #u !66;=F6N '3'%,Iy!!';??+C+CD$1  %)My!hh)F$"?@A%t~~'>'>D4++E""3'"BB)  U !STTUs   -D> >E)r   r   r!   r"   c                   	 | j                  |      j                  d      \  }}||d}|rt        |      |d<   |rd|d<   |r||d<   dj	                  | j
                  t        |      f      }	t        j                  d| j                  j                  |	       t        | j                  |	      }
| j                  |	|
|
      S # t        $ r t        d      w xY w)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/   )r1   r2   r3   r0   r;   r   r   r   r<   r   r=   r   r>   r?   )r   r@   r   r   r!   r"   r+   r*   rA   rB   rC   s              r   reversezPhoton.reverse   s    B	C33E:@@EHC 
 !%jF7OF7O%F6Nhh(()F*;<=%t~~'>'>D4++E""3'"BB  	CABB	Cs   #C Cc                     t        |d         sy|r| j                  |d   d         S |d   D cg c]  }| j                  |       c}S c c}w )zS
        Parse display name, latitude, and longitude from a JSON response.
        featuresNr   )len_parse_resource)r   	resourcesr   resources       r   r>   zPhoton._parse_json   sj     9Z()''	*(=a(@AA !,., 8@D((2,. . .s   Ac                    g d}|D cg c]*  }|d   j                  |      r|d   j                  |      , }}dj                  |      }|d   d   d   }|d   d   d   }|r|rt        |      }t        |      }t        |||f|      S c c}w )N)namehousenumberstreetpostcoderP   citystatecountry
propertiesz, geometrycoordinatesr'   r   )getr;   floatr   )r   rL   name_elementskrN   locationlatitude	longitudes           r   rJ   zPhoton._parse_resource   s    - !C  34$,\$:$>$>q$A &**1-  	 C99T?J'6q9Z(7:		XHi(I8Y"7BBCs   /B
)T)r=   
__module____qualname____doc__r   r   r   r   rD   rF   r>   rJ   __classcell__)r   s   @r   r	   r	      sq     LL
 $$%( 0Wl $VCx $2Ch
.Cr   r	   )collections.abcr7   	functoolsr   urllib.parser   geopy.geocoders.baser   r   geopy.locationr   
geopy.utilr   __all__r	    r   r   <module>rk      s,      " ; # 
kCX kCr   