
    g                      z    d dl mZ 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 dlmZ d dlmZ dZ G d	 d
e      Zy)    )partial)quote	urlencode)AdapterHTTPError)GeocoderQuotaExceeded)DEFAULT_SENTINELGeocoderLocation)logger)TomTomc                        e Zd ZdZdZdZdeededdd fd
Zdedd	dd
dZdedddZ	d Z
d Zd Zd Zd Zd Zd Zd Z xZS )r   zuTomTom geocoder.

    Documentation at:
        https://developer.tomtom.com/search-api/search-api-documentation
    z /search/2/geocode/%(query)s.jsonz*/search/2/reverseGeocode/%(position)s.jsonNzapi.tomtom.com)schemetimeoutproxies
user_agentssl_contextadapter_factorydomainc                    t         	|   ||||||       || _        | j                  d|| j                  | _        | j                  d|| j                  | _        y)a7  
        :param str api_key: TomTom API key.

        :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 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: Domain where the target TomTom service
            is hosted.
        )r   r   r   r   r   r   z://N)super__init__api_keyr   geocode_pathapireverse_pathapi_reverse)
selfr   r   r   r   r   r   r   r   	__class__s
            V/var/www/api/v1/venv_getwork_v1/lib/python3.12/site-packages/geopy/geocoders/tomtom.pyr   zTomTom.__init__   sd    N 	!#+ 	 	
 "&++vt7H7HI*.++vt?P?PQ    TF)exactly_oner   limit	typeaheadlanguagec                   | j                  |      }| j                  |      |d<   |rt        t        |            |d<   |rd|d<   |r||d<   t	        |j                  d            }dj                  | j                  t        |      z  t        |      f      }	t        j                  d| j                  j                  |	       t        | j                  |	      }
| j!                  |	|
|
      S )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 int limit: Maximum amount of results to return from the service.
            Unless exactly_one is set to False, limit will always be 1.

        :param bool typeahead: If the "typeahead" flag is set, the query
            will be interpreted as a partial input and the search will
            enter predictive mode.

        :param str language: Language in which search results should be
            returned. When data in specified language is not
            available for a specific field, default language is used.
            List of supported languages (case-insensitive):
            https://developer.tomtom.com/online-search/online-search-documentation/supported-languages

        :rtype: ``None``, :class:`geopy.location.Location` or a list of them, if
            ``exactly_one=False``.
        r$   r#   1r%   utf-8?)queryz%s.geocode: %sr"   r   )_geocode_params_boolean_valuestrintr   encodejoinr   dictr   r   debugr   __name__r   _parse_json_call_geocoder)r   r*   r"   r   r#   r$   r%   paramsquoted_queryurlcallbacks              r    geocodezTomTom.geocodeJ   s    N %%e,"11)<{!#e*oF7O!F7O!)F:U\\'23hh4l#;;!&)+ ,%t~~'>'>D4++E""3'"BBr!   )r"   r   r%   c                   | j                  |      }| j                  |      }|r||d<   t        |j                  d            }dj	                  | j
                  t        |      z  t        |      f      }t        j                  d| j                  j                  |       t        | j                  |      }	| j                  ||	|      S )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: Language in which search results should be
            returned. When data in specified language is not
            available for a specific field, default language is used.
            List of supported languages (case-insensitive):
            https://developer.tomtom.com/online-search/online-search-documentation/supported-languages

        :rtype: ``None``, :class:`geopy.location.Location` or a list of them, if
            ``exactly_one=False``.
        r%   r(   r)   )positionz%s.reverse: %sr+   r,   )_coerce_point_to_string_reverse_paramsr   r1   r2   r   r3   r   r   r4   r   r5   r   _parse_reverse_jsonr7   )
r   r*   r"   r   r%   r>   r8   quoted_positionr:   r;   s
             r    reversezTomTom.reverse   s    B //6%%h/!)F: 89hh((4+II!&)+ ,%t~~'>'>D433M""3'"BBr!   c                     |rdS dS )Ntruefalse )r   
bool_values     r    r.   zTomTom._boolean_value   s    #v00r!   c                     d| j                   iS Nkeyr   )r   formatted_querys     r    r-   zTomTom._geocode_params       4<<
 	
r!   c                     d| j                   iS rJ   rL   )r   r>   s     r    r@   zTomTom._reverse_params   rN   r!   c                     |r|d   sy |r| j                  |d   d         S |d   D cg c]  }| j                  |       c}S c c}w )Nresultsr   )_parse_search_resultr   	resourcesr"   results       r    r6   zTomTom._parse_json   sd    	) 4,,Yy-A!-DEE #,I"68"6 --f5"68 8 8   Ac                 L    |d   d   }|d   d   }t        |d   d   ||f|      S )Nr>   latlonaddressfreeformAddressr
   r   rU   latitude	longitudes       r    rR   zTomTom._parse_search_result   sD    *%e,:&u-	y)*;<!9-v7 	7r!   c                     |r|d   sy |r| j                  |d   d         S |d   D cg c]  }| j                  |       c}S c c}w )N	addressesr   )_parse_reverse_resultrS   s       r    rA   zTomTom._parse_reverse_json   sd    	+ 6--i.DQ.GHH #,K"8:"8 ..v6"8: : :rV   c                 Z    |d   j                  d      \  }}t        |d   d   ||f|      S )Nr>   ,rZ   r[   )splitr   r\   s       r    ra   zTomTom._parse_reverse_result   s@    $Z066s;)y)*;<!9-v7 	7r!   c                     t        |t              sy |j                  |j                  y |j                  dk\  rd|j                  v rt	        d      |y y )Ni  zDeveloper Over Qps)
isinstancer   status_codetextr   )r   errors     r    _geocoder_exception_handlerz"TomTom._geocoder_exception_handler   sY    %!12$

(:#(<

(J'(<=5H )K#r!   )r5   
__module____qualname____doc__r   r   r   r   r<   rC   r.   r-   r@   r6   rR   rA   ra   rj   __classcell__)r   s   @r    r   r      s     6L?L $$( #1Rn $7Cz $,C\1



87:7
Ir!   r   N)	functoolsr   urllib.parser   r   geopy.adaptersr   	geopy.excr   geopy.geocoders.baser   r	   geopy.locationr   
geopy.utilr   __all__r   rG   r!   r    <module>rw      s/     ) + + ; # 
VIX VIr!   