
    N}bgB                         d dl Z d dlmc m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 G d	 d
e          ZdS )    N)partial)	urlencode)GeocoderQueryError)DEFAULT_SENTINELGeocoder)Location)logger)	IGNFrancec                        e Zd ZdZdZdZ	 ddddddeededd
 fdZdd	d
ddeddZdd	ddeddZ		 	 	 ddZ
ddZd ZddZ xZS )r
   zGeocoder using the IGN France GeoCoder OpenLS API.

    Documentation at:
        https://geoservices.ign.fr/services-web-essentiels
    aK  <?xml version="1.0" encoding="UTF-8"?>
    <XLS version="1.2"
        xmlns="http://www.opengis.net/xls"
        xmlns:gml="http://www.opengis.net/gml"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.opengis.net/xls
        http://schemas.opengis.net/ols/1.2/olsAll.xsd">
        <RequestHeader srsName="epsg:4326"/>
        <Request methodName="{method_name}"
                 maximumResponses="{maximum_responses}"
                 requestID=""
                 version="1.2">
            {sub_request}
        </Request>
    </XLS>z/essentiels/geoportail/olsNz
wxs.ign.fr)
usernamepasswordrefererdomainschemetimeoutproxies
user_agentssl_contextadapter_factoryc       
            t                                          ||||	|
|           |s|s|s|rt          j        dt          d           |                    d          | _        | j        }| j        d| j        || _	        dS )a=  

        :param str api_key: Not used.

            .. deprecated:: 2.3
                IGNFrance geocoding methods no longer accept or require
                authentication, see `<https://geoservices.ign.fr/actualites/2021-10-04-evolution-des-modalites-dacces-aux-services-web>`_.
                This parameter is scheduled for removal in geopy 3.0.

        :param str username: Not used.

            .. deprecated:: 2.3
                See the `api_key` deprecation note.

        :param str password: Not used.

            .. deprecated:: 2.3
                See the `api_key` deprecation note.

        :param str referer: Not used.

            .. deprecated:: 2.3
                See the `api_key` deprecation note.

        :param str domain: Currently it is ``'wxs.ign.fr'``, can
            be changed for testing purposes for developer API
            e.g ``'gpp3-wxs.ign.fr'`` at the moment.

        :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
        )r   r   r   r   r   r   zIGNFrance no longer accepts or requires authentication, so api_key, username, password and referer are not used anymore. These arguments should be removed. In geopy 3 these options will be removed, causing an error instead of this warning.   )
stacklevel/z://N)
super__init__warningswarnDeprecationWarningstripr   api_pathr   api)selfapi_keyr   r   r   r   r   r   r   r   r   r   r    	__class__s                l/home/e360mart.nyusoft.in/public_html/e360mart_env/lib/python3.11/site-packages/geopy/geocoders/ignfrance.pyr   zIGNFrance.__init__'   s    @ 	!#+ 	 	
 	
 	
  		h 		( 		g 		M4
 #    ll3''="&+++t{{HHE    StreetAddress   FT)
query_typemaximum_responsesis_freeform	filteringexactly_oner   c                   |dvrt          d          |dk    r4t          |                                          dk    rt          d          d}| j                            d||          }	|rd	}nd
}|d}|	                    ||||          }
d|
i}d                    | j        t          |          f          }t          j	        d| j
        j        |           t          | j        ||          }|                     |||          S )a>  
        Return a location point by address.

        :param str query: The query string to be geocoded.

        :param str query_type: The type to provide for geocoding. It can be
            `PositionOfInterest`, `StreetAddress` or `CadastralParcel`.
            `StreetAddress` is the default choice if none provided.

        :param int maximum_responses: The maximum number of responses
            to ask to the API in the query body.

        :param str is_freeform: Set if return is structured with
            freeform structure or a more structured returned.
            By default, value is False.

        :param str filtering: Provide string that help setting geocoder
            filter. It contains an XML string. See examples in documentation
            and ignfrance.py file in directory tests.

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

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

        )PositionOfInterestr'   CadastralParcelzYou did not provided a query_type the
            webservice can consume. It should be PositionOfInterest,
            'StreetAddress or CadastralParcelr0      zfYou must send a string of fourteen
                characters long to match the cadastre required codea*  
                <GeocodeRequest returnFreeForm="{is_freeform}">
                    <Address countryCode="{query_type}">
                        <freeFormAddress>{query}</freeFormAddress>
                        {filtering}
                    </Address>
                </GeocodeRequest>
        LocationUtilityServicemethod_namesub_requestr*   truefalseN )r+   queryr)   r,   xls?z%s.geocode: %s)r+   r-   r   )r   lenr   xml_requestformatjoinr!   r   r	   debugr$   __name__r   
