
    A>iC                        S r SSKJr  SSKrSSKrSSKJrJrJr  SSK	J
r
  SSKJr  SSKJr  SSKJr  SS	KJr  SS
KJr  \(       a  SSKJrJrJrJrJr  SSKJr   " S S5      r " S S\5      r " S S\5      rg)zF
:mod:`pandas.io.formats.xml` is a module for formatting data in XML.
    )annotationsN)TYPE_CHECKINGAnyfinalAbstractMethodError)cache_readonly)is_list_like)isna)
get_handle)get_data_from_filepath)CompressionOptionsFilePath
ReadBufferStorageOptionsWriteBuffer)	DataFramec                  ^   \ rS rSrSr               S                                 SS jjrSS jr\SS j5       r\SS j5       r	\SS j5       r
\SS	 j5       rSS
 jr\SS j5       r\SS j5       r\SS j5       r\S 5       r\SS j5       r\SS j5       rSrg)_BaseXMLFormatter$   a
  
Subclass for formatting data in XML.

Parameters
----------
path_or_buffer : str or file-like
    This can be either a string of raw XML, a valid URL,
    file or file-like object.

index : bool
    Whether to include index in xml document.

row_name : str
    Name for root of xml document. Default is 'data'.

root_name : str
    Name for row elements of xml document. Default is 'row'.

na_rep : str
    Missing data representation.

attrs_cols : list
    List of columns to write as attributes in row element.

elem_cols : list
    List of columns to write as children in row element.

namespaces : dict
    The namespaces to define in XML document as dicts with key
    being namespace and value the URI.

prefix : str
    The prefix for each element in XML document including root.

encoding : str
    Encoding of xml object or document.

xml_declaration : bool
    Whether to include xml declaration at top line item in xml.

pretty_print : bool
    Whether to write xml document with line breaks and indentation.

stylesheet : str or file-like
    A URL, file, file-like object, or a raw string containing XSLT.

compression : str or dict, default 'infer'
    For on-the-fly compression of the output data. If 'infer' and 'path_or_buffer'
    is path-like, then detect compression from the following extensions: '.gz',
    '.bz2', '.zip', '.xz', '.zst', '.tar', '.tar.gz', '.tar.xz' or '.tar.bz2'
    (otherwise no compression).
    Set to ``None`` for no compression.
    Can also be a dict with key ``'method'`` set
    to one of {``'zip'``, ``'gzip'``, ``'bz2'``, ``'zstd'``, ``'xz'``, ``'tar'``}
    and other key-value pairs are forwarded to
    ``zipfile.ZipFile``, ``gzip.GzipFile``,
    ``bz2.BZ2File``, ``zstandard.ZstdCompressor``, ``lzma.LZMAFile`` or
    ``tarfile.TarFile``, respectively.
    As an example, the following could be passed for faster compression and to
    create a reproducible gzip archive:
    ``compression={'method': 'gzip', 'compresslevel': 1, 'mtime': 1}``.

storage_options : dict, optional
    Extra options that make sense for a particular storage connection, e.g.
    host, port, username, password, etc. For HTTP(S) URLs the key-value pairs
    are forwarded to ``urllib.request.Request`` as header options. For other
    URLs (e.g. starting with "s3://", and "gcs://") the key-value pairs are
    forwarded to ``fsspec.open``. Please see ``fsspec`` and ``urllib`` for more
    details, and for more examples on storage options refer `here
    <https://pandas.pydata.org/docs/user_guide/io.html?
    highlight=storage_options#reading-writing-remote-files>`_.

See also
--------
pandas.io.formats.xml.EtreeXMLFormatter
pandas.io.formats.xml.LxmlXMLFormatter

