
    N}bg                          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dS )    )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        | _        dS )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
            i/home/e360mart.nyusoft.in/public_html/e360mart_env/lib/python3.11/site-packages/geopy/geocoders/tomtom.pyr   zTomTom.__init__   s    N 	!#+ 	 	
 	
 	
 "&+++vvt7H7HI*.+++vvt?P?PQ    TF)exactly_oner   limit	typeaheadlanguagec                   |                      |          }|                     |          |d<   |rt          t          |                    |d<   |rd|d<   |r||d<   t	          |                    d                    }d                    | j        t          |          z  t          |          f          }	t          j        d| j        j        |	           t          | 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**ooF7O 	"!F7O 	*!)F:U\\'2233hh4l#;#;#;;!&))+ , ,%t~'>DDD4+EEE""3'"BBBr!   )r"   r   r%   c                   |                      |          }|                     |          }|r||d<   t          |                    d                    }d                    | j        t          |          z  t          |          f          }t          j	        d| j
        j        |           t          | 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6%%h// 	*!)F: 8 899hh(4+I+I+II!&))+ , ,%t~'>DDD43MMM""3'"BBBr!   c                     |rdndS )Ntruefalse )r   
bool_values     r    r.   zTomTom._boolean_value   s    #0vv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d S |r!                      |d         d                   S  fd|d         D             S )Nresultsr   c                 :    g | ]}                     |          S rG   _parse_search_result.0resultr   s     r    
<listcomp>z&TomTom._parse_json.<locals>.<listcomp>   s7     8 8 8 --f55 8 8 8r!   rS   r   	resourcesr"   s   `  r    r6   zTomTom._parse_json   sr     		) 4 	4 	8,,Yy-A!-DEEE8 8 8 8"+I"68 8 8 8r!   c                 x    |d         d         }|d         d         }t          |d         d         ||f|          S )Nr>   latlonaddressfreeformAddressr
   r   rW   latitude	longitudes       r    rT   zTomTom._parse_search_result   sI    *%e,:&u-	y)*;<!9-v7 7 	7r!   c                      |r|d         sd S |r!                      |d         d                   S  fd|d         D             S )N	addressesr   c                 :    g | ]}                     |          S rG   _parse_reverse_resultrU   s     r    rX   z.TomTom._parse_reverse_json.<locals>.<listcomp>   s7     : : : ..v66 : : :r!   rf   rY   s   `  r    rA   zTomTom._parse_reverse_json   sr     		+ 6 	4 	:--i.DQ.GHHH: : : :"+K"8: : : :r!   c                 |    |d                              d          \  }}t          |d         d         ||f|          S )Nr>   ,r^   r_   )splitr   r`   s       r    rg   zTomTom._parse_reverse_result   sH    $Z066s;;)y)*;<!9-v7 7 	7r!   c                     t          |t                    sd S |j        |j        d S |j        dk    rd|j        v rt	          d          |d S d S )Ni  zDeveloper Over Qps)
isinstancer   status_codetextr   )r   errors     r    _geocoder_exception_handlerz"TomTom._geocoder_exception_handler   si    %!122 	F$
(:F##(<
(J(J'(<==5H $#(J(Jr!   )r5   
__module____qualname____doc__r   r   r   r   r<   rC   r.   r-   r@   r6   rT   rA   rg   rp   __classcell__)r   s   @r    r   r      sP         6L?L $$( #1R 1R 1R 1R 1R 1R 1Rn $7C 7C 7C 7C 7Cz $,C ,C ,C ,C ,C\1 1 1
 
 


 
 

8 8 87 7 7: : :7 7 7
I I I I I I 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>r}      s          ) ) ) ) ) ) ) ) + + + + + + + + + + + + ; ; ; ; ; ; ; ; # # # # # #      
VI VI VI VI VIX VI VI VI VI VIr!   