_parse_xml_request_raw_content)r"   r9   r)   r*   r+   r,   r-   r   r5   r>   request_stringparamsurlcallbacks                 r%   geocodezIGNFrance.geocode   sq   Z  1 1 1 % &1 2 2 2
 ***s5;;==/A/AR/G/G$ &G H H H &--0#/ . 
 
  	" KK!K I %++#!	 , 
 
 >
 hh)F"3"3455%t~'>DDDO+
 
 
 ((h(HHHr&   )r'   r8   )reverse_geocode_preferencer*   r,   r-   r   c                   d}| j                             d||          }|D ]}	|	dvrt          d          |                     |d          }
d                    d |D                       }|                    ||
||	          }d
                    | j        t          d|i          f          }t          j        d| j	        j
        |           t          | j        |dd          }|                     |||          S )aU  
        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 list reverse_geocode_preference: Enable to set expected results
            type. It can be `StreetAddress` or `PositionOfInterest`.
            Default is set to `StreetAddress`.

        :param int maximum_responses: The maximum number of responses
            to ask to the API in the query body.

        :param str filtering: Provide string that help setting geocoder
            filter. It contains an XML string. See examples in documentation
            and ignfrance.py file in directory tests.

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

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

        a@  
            <ReverseGeocodeRequest>
                {reverse_geocode_preference}
                <Position>
                  <gml:Point>
                    <gml:pos>{query}</gml:pos>
                  </gml:Point>
                  {filtering}
                </Position>
            </ReverseGeocodeRequest>
        ReverseGeocodeRequestr3   )r'   r/   z[`reverse_geocode_preference` must contain one or more of: StreetAddress, PositionOfInterestz%(lat)s %(lon)s
c              3       K   | ]	}d |z  V  
dS )z7<ReverseGeocodePreference>%s</ReverseGeocodePreference>N ).0prefs     r%   	<genexpr>z$IGNFrance.reverse.<locals>.<genexpr>)  s<       /
 /
 FL/
 /
 /
 /
 /
 /
r&   )r*   r9   rJ   r,   r;   r:   z%s.reverse: %sTr7   )r-   
is_reverser+   r<   )r>   r?   r   _coerce_point_to_stringr@   r!   r   r	   rA   r$   rB   r   rC   rD   )r"   r9   rJ   r*   r,   r-   r   r5   r>   rQ   pointrE   rG   rH   s                 r%   reversezIGNFrance.reverse   s_   T
 &--/#/ . 
 
 / 	 	DBBB(H   C ,,U4EFF%)YY /
 /
 */
 /
 /
 &
 &
" %++/'A	 , 
 
 hh)UN,C"D"DEFF%t~'>DDDO#	
 
 
 ((h(HHHr&   c                 4    t          j        |                    d                    }d } ||d            ||d            ||d                                ||          }|sdS |r                     |d         	          S  fd
|D             S )ze
        Returns location, (latitude, longitude) from XML feed
        and transform to json
        zutf-8c                     d|z  }t          |          }|                                 D ]0}|j                            |          r|j        |d         |_        1dS )z*Remove namespace in the document in place.z{%s}N)r=   itertag
startswith)doc	namespacensnslelems        r%   remove_namespacez.IGNFrance._parse_xml.<locals>.remove_namespaceN  sb    )#Bb''C

 . .8&&r** .#x~DH. .r&   zhttp://www.opengis.net/gmlzhttp://www.opengis.net/xlszhttp://www.opengis.net/xlsext)rS   Nr   r+   c                 >    g | ]}                     |           S )rb   )_parse_place)rP   placer+   r"   s     r%   
<listcomp>z(IGNFrance._parse_xml.<locals>.<listcomp>b  sF         !! + "    r&   )ET
fromstringencode_xml_to_json_placesrd   )r"   pagerS   r+   r-   treera   placess   `  `    r%   rC   zIGNFrance._parse_xmlA  s     }T[[1122	. 	. 	. 	;<<<;<<<>??? ))$:)FF 	4 	$$VAYK$HHH      &	   r&   c                    |sdnd}|                     d|z             }g }d}|D ]'}i }|                    d          |d<   |                    d          |d<   |                    d	          |d
<   |                    |                    d                    |d<   |                    |                    d                    |d<   |                    |                    d                    |d<   |                    |                    d                    |d<   |                    |                    d                    |d<   |                    |                    d                    |d<   |                    |                    d                    |d<   |                    |                    d                    |d<   |                    |                    d                    |d<   |                    |                    d                    |d<   |                    |                    d                    |d <   |                    |                    d!                    |d"<   |                    |                    d#                    |d$<   |                    |                    d%                    |d&<   |                    d'          |d(<   |                    d)          |d*<   i }	d+ }
 |
