
    .hB                         S SK r S SKJs  Jr  S SKJr  S SKJr  S SK	J
r
  S SKJrJr  S SKJr  S SKJr  Sr " S	 S
\5      rg)    N)partial)	urlencode)GeocoderQueryError)DEFAULT_SENTINELGeocoder)Location)logger)	IGNFrancec                      ^  \ rS rSrSrSrSr SSSSSS\\S\SS.
U 4S jjjrS	S
SSS\S.S jr	SS
SS\S.S jr
   SS jrSS jrS rSS jrSrU =r$ )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U ]  UUUU	U
US9  U(       d  U(       d  U(       d  U(       a  [        R                  " S[        SS9  UR                  S5      U l        U R                  nU R                  < SU R                  < U< 3U l	        g)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                lC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\geopy/geocoders/ignfrance.pyr   IGNFrance.__init__'   s    @ 	!#+ 	 	
 h(gMM4
 # ll3'=="&++t{{HE    StreetAddress   FT)
query_typemaximum_responsesis_freeform	filteringexactly_oner   c                   US;  a  [        S5      eUS:X  a(  [        UR                  5       5      S:w  a  [        S5      eSnU R                  R	                  SUUS9n	U(       a  S	nOS
nUc  SnU	R	                  UUUUS9n
SU
0nSR                  U R                  [        U5      45      n[        R                  " SU R                  R                  U5        [        U R                  XFS9nU R                  XUS9$ )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 CadastralParcelr2   r   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#   r:   r+   r,   r-   r.   r/   r   r6   r?   request_stringparamsurlcallbacks                 r&   geocodeIGNFrance.geocode   s6   Z  1 1 % &1 2 2
 **s5;;=/AR/G$ &G H H &&--0#/ . 
  K!K I %++#!	 , 
 >
 hh)F"345%t~~'>'>DOO
 (((HHr(   )r)   r9   )reverse_geocode_preferencer,   r.   r/   r   c                   SnU R                   R                  SUUS9nU H  n	U	S;  d  M  [        S5      e   U R                  US5      n
SR	                  S U 5       5      nUR                  UU
UUS	9nS
R	                  U R
                  [        SU05      45      n[        R                  " SU R                  R                  U5        [        U R                  USSS9nU R                  XUS9$ )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 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>
        ReverseGeocodeRequestr4   )r)   r1   z[`reverse_geocode_preference` must contain one or more of: StreetAddress, PositionOfInterestz%(lat)s %(lon)s
c              3   ,   #    U  H
  nS U-  v   M     g7f)z7<ReverseGeocodePreference>%s</ReverseGeocodePreference>N ).0prefs     r&   	<genexpr>$IGNFrance.reverse.<locals>.<genexpr>)  s"      /
 *  FL)s   )r,   r:   rL   r.   r<   r;   z%s.reverse: %sTr8   )r/   
is_reverser-   r=   )r?   r@   r   _coerce_point_to_stringrA   r"   r   r	   rB   r%   rC   r   rD   rE   )r#   r:   rL   r,   r.   r/   r   r6   r?   rS   pointrF   rH   rI   s                 r&   reverseIGNFrance.reverse   s   T
 &&--/#/ . 
 /DBB(H  / ,,U4EF%)YY /
 */
 &
" %++/'A	 , 
 hh)UN,C"DEF%t~~'>'>DOO#	
 (((HHr(   c                 6   [         R                  " UR                  S5      5      nS nU" US5        U" US5        U" US5        U R                  XRS9nU(       d  gU(       a  U R	                  US   US	9$ U Vs/ s H  nU R	                  UUS	9PM     sn$ s  snf )
zM
Returns location, (latitude, longitude) from XML feed
and transform to json
zutf-8c                     SU-  n[        U5      nU R                  5        H9  nUR                  R                  U5      (       d  M%  UR                  US Ul        M;     g)z*Remove namespace in the document in place.z{%s}N)r>   itertag
startswith)doc	namespacensnslelems        r&   remove_namespace.IGNFrance._parse_xml.<locals>.remove_namespaceN  sK    )#Bb'C
88&&r**#xx~DH #r(   zhttp://www.opengis.net/gmlzhttp://www.opengis.net/xlszhttp://www.opengis.net/xlsext)rV   Nr   )r-   )ET
fromstringencode_xml_to_json_places_parse_place)	r#   pagerV   r-   r/   treere   placesplaces	            r&   rD   IGNFrance._parse_xmlA  s     }}T[[12	. 	;<;<>? ))$)F$$VAYK$HH  &	  &e !! + "   &	  s   9Bc                 >   U(       d  SOSnUR                  SU-   5      n/ nSnU GHr  n0 nUR                  S5      US'   UR                  S5      US'   UR                  S	5      US
'   UR                  UR                  S5      5      US'   UR                  UR                  S5      5      US'   UR                  UR                  S5      5      US'   UR                  UR                  S5      5      US'   UR                  UR                  S5      5      US'   UR                  UR                  S5      5      US'   UR                  UR                  S5      5      US'   UR                  UR                  S5      5      US'   UR                  UR                  S5      5      US'   UR                  UR                  S5      5      US'   UR                  UR                  S5      5      US '   UR                  UR                  S!5      5      US"'   UR                  UR                  S#5      5      US$'   UR                  UR                  S%5      5      US&'   UR                  S'5      US('   UR                  S)5      US*'   0 n	S+ n
U
" UR                  S,5      S-5      U	S-'   U
" UR                  S,5      S.5      U	S/'   U
" UR                  S05      S15      U	S2'   U
" UR                  S35      S45      U	S5'   [        UR	                  5       5       H  u  pUb  UR
                  X'   M  S6X'   M     U	S   (       a=  U	S   R                  S75      u  pUR                  5       U	S8'   UR                  5       U	S9'   O
S6=U	S8'   U	S9'   U	R                  SS65        UR                  U	5        GMu     U$ ):zD
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                 D    U b  U R                   R                  US5      $ S$ )zO
Helper to select by attribute and if not attribute,
value set to empty string
N)attribget)selectorkeys     r&   testContentAttrib8IGNFrance._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@   r]   itemstextsplitr    popappend)r#   rm   rV   select_multiadressesrn   sel_pladrelro   r   r   r   r   r   s                  r&   rj   IGNFrance._xml_to_json_placesi  s[     * 	 << 45/CB/BuI88$EFBxL$'HH-I$JB !!$&--*G!HB~88FMM($;<BxLHHV]]9%=>ByMHHV]]9%=>ByM #})E FB}%(XXfmm<M.N%OB!"HHV]]9%=>ByM((6==#9:BwKHHV]]9%=>ByM"xxl(CDB|xxd 34BtH((6==#9:BwK&--"78BvJ88FMM($;<BxL #)@ AB}03-1B,- E4 !2./!=E* #4./#>E, !2<=x!IE* /@23W/>E*+ #288:.
$!&EJ!%EJ	 / U| <--c2"yy{e"yy{e.22euU| IIeT"MM% A D r(   c                &    U R                  UUUSS9$ )z&
Send the request to get raw content.
F)r   is_json)_call_geocoder)r#   rH   rI   r   s       r&   rE   IGNFrance._request_raw_content  s(     ""	 # 
 	
r(   c                    US:X  a  UR                  S5      nOUR                  S5      (       a  UR                  S5      nOUR                  SS5      < SUR                  SS5      < 3nUR                  S5      (       a  UR                  SS5      < S	U< 3nUR                  S
5      (       a  UR                  S
S5      < SU< 3n[        X1R                  S5      UR                  S5      4U5      $ )z@
Get the location, lat, lng and place from a single json place.
r7   rv   rz   ru   r   r9   r   r   z, r   r   r   )r   r   )r#   ro   r-   locations       r&   rk   IGNFrance._parse_place  s    
 & yy!23H yy"" 99X.
 IImR0IIi, 99X&&		(B/  H 99Z((		*b1  H
 99U#3UYYu5E"FNNr(   )r"   r   )N)FFT)F)rC   
__module____qualname____firstlineno____doc__r?   r!   r   r   rJ   rY   rD   rj   rE   rk   __static_attributes____classcell__)r%   s   @r&   r
   r
      s    K  ,H VF $$( VF VFx ' $dIT (; $ZI| $$#	&PQf	
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
   rQ   r(   r&   <module>r      s5     " "  " ( ; # 
VO VOr(   