Ë
    Ï.fºB  ã                   ó„   — 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y)é    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
   z‰Geocoder 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¬«       |j                  d«      | _        | j                  }| j                  ›d| j                  ›|›�| _	        y)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   zïIGNFrance 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                €úXC:\Users\user\Documents\project_loop\venv\Lib\site-packages\geopy/geocoders/ignfrance.pyr   zIGNFrance.__init__'   s   ø€ ô@ 	‰ÑØØØØ!Ø#Ø+ð 	ô 	
ñ ‘h¡(©gÜ�M‰Mð4ô
 #Øõð —l‘l 3Ó'ˆŒØ—=‘=ˆØ"&§+£+¨t¯{ª{¹HÐEˆ�ó    ÚStreetAddressé   FT)Ú
query_typeÚmaximum_responsesÚis_freeformÚ	filteringÚexactly_oner   c                óú  — |dvrt        d«      ‚|dk(  r't        |j                  «       «      dk7  rt        d«      ‚d}| j                  j	                  d||¬«      }	|rd	}nd
}|€d}|	j	                  ||||¬«      }
d|
i}dj                  | j                  t        |«      f«      }t        j                  d| j                  j                  |«       t        | j                  ||¬«      }| 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'   ÚCadastralParcelz˜You 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ÚfalseÚ )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   s:  € ðZ ð 1ñ 1ô %ð &1ó 2ð 2ð
 Ð*Ò*¬s°5·;±;³=Ó/AÀRÒ/GÜ$ð &Gó Hð Hðˆð ×&Ñ&×-Ñ-Ø0Ø#Ø/ð .ó 
ˆñ Ø ‰Kà!ˆKð ÐØˆIð %×+Ñ+Ø#ØØ!Øð	 ,ó 
ˆð �>ð
ˆð �h‰h˜Ÿ™¤)¨FÓ"3Ð4Ó5ˆä�‰Ð% t§~¡~×'>Ñ'>ÀÔDÜØ�O‰O¨À+ô
ˆð ×(Ñ(¨¨hÀÐ(ÓHÐHr&   )r'   r8   )Úreverse_geocode_preferencer*   r,   r-   r   c                óì  — d}| j                   j                  d||¬«      }|D ]  }	|	dvsŒt        d«      ‚ | j                  |d«      }
dj	                  d„ |D «       «      }|j                  ||
||¬	«      }d
j	                  | j
                  t        d|i«      f«      }t        j                  d| j                  j                  |«       t        | j                  |dd¬«      }| j                  |||¬«      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  –— Œ y­w)z7<ReverseGeocodePreference>%s</ReverseGeocodePreference>N© )Ú.0Úprefs     r%   ú	<genexpr>z$IGNFrance.reverse.<locals>.<genexpr>)  s   è ø€ ò /
àð FÈÕLñ/
ùs   ‚)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Ü(ðHóð ð	ð ×,Ñ,¨UÐ4EÓFˆØ%)§Y¡Yñ /
ð *ô/
ó &
Ð"ð %×+Ñ+Ø/ØØ'AØð	 ,ó 
ˆð �h‰h˜Ÿ™¤)¨U°NÐ,CÓ"DÐEÓFˆä�‰Ð% t§~¡~×'>Ñ'>ÀÔDÜØ�O‰OØ#ØØô	
ˆð ×(Ñ(¨¨hÀÐ(ÓHÐHr&   c                 ó.  — t        j                  |j                  d«      «      }d„ } ||d«        ||d«        ||d«       | j                  ||¬«      }|sy|r| j	                  |d   |¬	«      S |D �cg c]  }| j	                  ||¬	«      ‘Œ c}S c c}w )
ze
        Returns location, (latitude, longitude) from XML feed
        and transform to json
        zutf-8c                 ó®   — d|z  }t        |«      }| j                  «       D ]2  }|j                  j                  |«      sŒ|j                  |d |_        Œ4 y)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  sM   € à˜)Ñ#ˆBÜ�b“'ˆCØŸ™›
ò .�Ø—8‘8×&Ñ& rÕ*Ø#Ÿx™x¨¨˜~�D•Hñ.r&   zhttp://www.opengis.net/gmlzhttp://www.opengis.net/xlszhttp://www.opengis.net/xlsext)rS   Nr   )r+   )ÚETÚ
fromstringÚencodeÚ_xml_to_json_placesÚ_parse_place)	r"   ÚpagerS   r+   r-   Útreera   ÚplacesÚplaces	            r%   rC   zIGNFrance._parse_xmlA  s·   € ô �}‰}˜TŸ[™[¨Ó1Ó2ˆò	.ñ 	˜Ð;Ô<Ù˜Ð;Ô<Ù˜Ð>Ô?ð ×)Ñ)¨$¸:Ð)ÓFˆáØÙØ×$Ñ$ V¨A¡Y¸KÐ$ÓHÐHð  &ö	ð ð ×!Ñ!ØØ +ð "õ òð ùò s   Á5Bc                 ó&  — |sdnd}|j                  d|z   «      }g }d}|D �]l  }i }|j                  d«      |d<   |j                  d«      |d<   |j                  d	«      |d
<   |j                  |j                  d«      «      |d<   |j                  |j                  d«      «      |d<   |j                  |j                  d«      «      |d<   |j                  |j                  d«      «      |d<   |j                  |j                  d«      «      |d<   |j                  |j                  d«      «      |d<   |j                  |j                  d«      «      |d<   |j                  |j                  d«      «      |d<   |j                  |j                  d«      «      |d<   |j                  |j                  d«      «      |d<   |j                  |j                  d«      «      |d <   |j                  |j                  d!«      «      |d"<   |j                  |j                  d#«      «      |d$<   |j                  |j                  d%«      «      |d&<   |j                  d'«      |d(<   |j                  d)«      |d*<   i }	d+„ }
 |
