a
    }c7                     @   s   d dl Z d dlm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e d	e jZd
d ZG dd de	ZG dd de	ZdS )    N)partial)	urlencode)exc)DEFAULT_SENTINELGeocoder)Location)logger)
What3WordsWhat3WordsV3z-[^\W\d\_]+\.{1,1}[^\W\d\_]+\.{1,1}[^\W\d\_]+$c                 C   s   t | sdS dS dS )z)
    Check query validity with regex
    FTN)_MULTIPLE_WORD_REmatch)query r   V/var/www/html/django/DPS/env/lib/python3.9/site-packages/geopy/geocoders/what3words.py_check_query   s    
r   c                       sn   e Zd ZdZdZdZeededd fdd
Zdd	ed
ddZdddZ	dd	ed
ddZ
dddZ  ZS )r	   zWhat3Words geocoder using the legacy V2 API.

    Documentation at:
        https://docs.what3words.com/api/v2/

    .. attention::
        Consider using :class:`.What3WordsV3` instead.
    z/v2/forwardz/v2/reverseNtimeoutproxies
user_agentssl_contextadapter_factoryc                   sN   t  jd|||||d || _d}d| j|| jf | _d| j|| jf | _dS )a  

        :param str api_key: Key provided by What3Words
            (https://accounts.what3words.com/register).

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

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

        :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
        httpsschemer   r   r   r   r   api.what3words.com	%s://%s%sNsuper__init__api_keyr   geocode_pathgeocode_apireverse_pathreverse_apiselfr   r   r   r   r   r   domain	__class__r   r   r   (   s    !	zWhat3Words.__init__enTlangexactly_oner   c                C   sh   t |std|| | jd}d| jt|f}t	d| j
j| t| j|d}| j|||dS )a(  
        Return a location point for a `3 words` query. If the `3 words` address
        doesn't exist, a :class:`geopy.exc.GeocoderQueryError` exception will be
        thrown.

        :param str query: The 3-word address you wish to geocode.

        :param str lang: two character language code as supported by
            the API (https://docs.what3words.com/api/v2/#lang).

        :param bool exactly_one: Return one result or a list of results, if
            available. Due to the address scheme there is always exactly one
            result for each `3 words` address, so this parameter is rather
            useless for this geocoder.

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

        :rtype: :class:`geopy.location.Location` or a list of them, if
            ``exactly_one=False``.
        &Search string must be 'word.word.word')addrr+   key?%s.geocode: %sr,   r   )r   r   GeocoderQueryErrorlowerr   joinr!   r   r   debugr(   __name__r   _parse_json_call_geocoderr%   r   r+   r,   r   paramsurlcallbackr   r   r   geocodeW   s    !zWhat3Words.geocodec                 C   s`   |d  d}|r>d|d d  }|dkr4t|t|dd }||}|rV|S |gS dS )	g
        Parse type, words, latitude, and longitude and language from a
        JSON response.
        statuscode Error returned by What3Words: %smessagei  c                 S   s`   d| v rR| d }| d }|d |d  }}|rB|rBt |}t |}t|||f| S tddS )'
            Parse record.
            ZgeometrywordslatlngError parsing result.Nfloatr   r   ZGeocoderParseErrorresourcerF   positionZlatitudeZ	longituder   r   r   parse_resource   s    z.What3Words._parse_json.<locals>.parse_resourceNgetr   ZGeocoderAuthenticationFailurer4   )r%   	resourcesr,   rB   exc_msgrO   locationr   r   r   r9      s    

zWhat3Words._parse_jsonc                C   sd   |  }| ||  | jd}d| jt|f}td| jj	| t
| j|d}| j|||dS )a  
        Return a `3 words` address by location point. Each point on surface has
        a `3 words` address, so there's always a non-empty response.

        :param query: The coordinates for which you wish to obtain the 3 word
            address.
        :type query: :class:`geopy.point.Point`, list or tuple of ``(latitude,
            longitude)``, or string as ``"%(latitude)s, %(longitude)s"``.

        :param str lang: two character language code as supported by the
            API (https://docs.what3words.com/api/v2/#lang).

        :param bool exactly_one: Return one result or a list of results, if
            available. Due to the address scheme there is always exactly one
            result for each `3 words` address, so this parameter is rather
            useless for this geocoder.

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

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

        )Zcoordsr+   r/   r0   %s.reverse: %sr2   r3   r5   Z_coerce_point_to_stringr   r6   r#   r   r   r7   r(   r8   r   _parse_reverse_jsonr:   r;   r   r   r   reverse   s    "zWhat3Words.reversec                 C   s   |  ||S zJ
        Parses a location from a single-result reverse API call.
        r9   r%   rR   r,   r   r   r   rW      s    zWhat3Words._parse_reverse_json)T)Tr8   
