
    gj&                     z    d dl Zd dlmZ d dlmZ d dlmZmZ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)    N)partial)	urlencode)GeocoderQueryErrorGeocoderServiceErrorGeocoderUnavailable)DEFAULT_SENTINELGeocoder)Location)logger)Woosmapc                   x     e Zd ZdZdZddeededd fd
Zd Zddeddddd	d
ZddeddddZ	ddZ
d Z xZS )r   zGeocoder using the Woosmap Address API.

    Documentation at:
        https://developers.woosmap.com/products/address-api/geocode/

    .. versionadded:: 2.4
    z/address/geocode/jsonzapi.woosmap.comN)domainschemetimeoutproxies
user_agentssl_contextadapter_factoryc                    t         	|   ||||||       || _        |j                  d      | _        | j
                  d| j                  | j                  | _        y)a/  

        :param str api_key: The Private API key required by Woosmap to perform
            geocoding requests.
            API keys are managed through
            the Woosmap Console (https://console.woosmap.com/).
            Make sure to have ``Address API`` service enabled
            for your project Private API key.

        :param str domain: Domain where the target Woosmap service
            is hosted.

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

        )r   r   r   r   r   r   /z://N)super__init__api_keystripr   r   api_pathapi)
selfr   r   r   r   r   r   r   r   	__class__s
            W/var/www/api/v1/venv_getwork_v1/lib/python3.12/site-packages/geopy/geocoders/woosmap.pyr   zWoosmap.__init__   s]    X 	!#+ 	 	
 ll3'"&++t{{DMMJ    c                 0   g }t        |t        j                  j                        r|j	                         }nHt        |t        j                  j
                        rt        |t        t        f      s|}nt        d      dj                  d |D              S )Nz7`components` parameter must be of type `dict` or `list`|c              3   >   K   | ]  }d j                  |        yw):N)join).0items     r   	<genexpr>z3Woosmap._format_components_param.<locals>.<genexpr>^   s      
'6tCHHTNs   )

isinstancecollectionsabcMappingitemsSequencestrbytes
ValueErrorr%   )r   
componentscomponent_itemss      r   _format_components_paramz Woosmap._format_components_paramP   s    j+//"9"9:(..0Oz;??#;#;<zC<8(OIK K xx 
'6
 
 	
r    T)limitexactly_oner   locationr2   languagecountry_code_formatc                   || j                   d}	|r| j                  |d      }
|
|	d<   |r| j                  |      |	d<   |r||	d<   |r||	d<   |r||	d<   |rd	|	d<   d
j                  | j                  t        |	      f      }t        j                  d| j                  j                  |       t        | j                  |      }| j                  |||      S )ay  
        Return a location point by address.

        :param str query: The address you wish to geocode.

        :param int limit: Maximum number of results to be returned.
            This will be reset to one if ``exactly_one`` is True.

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

        :type location: :class:`geopy.point.Point`, list or tuple of ``(latitude,
            longitude)``, or string as ``"%(latitude)s, %(longitude)s"``.
        :param location: The center latlng to bias the search context.

        :type components: dict or list
        :param components: Geographic places to which you would like to restrict
            your results. Currently, you can use components to filter over countries.
            Countries are identified by a two character, ISO 3166-1 Alpha-2
            or a three character, ISO 3166-1 Alpha-3 compatible country code.

            Pass a list of tuples if you want to specify multiple components of
            the same type, e.g.:

                >>> [('country', 'FRA'), ('country', 'DE')]

        :param str language: The language in which to return results.
            Must be a ISO 639-1 language code.

        :param str country_code_format: Default country code format
            in responses is Alpha3.
            However, format in responses can be changed
            by specifying components in alpha2.
            Available formats: ``alpha2``, ``alpha3``.

        :rtype: ``None``, :class:`geopy.location.Location` or a list of them, if
            ``exactly_one=False``.
        )addressprivate_key%(lat)s,%(lon)soutput_formatr7   r2   r8   	cc_formatr5      ?z%s.geocode: %sr6   r   )r   _coerce_point_to_stringr4   r%   r   r   r   debugr   __name__r   _parse_json_call_geocoder)r   queryr5   r6   r   r7   r2   r8   r9   paramspointurlcallbacks                r   geocodezWoosmap.geocodeb   s    p <<

 00?P 1 RE!&F:#'#@#@#LF< !)F:"5F;#F7OF7Ohh)F"345%t~~'>'>D4++E""3'"BBr    )r5   r6   r   r8   r9   c                v   | j                  |d      }|| j                  d}|r||d<   |r||d<   |r||d<   |rd|d<   dj                  | j                  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 int limit: Maximum number of results to be returned.
            This will be reset to one if ``exactly_one`` is True.

        :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: The language in which to return results.

        :param str country_code_format: Default country code format
            in responses is Alpha3.
            However, format in responses can be changed
            by specifying components in alpha2.
            Available formats: ``alpha2``, ``alpha3``.

        :rtype: ``None``, :class:`geopy.location.Location` or a list of them, if
            ``exactly_one=False``.
        r=   r>   )latlngr<   r8   r@   r5   rA   rB   z%s.reverse: %srC   rD   )rE   r   r%   r   r   r   rF   r   rG   r   rH   rI   )r   rJ   r5   r6   r   r8   r9   rQ   rK   rM   rN   s              r   reversezWoosmap.reverse   s    R --eCT-U<<
 !)F:"5F;#F7OF7Ohh)F"345%t~~'>'>D4++E""3'"BBr    c                     |j                  dg       }| j                  |       |sy d }|r ||d         S |D cg c]
  } ||       c}S c c}w )Nresultsc                 n    | j                  d      }| d   d   d   }| d   d   d   }t        |||f|       S )z6Get the location, lat, lng from a single json address.formatted_addressgeometryr7   latlng)getr
   )r;   r7   latitude	longitudes       r   parse_addressz*Woosmap._parse_json.<locals>.parse_address   sM    {{#67Hz*:6u=H
+J7>IHx&;WEEr    r   )rZ   _check_status)r   responser6   	addressesr]   r;   s         r   rH   zWoosmap._parse_json   s]    LLB/	8$	F  1..:CD)wM'*)DDDs   Ac                     |j                  d      }|dk(  ry |dk(  ry |j                  d      }|dk(  rt        |xs d      |dk(  rt        |xs d      |d	k(  rt        |xs d
      t        |xs d      )NstatusOKZERO_RESULTSerror_messageINVALID_REQUESTz,Invalid request or missing address or latlngREQUEST_DENIEDz2Your request was denied. Please check your API KeyUNKNOWN_ERRORzServer errorzUnknown error)rZ   r   r   r   )r   r_   rb   re   s       r   r^   zWoosmap._check_status  s    h'T>^# _5&&$O!OQ Q''$U!UW W&%m&E~FF '}'GHHr    )T)rG   
__module____qualname____doc__r   r   r   r4   rO   rR   rH   r^   __classcell__)r   s   @r   r   r      su     'H !  $6Kp
,   NCh   :CxE&Ir    r   )collections.abcr*   	functoolsr   urllib.parser   	geopy.excr   r   r   geopy.geocoders.baser   r	   geopy.locationr
   
geopy.utilr   __all__r    r    r   <module>rv      s2      " S S ; # 
GIh GIr    