|                    d,          d-          |	d-<    |
|                    d,          d.          |	d/<    |
|                    d0          d1          |	d2<    |
|                    d3          d4          |	d5<   t          |                                          D ]\  }}||j        |	|<   d6|	|<   |	d         rM|	d                             d7          \  }}|                                |	d8<   |                                |	d9<   n
d6x|	d8<   |	d9<   |	                    dd6           |	                    |	           )|S ):zT
        Transform the xml ElementTree due to XML webservice return to json
        GeocodedAddressReverseGeocodedLocationz.//z.//Address/Place[@type="{}"]z./Point/posposz.//Address/StreetAddress/Streetstreetz.//Address/freeFormAddressfreeformaddressMunicipalitymunicipalityNumeronumeroFeuillefeuilleSectionsectionDepartementdepartementCommuneAbsorbeecommune_absorbeeCommunecommuneINSEEinseeQualitequalite
Territoire
territoireIDidID_TRid_trBboxbboxNaturenaturez.//Address/PostalCodepostal_codez.//ExtendedGeocodeMatchCodeextended_geocode_match_codec                 @    | | j                             |d          ndS )z
                Helper to select by attribute and if not attribute,
                value set to empty string
                N)attribget)selectorkeys     r%   testContentAttribz8IGNFrance._xml_to_json_places.<locals>.testContentAttrib  s6     )  **   044r&   z.//GeocodeMatchCodeaccuracy	matchType
match_typez!.//Address/StreetAddress/Buildingnumberbuildingz.//SearchCentreDistancevaluesearch_centre_distanceN latlng)
findallfindr?   rY   itemstextsplitr   popappend)r"   rl   rS   select_multiadressesrm   sel_pladrelre   r   r   r   r   r   s                  r%   rj   zIGNFrance._xml_to_json_placesi  s4    +* 	 << 455/ @	! @	!CB//BuI88$EFFBxL$'HH-I$J$JB !!$&--*G*G!H!HB~88FMM($;$;<<BxLHHV]]9%=%=>>ByMHHV]]9%=%=>>ByM #})E)E F FB}%(XXfmm<M.N.N%O%OB!"HHV]]9%=%=>>ByM((6==#9#9::BwKHHV]]9%=%=>>ByM"xxl(C(CDDB|xxd 3 344BtH((6==#9#9::BwK&--"7"788BvJ88FMM($;$;<<BxL #)@ A AB}03-1 1B,- E4 4 4 !2 1.//!= !=E* #4"3.//#> #>E, !2 1<==x!I !IE* /@.?233W/> />E*+ #288::.. & &
U$!&E#JJ!%E#JJ U| 3 <--c22S"yy{{e"yy{{e.22euU| IIeT"""MM%    r&   c                4    |                      |||d          S )z6
        Send the request to get raw content.
        F)r   is_json)_call_geocoder)r"   rG   rH   r   s       r%   rD   zIGNFrance._request_raw_content  s-     ""	 # 
 
 	
r&   c                     |dk    r|                     d          }n|                     d          r|                     d          }n|                     dd          d|                     dd          }|                     d          r|                     dd          d	|}|                     d
          r|                     d
d          d|}t          ||                     d          |                     d          f|          S )zP
        Get the location, lat, lng and place from a single json place.
        r6   rs   rw   rr   r   r8   r   r   z, r   r   r   )r   r   )r"   re   r+   locations       r%   rd   zIGNFrance._parse_place  s#   
 &  yy!233HH yy""  99X..
 IImR0000IIi,,, 99X&& 		(B////  H 99Z(( 		*b1111  H
 599U#3#3UYYu5E5E"FNNNr&   )N)FFT)F)rB   
__module____qualname____doc__r>   r    r   r   rI   rV   rC   rj   rD   rd   __classcell__)r$   s   @r%   r
   r
      sf        K  ,H VF $$( VF VF VF VF VF VF VFx ' $dI dI dI dI dIT (; $ZI ZI ZI ZI ZI| $$#	& & & &PQ Q Q Qf	
 	
 	
O O O O O O O Or&   r
   )r   xml.etree.ElementTreeetreeElementTreerg   	functoolsr   urllib.parser   	geopy.excr   geopy.geocoders.baser   r   geopy.locationr   
geopy.utilr	   __all__r
   rO   r&   r%   <module>r      s     " " " " " " " " "       " " " " " " ( ( ( ( ( ( ; ; ; ; ; ; ; ; # # # # # #      
VO VO VO VO VO VO VO VO VO VOr&   