Nc                   Xl         X l        X0l        X@l        XPl        X`l        Xpl        Xl        Xl        Xl	        Xl
        Xl        Xl        Xl        Xl        UU l        U R                   R                   R#                  5       U l        U R'                  5       U l        U R+                  5         U R-                  5         U R/                  5       U l        U R3                  5         g N)framepath_or_bufferindex	root_namerow_namena_rep	attr_cols	elem_cols
namespacesprefixencodingxml_declarationpretty_print
stylesheetcompressionstorage_optionscolumnstolist	orig_cols_process_dataframeframe_dicts_validate_columns_validate_encoding_get_prefix_uri
prefix_uri_handle_indexes)selfr   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   s                    T/var/www/html/land-tabula/venv/lib/python3.13/site-packages/pandas/io/formats/xml.py__init___BaseXMLFormatter.__init__t   s    & 
,
" ""$ .($/:.++224224 !..0    c                    [        U 5      e)w
Build tree from  data.

This method initializes the root and builds attributes and elements
with optional namespaces.
r   r3   s    r4   _build_tree_BaseXMLFormatter._build_tree   s     "$''r7   c                ^   U R                   (       aE  [        U R                   5      (       d+  [        [        U R                   5      R                   S35      eU R
                  (       aF  [        U R
                  5      (       d+  [        [        U R
                  5      R                   S35      egg)z
Validate elems_cols and attrs_cols.

This method will check if columns is list-like.

Raises
------
ValueError
    * If value is not a list and less then length of nodes.
z" is not a valid type for attr_colsz" is not a valid type for elem_colsN)r   r
   	TypeErrortype__name__r    r:   s    r4   r.   #_BaseXMLFormatter._validate_columns   s     >>,t~~">">'0011ST  >>,t~~">">'0011ST  #?>r7   c                D    [         R                  " U R                  5        g)z
Validate encoding.

This method will check if encoding is among listed under codecs.

Raises
------
LookupError
    * If encoding is not available in codecs.
N)codecslookupr#   r:   s    r4   r/   $_BaseXMLFormatter._validate_encoding   s     	dmm$r7   c                    U R                   nU R                  (       a  UR                  5       nU R                  b  UR	                  U R                  5      nUR                  SS9$ )z
Adjust Data Frame to fit xml output.

This method will adjust underlying data frame for xml output,
including optionally replacing missing values and including indexes.
r   )orient)r   r   reset_indexr   fillnato_dict)r3   dfs     r4   r,   $_BaseXMLFormatter._process_dataframe   sM     ZZ::!B;;"4;;'Bzzz))r7   c                |   U R                   (       d  g[        [        U R                  5      5      nU R                  U   R	                  5        Vs/ s H  o"U R
                  ;  d  M  UPM     nnU R                  (       a  X0R                  -   U l        U R                  (       a  X0R                  -   U l        ggs  snf )zL
Handle indexes.

This method will add indexes into attr_cols or elem_cols.
N)r   nextiterr-   keysr+   r   r    )r3   	first_keyxindexess       r4   r2   !_BaseXMLFormatter._handle_indexes   s     zzd../0	''	2779
9!dnn=TA9 	 
 >>$~~5DN>>$~~5DN 
s   B9'B9c                    [        U 5      e)z
Get uri of namespace prefix.

This method retrieves corresponding URI to prefix in namespaces.

Raises
------
KeyError
    *If prefix is not included in namespace dict.
r   r:   s    r4   r0   !_BaseXMLFormatter._get_prefix_uri   s     "$''r7   c                    0 nU R                   (       aQ  U R                   R                  5        VVs0 s H*  u  p#X0R                  SS :w  d  M  SUS:X  a  UOSU 3 3U_M,     nnnU$ s  snnf )z
Define other namespaces.

This method will build dictionary of namespaces attributes
for root element, conditionally with optional namespaces and
prefix.
   xmlns :)r!   itemsr1   )r3   	nmsp_dictpns       r4   _other_namespaces#_BaseXMLFormatter._other_namespaces  s|     %'	?? !OO1133DA"-- 7%Q"WAaS'23Q63   s   A'A'c                   U R                   (       d  U$ U R                    HC  nU R                  U5      n [        X   5      (       d  [        X   5      UR                  U'   MC  ME     U$ ! [
         a  n[        SU 35      UeSnAff = f)z
Create attributes of row.

This method adds attributes using attr_cols to row element and
works with tuples for multindex or hierarchical columns.
no valid column, N)r   _get_flat_col_namer   strattribKeyError)r3   delem_rowcol	attr_nameerrs         r4   _build_attribs _BaseXMLFormatter._build_attribs  s     ~~O>>C//4ICAF||14QVHOOI. $ "   C!23%89sBCs   ,A))
B3BBc                T   Un[        U[        5      (       ax  SU;   a9  SR                  U Vs/ s H  n[        U5      PM     sn5      R	                  5       O8SR                  U Vs/ s H  n[        U5      PM     sn5      R	                  5       nU R
                   U 3$ s  snf s  snf )Nr[   _)
isinstancetuplejoinrf   stripr1   )r3   rk   flat_colcs       r4   re   $_BaseXMLFormatter._get_flat_col_name.  s    c5!! 9 -AQ-.446XXs3s!s1vs34::< 
 //"8*--	 .3s   B &B%c                    [        U 5      er   r   r:   s    r4   _sub_element_cls"_BaseXMLFormatter._sub_element_cls9  s    !$''r7   c                6   U R                   nU R                  (       d  gU R                   HJ  nU R                  U5      n [        X   5      (       d  X   S:X  a  SO[	        X   5      nXc" X%5      l        ML     g! [         a  n[        SU 35      UeSnAff = f)z
Create child elements of row.

This method adds child elements using elem_cols to row element and
works with tuples for multindex or hierarchical columns.
Nr[   rd   )rz   r    re   r   rf   textrh   )r3   ri   rj   sub_element_clsrk   	elem_namevalrm   s           r4   _build_elems_BaseXMLFormatter._build_elems=  s     //~~>>C//4IC"16llafldAF<?49	 "
  C!23%89sBCs    5A::
BBBc                P   U R                  5       nU R                  bP  [        U R                  SU R                  U R                  SS9 nUR
                  R                  U5        S S S 5        g UR                  U R                  5      R                  5       $ ! , (       d  f       g = f)NwbF)r'   r(   is_text)
r;   r   r   r'   r(   handlewritedecoder#   rstrip)r3   xml_dochandless      r4   write_output_BaseXMLFormatter.write_outputR  s    ""$*## ,, $ 4 4 $$W-  >>$--07799  s   	B
B%)r   r'   r    r#   r   r-   r   r   r!   r+   r   r"   r1   r%   r   r   r(   r&   r$   )NTdatarowNNNNNzutf-8TTNinferN)"r   r   r   z7FilePath | WriteBuffer[bytes] | WriteBuffer[str] | Noner   boolr   
str | Noner   r   r   r   r   list[str] | Noner    r   r!   zdict[str | None, str] | Noner"   r   r#   rf   r$   bool | Noner%   r   r&   z5FilePath | ReadBuffer[str] | ReadBuffer[bytes] | Noner'   r   r(   zStorageOptions | NonereturnNoner   bytesr   r   )r   zdict[int | str, dict[str, Any]]r   rf   )r   dict)ri   dict[str, Any]rj   r   r   r   )rk   zstr | tupler   rf   )ri   r   rj   r   r   r   )r   r   )r@   
__module____qualname____firstlineno____doc__r5   r;   r   r.   r/   r,   r2   r0   ra   rn   re   r	   rz   r   r   __static_attributes__ r7   r4   r   r   $   s   Md SW &$!&*&*37!'+$(LP*115#** P* 	*
 * * * $* $* 1* * * %* "* J*  (!*" /#*$ 
%*X(  * % % * *$ 6 6*(  &  ( . . ( ( C C( : :r7   r   c                  F    \ rS rSrSrS	S jrS
S jr\S 5       rS	S jr	Sr
g)EtreeXMLFormatterie  x
Class for formatting data in xml using Python standard library
modules: `xml.etree.ElementTree` and `xml.dom.minidom`.
c                   SSK JnJnJn  U" U R                   U R
                   3U R                  5       S9U l        U R                  R                  5        H  nU" U R                  U R                   U R                   35      nU R                  (       dB  U R                  (       d1  [        UR                  5       5      U l        U R                  XE5        M  U R!                  XE5      nU R                  XE5        M     U" U R                  SU R"                  U R$                  S9U l        U R(                  (       a  U R+                  5       U l        U R,                  b  [/        S5      eU R&                  $ )Nr   Element
SubElementtostring)rg   xml)methodr#   r$   zBTo use stylesheet, you need lxml installed and selected as parser.)xml.etree.ElementTreer   r   r   r1   r   ra   rootr-   valuesr   r   r    listrP   r   rn   r#   r$   out_xmlr%   _prettify_treer&   
ValueErrorr3   r   r   r   ri   rj   s         r4   r;   EtreeXMLFormatter._build_treek  s-   	
 	
 /09O9O9Q
	 !!((*A!$))/@-PQH>>$..!%affh!!!.  ..q;!!!. +  II]] 00	
 ..0DL??&T  ||r7   c                   SSK Jn  SnU R                  (       a  U R                  R                  5        H;  u  p4[	        U[
        5      (       d  M  [	        U[
        5      (       d  M3  U" X45        M=     U R                  (       a    SU R                  U R                      S3nU$ SU R                  ;   a  SU R                  S    S3nU$ SnU$ ! [         a  n[        U R                   S35      UeS nAff = f)Nr   )register_namespacer[   {} is not included in namespaces)r   r   r!   r]   rr   rf   r"   rh   )r3   r   urir_   r`   rm   s         r4   r0   !EtreeXMLFormatter._get_prefix_uri  s    <??--/a%%*Q*<*<&q, 0 {{tt{{;<B?C 
 t&4??2./r2 
 
   ";;-'EFs   C 
C5C00C5c                    SSK Jn  U$ Nr   )r   )r   r   r3   r   s     r4   rz   "EtreeXMLFormatter._sub_element_cls  s    4r7   c                f    SSK Jn  U" U R                  5      nUR                  SU R                  S9$ )zk
Output tree for pretty print format.

This method will pretty print xml with line breaks and indentation.
r   )parseStringz  )indentr#   )xml.dom.minidomr   r   toprettyxmlr#   )r3   r   doms      r4   r    EtreeXMLFormatter._prettify_tree  s,     	0$,,'dT]]CCr7   r    r   r   Nr   r   )r@   r   r   r   r   r;   r0   r	   rz   r   r   r   r7   r4   r   r   e  s,    
%N,  
Dr7   r   c                  h   ^  \ rS rSrSrS
U 4S jjrSS jrS
S jrSS jr\	S 5       r
SS jrS	rU =r$ )LxmlXMLFormatteri  r   c                F   > [         TU ]  " U0 UD6  U R                  5         g r   )superr5   _convert_empty_str_key)r3   argskwargs	__class__s      r4   r5   LxmlXMLFormatter.__init__  s!    $)&)##%r7   c                   SSK JnJnJn  U" U R                   U R
                   3U R                  S9U l        U R                  R                  5        H  nU" U R                  U R                   U R                   35      nU R                  (       dB  U R                  (       d1  [        UR                  5       5      U l        U R                  XE5        M  U R!                  XE5      nU R                  XE5        M     U" U R                  U R"                  SU R$                  U R&                  S9U l        U R*                  b  U R-                  5       U l        U R(                  $ )r9   r   r   )nsmapr   )r%   r   r#   r$   )
