a
    }c                      @   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0 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                       s\   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-SHA1ZAUTH_HEADER)Z
client_keyZclient_secretZsignature_methodZ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__ W/var/www/html/django/DPS/env/lib/python3.9/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 )Z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 )Zcountrycoder   r   )valid_country_codesr   r   r"   W   s   r   )resultsr!   r$   r   )r!   r$   r   _filtered_resultsI   s    

z"YahooPlaceFinder._filtered_resultsc              	      sh   zD|d d }t |r&t |dg s,W dS  fdd|d D }W n ttfyb   tdY n0 |S )zF
        Returns the parsed result of a PlaceFinder API call.
        Zbossresponseplacefinderr%   Nc                    s4   g | ],}t  |t|d  t|d f|dqS )ZlatitudeZ	longituder#   )r   humanizefloat)r   Zplacer   r   r   r"   i   s   z4YahooPlaceFinder._parse_response.<locals>.<listcomp>z Error parsing PlaceFinder result)lenr   KeyError
ValueErrorr   )r   contentr'   r%   r   r*   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)joinr1   r   r1   r   r(   v   s    zYahooPlaceFinder.humanizeTr   Fc                 C   s   |dd}|rd|d< |r"d|d< |r6|d  d7  < | j | j|t|| jd	}	| |	}
|
d
u rdd
S | |
||}
|r~|
d S |
S d
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)r2   flagsRZgflags1countr9   T)r   Z	requesterparamsr   Nr   )Z_call_geocoderr   r   r   r/   r&   )r   queryexactly_oner   r!   reverser$   Zwith_timezoner>   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)r@   r   rA   )Z_coerce_point_to_string
isinstancer	   replacerC   )r   r?   r@   r   r   r   r   rA      s    

zYahooPlaceFinder.reverse)TNr   FNF)TN)__name__
__module____qualname____doc__r   r   staticmethodr&   r/   r(   rC   rA   __classcell__r   r   r   r   r      s$   	/

      
>r   N)rK   requestsr   r   Zrequests_oauthlibr   r   r   Zgeopy.geocoders.baser   r   Z	geopy.excr   Zgeopy.locationr   Zgeopy.compatr	   r
   __all__r   r   r   r   r   <module>   s   