__module____qualname____doc__r    r"   r   r   r?   r9   rX   rW   __classcell__r   r   r'   r   r	      s&   	31
+0r	   c                       sl   e Zd ZdZdZdZeededd fdd
Zded	d
dZdddZ	ddedddZ
dddZ  ZS )r
   zWhat3Words geocoder using the V3 API.

    Documentation at:
        https://developer.what3words.com/public-api/docs

    .. versionadded:: 2.2
    z/v3/convert-to-coordinatesz/v3/convert-to-3waNr   c                   sN   t  jd|||||d || _d}d| j|| jf | _d| j|| jf | _dS )a  

        :param str api_key: Key provided by What3Words
            (https://accounts.what3words.com/register).

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

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

        :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`.
        r   r   r   r   Nr   r$   r'   r   r   r      s    	zWhat3WordsV3.__init__T)r,   r   c                C   sb   t |std|| jd}d| jt|f}td| j	j
| t| j|d}| j|||dS )a  
        Return a location point for a `3 words` query. If the `3 words` address
        doesn't exist, a :class:`geopy.exc.GeocoderQueryError` exception will be
        thrown.

        :param str query: The 3-word address you wish to geocode.

        :param bool exactly_one: Return one result or a list of results, if
            available. Due to the address scheme there is always exactly one
            result for each `3 words` address, so this parameter is rather
            useless for this geocoder.

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

        :rtype: :class:`geopy.location.Location` or a list of them, if
            ``exactly_one=False``.
        r-   )rF   r/   r0   r1   r2   r3   )r   r   r4   r   r6   r!   r   r   r7   r(   r8   r   r9   r:   )r%   r   r,   r   r<   r=   r>   r   r   r   r?     s    zWhat3WordsV3.geocodec                 C   sj   | d}|durHd|d d  }| d}|dv r>t|t|dd }||}|r`|S |gS dS )	r@   errorNrC   rD   rB   )Z
MissingKeyZ
InvalidKeyc                 S   s`   d| v rR| d }| d }|d |d  }}|rB|rBt |}t |}t|||f| S tddS )rE   coordinatesrF   rG   rH   rI   NrJ   rL   r   r   r   rO   \  s    z0What3WordsV3._parse_json.<locals>.parse_resourcerP   )r%   rR   r,   ra   rS   Zexc_coderO   rT   r   r   r   r9   K  s    



zWhat3WordsV3._parse_jsonr)   r*   c                C   sd   |  }| ||  | jd}d| jt|f}td| jj	| t
| j|d}| j|||dS )a  
        Return a `3 words` address by location point. Each point on surface has
        a `3 words` address, so there's always a non-empty response.

        :param query: The coordinates for which you wish to obtain the 3 word
            address.
        :type query: :class:`geopy.point.Point`, list or tuple of ``(latitude,
            longitude)``, or string as ``"%(latitude)s, %(longitude)s"``.

        :param str lang: two character language code as supported by the
            API (https://developer.what3words.com/public-api/docs#available-languages).

        :param bool exactly_one: Return one result or a list of results, if
            available. Due to the address scheme there is always exactly one
            result for each `3 words` address, so this parameter is rather
            useless for this geocoder.

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

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

        )rb   languager/   r0   rU   r2   r3   rV   r;   r   r   r   rX   s  s    "zWhat3WordsV3.reversec                 C   s   |  ||S rY   rZ   r[   r   r   r   rW     s    z What3WordsV3._parse_reverse_json)T)Tr\   r   r   r'   r   r
      s$   1,
,0r
   )re	functoolsr   urllib.parser   Zgeopyr   Zgeopy.geocoders.baser   r   Zgeopy.locationr   Z
geopy.utilr   __all__compileUr   r   r	   r
   r   r   r   r   <module>   s   
 L