lxml.etreer   r   r   r1   r   r!   r   r-   r   r   r   r    r   rP   r   rn   r%   r#   r$   r   r&   _transform_docr   s         r4   r;   LxmlXMLFormatter._build_tree  s   	
 	
 t//?@X	!!((*A!$))/@-PQH>>$..!%affh!!!.  ..q;!!!. +  II**]] 00
 ??&..0DL||r7   c                    U R                   (       aI  SU R                   R                  5       ;   a*  U R                   R                  SS5      U R                   S'   ggg)z
Replace zero-length string in `namespaces`.

This method will replace '' with None to align to `lxml`
requirement that empty string prefixes are not allowed.
r[   defaultN)r!   rP   popr:   s    r4   r   'LxmlXMLFormatter._convert_empty_str_key  sE     ??rT__%9%9%;;$(OO$7$7I$FDOOD!  <?r7   c                2   SnU R                   (       aX  U R                  (       a    SU R                   U R                      S3nU$ SU R                   ;   a  SU R                   S    S3nU$ SnU$ ! [         a  n[        U R                   S35      UeS nAff = f)Nr[   r   r   r   )r!   r"   rh   )r3   r   rm   s      r4   r0    LxmlXMLFormatter._get_prefix_uri  s    ??{{tt{{;<B?C 
 t&4??2./r2 
 
   ";;-'EFs   A. .
B8BBc                    SSK Jn  U$ r   )r   r   r   s     r4   rz   !LxmlXMLFormatter._sub_element_cls
  s    )r7   c                   SSK JnJnJnJn  U R
                  nUc   e[        UU R                  U R                  U R                  S9nU nU" U R                  S9n[        U[        R                  5      (       a/  U" UR                  5       R                  U R                  5      US9n	OU" XxS9n	SSS5        U" W	5      n
U
" U R                  5      n[!        U5      $ ! , (       d  f       N3= f)z
Parse stylesheet from file or buffer and run it.

This method will parse stylesheet object into tree for parsing
conditionally by its specific object type, then transforms
original tree with XSLT script.
r   )XSLT	XMLParser
fromstringparseN)filepath_or_bufferr#   r'   r(   )r#   )parser)r   r   r   r   r   r&   r   r#   r'   r(   rr   ioStringIOgetvalueencoder   r   )r3   r   r   r   r   	style_dochandle_dataxml_datacurr_parserxsl_doctransformernew_docs               r4   r   LxmlXMLFormatter._transform_doc  s    	
 	
 OO	$$$,(]](( 00	
 H#T]];K(BKK00$%%'..t}}=k  =  7mdii(W~ [s   
A%C
C*r   r   r   r   )r@   r   r   r   r   r5   r;   r   r0   r	   rz   r   r   __classcell__)r   s   @r4   r   r     s<    
&
%N	G"  
& &r7   r   ) r   
__future__r   rC   r   typingr   r   r   pandas.errorsr   pandas.util._decoratorsr	   pandas.core.dtypes.commonr
   pandas.core.dtypes.missingr   pandas.io.commonr   pandas.io.xmlr   pandas._typingr   r   r   r   r   pandasr   r   r   r   r   r7   r4   <module>r      ss    #  	  . 2 2 + ' 0  !~: ~:B
TD) TDnz( zr7   