|j                  d,«      d-«      |	d-<    |
|j                  d,«      d.«      |	d/<    |
|j                  d0«      d1«      |	d2<    |
|j                  d3«      d4«      |	d5<   t        |j	                  «       «      D ]  \  }}|�|j
                  |	|<   Œd6|	|<   Œ |	d   r>|	d   j                  d7«      \  }}|j                  «       |	d8<   |j                  «       |	d9<   n
d6x|	d8<   |	d9<   |	j                  dd6«       |j                  |	«       �Œo |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                 óB   — | �| j                   j                  |d«      S 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’  s3   € ð Ð)ð  —‘×*Ñ*ØØóð 4ð 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"   rh   rS   Úselect_multiÚadressesri   Úsel_plÚadrÚelrj   r”   r“   rš   r�   rž   s                  r%   re   zIGNFrance._xml_to_json_placesi  so  € ñ ñ à*ð 	ð —<‘< ¨Ñ 4Ó5ˆØˆà/ˆØó @	!ˆCØˆBØŸ™ Ó/ˆBˆu‰IØŸ8™8Ð$EÓFˆBˆx‰LØ$'§H¡HÐ-IÓ$JˆBÐ Ñ!Ø!$§¡¨&¯-©-¸Ó*GÓ!HˆBˆ~ÑØŸ8™8 F§M¡M°(Ó$;Ó<ˆBˆx‰LØŸH™H V§]¡]°9Ó%=Ó>ˆBˆy‰MØŸH™H V§]¡]°9Ó%=Ó>ˆBˆy‰MØ #§¡¨¯©°}Ó)EÓ FˆBˆ}ÑØ%(§X¡X¨f¯m©mÐ<MÓ.NÓ%OˆBÐ!Ñ"ØŸH™H V§]¡]°9Ó%=Ó>ˆBˆy‰MØŸ(™( 6§=¡=°Ó#9Ó:ˆBˆw‰KØŸH™H V§]¡]°9Ó%=Ó>ˆBˆy‰MØ"Ÿx™x¨¯©°lÓ(CÓDˆBˆ|ÑØ—x‘x §¡¨dÓ 3Ó4ˆBˆt‰HØŸ(™( 6§=¡=°Ó#9Ó:ˆBˆw‰KØŸ™ &§-¡-°Ó"7Ó8ˆBˆv‰JØŸ8™8 F§M¡M°(Ó$;Ó<ˆBˆx‰LØ #§¡Ð)@Ó AˆBˆ}ÑØ03·±Ø-ó1ˆBÐ,Ñ-ð ˆEò4ñ !2Ø—‘Ð.Ó/°ó!=ˆE�*Ññ #4Ø—‘Ð.Ó/°ó#>ˆE�,Ññ !2Ø—‘Ð<Ó=¸xó!IˆE�*Ññ /@Ø—‘Ð2Ó3°Wó/>ˆEÐ*Ñ+ô # 2§8¡8£:Ó.ò &‘
��UØÐ$Ø!&§¡�E˜#’Jà!%�E˜#’Jð	&ð �UŠ|Ø  ™<×-Ñ-¨cÓ2‘��SØ"Ÿy™y›{��e‘Ø"Ÿy™y›{��e’à.2Ð2��e‘˜u U™|ð �I‰I�e˜TÔ"Ø�M‰M˜%Ö ðA@	!ðD ˆr&   c                ó,   — | j                  |||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|j                  d«      }nš|j                  d«      r|j                  d«      }nw|j                  dd«      ›d|j                  dd«      ›�}|j                  d«      r|j                  dd«      ›d	|›�}|j                  d
«      r|j                  d
d«      ›d|›�}t        ||j                  d«      |j                  d«      f|«      S )zP
        Get the location, lat, lng and place from a single json place.
        r6   rp   rt   ro   r�   r8   rœ   r~   z, r™   r�   rž   )r‘   r   )r"   rj   r+   Úlocations       r%   rf   zIGNFrance._parse_placeÇ  sÐ   € ð
 ˜&Ò Ø—y‘yÐ!2Ó3‰Hð �y‰y˜Ô"Ø Ÿ9™9 XÓ.‘ð
 —I‘I˜m¨RÕ0Ø—I‘I˜i¨Ô,ð�ð —9‘9˜XÔ&àŸ	™	 (¨BÕ/Ù ð �Hð —9‘9˜ZÔ(àŸ	™	 *¨bÕ1Ù ð �Hô
 ˜ 5§9¡9¨UÓ#3°U·Y±Y¸uÓ5EÐ"FÈÓNÐNr&   )N)FFT)F)rB   Ú
__module__Ú__qualname__Ú__doc__r>   r    r   r   rI   rV   rC   re   rD   rf   Ú__classcell__)r$   s   @r%   r
   r
      s¢   ø„ ñð€Kð  ,€Hð ðVFð ØØØØØ$Ø$ØØ(Ø öVFðx 'Ø ØØØØ$ôdIðT (;Ø ØØØ$ôZIð| $Ø$Ø#ó	&óPQòf	
÷Or&   r
   )r   Úxml.etree.ElementTreeÚetreeÚElementTreerb   Ú	functoolsr   Úurllib.parser   Ú	geopy.excr   Úgeopy.geocoders.baser   r   Úgeopy.locationr   Ú
geopy.utilr	   Ú__all__r
   rO   r&   r%   ú<module>r¾      s5   ðÛ ß "Ð "Ý Ý "å (ß ;Ý #Ý à
€ôVO�õ VOr&   