
    Mh>                    8   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	r	SSK
Jr  SSK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Jr  \(       a  SSKJrJrJrJrJr  SSK J!r!  \" \S   \S   S-  S9 " S S5      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doc)is_list_like)isna)_shared_docs)
get_handle)get_data_from_filepathpreprocess_data)CompressionOptionsFilePath
ReadBufferStorageOptionsWriteBuffer)	DataFramestorage_optionscompression_optionspath_or_buffer)r   r   c                  ^   \ 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_options}

    .. versionchanged:: 1.4.0 Zstandard support.

{storage_options}

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)framer   index	root_namerow_namena_rep	attr_cols	elem_cols
namespacesprefixencodingxml_declarationpretty_print
stylesheetcompressionr   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                    G/var/www/html/env/lib/python3.13/site-packages/pandas/io/formats/xml.py__init___BaseXMLFormatter.__init__l   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   r7   s    r8   _build_tree_BaseXMLFormatter._build_tree   s     "$''r;   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    r8   r2   #_BaseXMLFormatter._validate_columns   s     >>,t~~">">'0011ST  >>,t~~">">'0011ST  #?>r;   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    r8   r3   $_BaseXMLFormatter._validate_encoding   s     	dmm$r;   c                \   U R                   nU R                  (       a  UR                  5       nU R                  bS  [        R
                  " 5          [        R                  " SS[        S9  UR                  U R                  5      nSSS5        UR                  SS9$ ! , (       d  f       N= f)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.
NignorezDowncasting object dtype arrays)categoryr    )orient)
r   r    reset_indexr#   warningscatch_warningsfilterwarningsFutureWarningfillnato_dict)r7   dfs     r8   r0   $_BaseXMLFormatter._process_dataframe   s     ZZ::!B;;"((*''5*
 YYt{{+ + zzz)) +*s   6B
B+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iterr1   keysr/   r$   r%   )r7   	first_keyxindexess       r8   r6   !_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    r8   r4   !_BaseXMLFormatter._get_prefix_uri   s     "$''r;   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&   itemsr5   )r7   	nmsp_dictpns       r8   _other_namespaces#_BaseXMLFormatter._other_namespaces  s|     %'	?? !OO1133DA"-- 5%QU!A30114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    [        SU 35      e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, )r$   _get_flat_col_namer   strattribKeyError)r7   delem_rowcol	attr_names        r8   _build_attribs _BaseXMLFormatter._build_attribs  s     ~~O>>C//4I:AF||14QVHOOI. $ "   :!23%899:s   ,A))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 )Nre   _)
isinstancetuplejoinrp   stripr5   )r7   ru   flat_colcs       r8   ro   $_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    r8   _sub_element_cls"_BaseXMLFormatter._sub_element_cls7  s    !$''r;   c                ,   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    [        SU 35      e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.
Nre   rn   )r   r%   ro   r   rp   textrr   )r7   rs   rt   sub_element_clsru   	elem_namevals          r8   _build_elems_BaseXMLFormatter._build_elems;  s     //~~>>C//4I:"16llafldAF<?49	 "
  :!23%899:s    5A::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)r7   xml_dochandless      r8   write_output_BaseXMLFormatter.write_outputP  s    ""$*## ,, $ 4 4 $$W-  >>$--07799  s   	B
