
    g08                         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 j                  d	e j                         Zd
 Z G d de	      Z G d de	      Zy)    N)partial)	urlencode)exc)DEFAULT_SENTINELGeocoder)Location)logger)
What3WordsWhat3WordsV3z-[^\W\d\_]+\.{1,1}[^\W\d\_]+\.{1,1}[^\W\d\_]+$c                 0    t         j                  |       syy)z)
    Check query validity with regex
    FT)_MULTIPLE_WORD_REmatch)querys    Z/var/www/api/v1/venv_getwork_v1/lib/python3.12/site-packages/geopy/geocoders/what3words.py_check_queryr      s     ""5)    c                   j     e Zd ZdZdZdZeededdd fd
Zdd	ed
dZddZ	dd	ed
dZ
ddZ x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api.what3words.comtimeoutproxies
user_agentssl_contextadapter_factorydomainc                    t         |   d|||||       || _        | j                  d|| j                  | _        | j                  d|| j                  | _        y)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

        :param str domain: base api domain

            .. versionadded:: 2.4
        httpsschemer   r   r   r   r   ://Nsuper__init__api_keyr   geocode_pathgeocode_apireverse_pathreverse_api	selfr$   r   r   r   r   r   r   	__class__s	           r   r#   zWhat3Words.__init__(   se    L 	!#+ 	 	
 *.++vt?P?PQ*.++vt?P?PQr   enTlangexactly_oner   c                v   t        |      st        j                  d      ||j                         | j                  d}dj                  | j                  t        |      f      }t        j                  d| j                  j                  |       t        | j                  |      }| j                  |||      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callbacks           r   geocodezWhat3Words.geocode[   s    B E"((8 
 JJL<<
 hh(()F*;<=%t~~'>'>D4++E""3'"BBr   c                     |d   j                  d      }|r:d|d   d   z  }|dk(  rt        j                  |      t        j                  |      d } ||      }|r|S |gS )g
        Parse type, words, latitude, and longitude and language from a
        JSON response.
        statuscode Error returned by What3Words: %smessagei  c                     d| v r=| d   }| d   }|d   |d   }}|r|rt        |      }t        |      }t        |||f|       S t        j                  d      )'
            Parse record.
            geometrywordslatlngError parsing result.floatr   r   GeocoderParseErrorresourcerM   positionlatitude	longitudes        r   parse_resourcez.What3Words._parse_json.<locals>.parse_resource   so    
 X% )#J/&.uox)	$XH %i 0I)'<hGG,,-DEEr   getr   GeocoderAuthenticationFailurer8   )r*   	resourcesr/   rG   exc_msgrY   locations          r   r=   zWhat3Words._parse_json   s{     "&&v.89X;Ny;YYGs{77@@((11	F" "),O:r   c                t   |j                         }| j                  |      |j                         | j                  d}dj                  | j                  t        |      f      }t        j                  d| j                  j                  |       t        | j                  |      }| j                  |||      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``.

        )coordsr.   r3   r4   %s.reverse: %sr6   r7   r9   _coerce_point_to_stringr$   r:   r(   r   r	   r;   r+   r<   r   _parse_reverse_jsonr>   r?   s           r   reversezWhat3Words.reverse   s    D zz| 2259JJL<<
 hh(()F*;<=%t~~'>'>D433M""3'"BBr   c                 &    | j                  ||      S zJ
        Parses a location from a single-result reverse API call.
        r=   r*   r]   r/   s      r   re   zWhat3Words._parse_reverse_json        	;77r   Tr<   
__module____qualname____doc__r%   r'   r   r#   rC   r=   rf   re   __classcell__r+   s   @r   r
   r
      s^     !L L %$( '1Rn $/Cb%V $.C`8r   r
   c                   h     e Zd ZdZdZdZeededdd fd
Zded	d
ZddZ	ddeddZ
ddZ x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   r   c                    t         |   d|||||       || _        | j                  d|| j                  | _        | j                  d|| j                  | _        y)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`.

        :param str domain: base api domain

            .. versionadded:: 2.4
        r   r   r    Nr!   r)   s	           r   r#   zWhat3WordsV3.__init__   se    H 	!#+ 	 	
 *.++vt?P?PQ*.++vt?P?PQr   T)r/   r   c                X   t        |      st        j                  d      || j                  d}dj	                  | j
                  t        |      f      }t        j                  d| j                  j                  |       t        | j                  |      }| j                  |||      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``.
        r1   )rM   r3   r4   r5   r6   r7   )r   r   r8   r$   r:   r&   r   r	   r;   r+   r<   r   r=   r>   )r*   r   r/   r   r@   rA   rB   s          r   rC   zWhat3WordsV3.geocode'  s    : E"((8 
 <<

 hh(()F*;<=%t~~'>'>D4++E""3'"BBr   c                     |j                  d      }|Jd|d   d   z  }|j                  d      }|dv rt        j                  |      t        j                  |      d } ||      }|r|S |gS )rE   errorrH   rI   rG   )
MissingKey
InvalidKeyc                     d| v r=| d   }| d   }|d   |d   }}|r|rt        |      }t        |      }t        |||f|       S t        j                  d      )rK   coordinatesrM   rN   rO   rP   rQ   rT   s        r   rY   z0What3WordsV3._parse_json.<locals>.parse_resourced  so    
 ( )#M2&.uox)	$XH %i 0I)'<hGG,,-DEEr   rZ   )r*   r]   r/   rw   r^   exc_coderY   r_   s           r   r=   zWhat3WordsV3._parse_jsonS  s     g&89W;Mi;XXGyy(H7777@@((11	F" "),O:r   r,   r-   c                t   |j                         }| j                  |      |j                         | j                  d}dj                  | j                  t        |      f      }t        j                  d| j                  j                  |       t        | j                  |      }| j                  |||      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``.

        )r{   languager3   r4   rb   r6   r7   rc   r?   s           r   rf   zWhat3WordsV3.reverse{  s    D zz|  77>

<<
 hh(()F*;<=%t~~'>'>D433M""3'"BBr   c                 &    | j                  ||      S rh   ri   rj   s      r   re   z What3WordsV3._parse_reverse_json  rk   r   rl   rm   rr   s   @r   r   r      s[     0L'L %$( '/Rj $*CX&X $.C`8r   r   )re	functoolsr   urllib.parser   geopyr   geopy.geocoders.baser   r   geopy.locationr   
geopy.utilr	   __all__compileUr   r   r
   r    r   r   <module>r      s[    	  "  ; # 
(BJJ4bdd 
L8 L8^E88 E8r   