o
    ÔèFh   ã                   @   s�   d Z zddlmZmZ ddlmZ dZW n ey   dZY nw ddlm	Z	m
Z
 ddlmZ ddlmZ dd	lmZmZ d
ZG dd„ de	ƒZdS )z&
:class:`.YahooPlaceFinder` geocoder.
é    )ÚgetÚRequest)ÚOAuth1FT)ÚGeocoderÚDEFAULT_TIMEOUT)ÚGeocoderParseError)ÚLocation)Ústring_compareÚ	text_type)ÚYahooPlaceFinderc                       sh   e Zd ZdZeddf‡ fdd„	Zedd„ ƒZdd„ Zed	d
„ ƒZ							ddd„Z
ddd„Z‡  ZS )r   z†
    Geocoder that utilizes the Yahoo! BOSS PlaceFinder API. Documentation at:
        https://developer.yahoo.com/boss/geo/docs/
    Nc                    sV   t rtdƒ‚tt| ƒj|||d� t|ƒ| _t|ƒ| _t| j| jddd�| _	d| _
dS )aØ  
        :param str consumer_key: Key provided by Yahoo.

        :param str consumer_secret: Secret corresponding to the key
            provided by Yahoo.

        :param int timeout: Time, in seconds, to wait for the geocoding service
            to respond before raising a :class:`geopy.exc.GeocoderTimedOut`
            exception.

        :param dict proxies: If specified, routes this geocoder"s requests
            through the specified proxy. E.g., {"https": "192.0.2.0"}. For
            more information, see documentation on
            :class:`urllib2.ProxyHandler`.

            .. versionadded:: 0.96

        :param str user_agent: Use a custom User-Agent header.

            .. versionadded:: 1.12.0
        zgrequests-oauthlib is needed for YahooPlaceFinder. Install with `pip install geopy -e ".[placefinder]"`.)ÚtimeoutÚproxiesÚ
user_agentz	HMAC-SHA1ÚAUTH_HEADER)Ú
client_keyÚclient_secretÚsignature_methodÚsignature_typez+https://yboss.yahooapis.com/geo/placefinderN)Úrequests_missingÚImportErrorÚsuperr   Ú__init__r
   Úconsumer_keyÚconsumer_secretr   ÚauthÚapi)Úselfr   r   r   r   r   ©Ú	__class__© úT/var/www/html/loop/nvenv/lib/python3.10/site-packages/geopy/geocoders/placefinder.pyr      s    ÿ
ÿ

ü
zYahooPlaceFinder.__init__c                    s0   ˆ r‡ fdd„| D ƒ} ˆr‡fdd„| D ƒ} | S )z�
        Returns only the results that meet the minimum quality threshold
        and are located in expected countries.
        c                    s"   g | ]}t |jd  ƒˆ kr|‘qS )Úquality)ÚintÚraw©Ú.0Úloc)Úmin_qualityr   r    Ú
<listcomp>P   s
    þz6YahooPlaceFinder._filtered_results.<locals>.<listcomp>c                    s   g | ]}|j d  ˆ v r|‘qS )Úcountrycode©r#   r$   )Úvalid_country_codesr   r    r(   W   s
    þr   )Úresultsr'   r+   r   )r'   r+   r    Ú_filtered_resultsI   s   
þ
þz"YahooPlaceFinder._filtered_resultsc              	      sb   z#|d d }t |ƒrt | dg ¡ƒsW dS ‡ fdd„|d D ƒ}W |S  ttfy0   tdƒ‚w )zF
        Returns the parsed result of a PlaceFinder API call.
        ÚbossresponseÚplacefinderr,   Nc                    s4   g | ]}t ˆ  |¡t|d  ƒt|d ƒf|d�‘qS )ÚlatitudeÚ	longituder*   )r   ÚhumanizeÚfloat)r%   Úplace©r   r   r    r(   i   s    ûýÿz4YahooPlaceFinder._parse_response.<locals>.<listcomp>z Error parsing PlaceFinder result)Úlenr   ÚKeyErrorÚ
ValueErrorr   )r   Úcontentr/   r,   r   r5   r    Ú_parse_response_   s   
ÿ
úýÿz YahooPlaceFinder._parse_responsec                    s   d  ‡ fdd„dD ƒ¡S )zW
        Returns a human readable representation of a raw PlaceFinder location
        z, c                    s   g | ]
}ˆ | rˆ | ‘qS r   r   )r%   Úline©Úlocationr   r    r(   {   s    ýÿz-YahooPlaceFinder.humanize.<locals>.<listcomp>)Úline1Úline2Úline3Úline4)Újoinr<   r   r<   r    r2   v   s   þzYahooPlaceFinder.humanizeTr   Fc                 C   s‚   |ddœ}|rd|d< |rd|d< |r|d  d7  < | j | j|t|| jd	�}	|  |	¡}
|
d
u r2d
S |  |
||¡}
|r?|
d S |
S )aâ  
        Geocode a location query.

        :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 min_quality:

        :param bool reverse:

        :param valid_country_codes:
        :type valid_country_codes: list or tuple

        :param bool with_timezone: Include the timezone in the response's
            `raw` dictionary (as `timezone`).
        ÚJ)r=   ÚflagsÚRÚgflagsÚ1ÚcountrD   ÚT)r   Ú	requesterÚparamsr   Nr   )Ú_call_geocoderr   r   r   r:   r-   )r   ÚqueryÚexactly_oner   r'   Úreverser+   Úwith_timezonerK   Úresponser,   r   r   r    Úgeocode�   s6   þû
ýzYahooPlaceFinder.geocodec                 C   s2   |   |¡}t|tƒr| dd¡}| j|||dd�S )a¾  
        Returns a reverse geocoded location using Yahoo"s PlaceFinder API.

        :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.
        ú Ú T)rN   r   rO   )Ú_coerce_point_to_stringÚ
isinstancer	   ÚreplacerR   )r   rM   rN   r   r   r   r    rO   ¿   s   

üzYahooPlaceFinder.reverse)TNr   FNF)TN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Ústaticmethodr-   r:   r2   rR   rO   Ú__classcell__r   r   r   r    r      s&    	ú/


ø>r   N)r[   Úrequestsr   r   Úrequests_oauthlibr   r   r   Úgeopy.geocoders.baser   r   Ú	geopy.excr   Úgeopy.locationr   Úgeopy.compatr	   r
   Ú__all__r   r   r   r   r    Ú<module>   s    ÿ