B%)r$   r,   r%   r(   r   r1   r    r#   r&   r/   r   r'   r5   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(   rp   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   rp   )r   dict)rs   dict[str, Any]rt   r   r   r   )ru   zstr | tupler   rp   )rs   r   rt   r   r   r   )r   r   )rD   
__module____qualname____firstlineno____doc__r9   r?   r   r2   r3   r0   r6   r4   rk   rw   ro   r	   r   r   r   __static_attributes__ r;   r8   r   r   ,   s   
9| SW &$!&*&*37!'+$(LP*115#** P* 	*
 * * * $* $* 1* * * %* "* J*  (!*" /#*$ 
%*X(  * % % * *0 6 6*(  &  ( . . ( ( : :( : :r;   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)EtreeXMLFormatteric  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)rq   xml)methodr(   r)   zBTo use stylesheet, you need lxml installed and selected as parser.)xml.etree.ElementTreer   r   r   r5   r!   rk   rootr1   valuesr"   r$   r%   listrZ   r   rw   r(   r)   out_xmlr*   _prettify_treer+   
ValueErrorr7   r   r   r   rs   rt   s         r8   r?   EtreeXMLFormatter._build_treei  s-   	
 	
 /09O9O9Q
	 !!((*A!$))/@-PQH>>$..!%affh!!!.  ..q;!!!. +  II]] 00	
 ..0DL??&T  ||r;   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    [        U R                   S35      ef = f)Nr   )register_namespacere   {} is not included in namespaces)r   r   r&   rg   r{   rp   r'   rr   )r7   r   uriri   rj   s        r8   r4   !EtreeXMLFormatter._get_prefix_uri  s    <??--/a%%*Q*<*<&q, 0 {{Stt{{;<B?C 
 t&4??2./r2 
 
   S"dkk]2P#QRRSs   C #C0c                    SSK Jn  U$ Nr   )r   )r   r   r7   r   s     r8   r   "EtreeXMLFormatter._sub_element_cls  s    4r;   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(   )r7   r   doms      r8   r    EtreeXMLFormatter._prettify_tree  s,     	0$,,'dT]]CCr;   r%   r   r   Nr   r   )rD   r   r   r   r   r?   r4   r	   r   r   r   r   r;   r8   r   r   c  s,    
%N(  
Dr;   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   )superr9   _convert_empty_str_key)r7   argskwargs	__class__s      r8   r9   LxmlXMLFormatter.__init__  s!    $)&)##%r;   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(                  $ )r=   r   r   )nsmapr   )r*   r   r(   r)   )
lxml.etreer   r   r   r5   r!   r&   r   r1   r   r"   r$   r%   r   rZ   r   rw   r*   r(   r)   r   r+   _transform_docr   s         r8   r?   LxmlXMLFormatter._build_tree  s   	
 	
 t//?@X	!!((*A!$))/@-PQH>>$..!%affh!!!.  ..q;!!!. +  II**]] 00
 ??&..0DL||r;   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.
re   defaultN)r&   rZ   popr>   s    r8   r   'LxmlXMLFormatter._convert_empty_str_key  sE     ??rT__%9%9%;;$(OO$7$7I$FDOOD!  <?r;   c                (   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    [        U R                   S35      ef = f)Nre   r   r   r   )r&   r'   rr   )r7   r   s     r8   r4    LxmlXMLFormatter._get_prefix_uri  s    ??{{Stt{{;<B?C 
 t&4??2./r2 
 
   S"dkk]2P#QRRSs   A. .#Bc                    SSK Jn  U$ r   )r   r   r   s     r8   r   !LxmlXMLFormatter._sub_element_cls  s    )r;   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5       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   r   r{   ioStringIOgetvalueencoder   r   )r7   r   r   r   r   	style_dochandle_dataxml_datacurr_parserxsl_doctransformernew_docs               r8   r   LxmlXMLFormatter._transform_doc
  s    	
 	
 OO	$$$,(]](( 00	
 [)X#T]];K(BKK00$%%'..t}}=k  = * 7mdii(W~ *)s   A%C%%
C3r   r   r   r   )rD   r   r   r   r   r9   r?   r   r4   r	   r   r   r   __classcell__)r   s   @r8   r   r     s<    
&
%N	G  
& &r;   r   )%r   
__future__r   rG   r   typingr   r   r   rO   pandas.errorsr   pandas.util._decoratorsr	   r
   pandas.core.dtypes.commonr   pandas.core.dtypes.missingr   pandas.core.shared_docsr   pandas.io.commonr   pandas.io.xmlr   r   pandas._typingr   r   r   r   r   pandasr   r   r   r   r   r;   r8   <module>r     s    #  	 
  -
 3 + 0 '
   !  !23$%:;>NNp: p:	p:f	RD) RDjx( xr;   