gL i>4dZddlmZddlZddlZddlmZmZmZddl Z ddl m Z ddl m Z mZddlmZddlmZdd lmZdd lmZdd lmZmZerdd lmZmZmZmZmZdd l m!Z!eededdzGddZ"Gdde"Z#Gdde"Z$y)zF :mod:`pandas.io.formats.xml` is a module for formatting data in XML. ) annotationsN) TYPE_CHECKINGAnyfinalAbstractMethodError)cache_readonlydoc) is_list_like)isna) _shared_docs) get_handle)get_data_from_filepathpreprocess_data)CompressionOptionsFilePath ReadBufferStorageOptions WriteBuffer) DataFramestorage_optionscompression_optionspath_or_buffer)rrc<eZdZdZ d ddZddZeddZeddZeddZ eddZ dd Z edd Z edd Z edd Zed ZeddZeddZy)_BaseXMLFormattera 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||_||_||_||_||_||_||_||_| |_| |_ | |_ | |_ | |_ ||_ ||_||_|jj j#|_|j'|_|j+|j-|j/|_|j3yN)framerindex root_namerow_namena_rep attr_cols elem_cols namespacesprefixencodingxml_declaration pretty_print stylesheet compressionrcolumnstolist orig_cols_process_dataframe frame_dicts_validate_columns_validate_encoding_get_prefix_uri prefix_uri_handle_indexes)selfrrrr r!r"r#r$r%r&r'r(r)r*r+rs [/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/pandas/io/formats/xml.py__init__z_BaseXMLFormatter.__init__ls& , "   ""$   .($/:.++224224   !..0 ct|) Build tree from data. This method initializes the root and builds attributes and elements with optional namespaces. rr6s r7 _build_treez_BaseXMLFormatter._build_trees"$''r9c6|jr@t|js+tt|jjd|j rAt|j s+tt|j jdyy)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 TypeErrortype__name__r$r<s r7r1z#_BaseXMLFormatter._validate_columnss >>,t~~">'0011ST  >>,t~~">'0011ST #?>r9cBtj|jy)z Validate encoding. This method will check if encoding is among listed under codecs. Raises ------ LookupError * If encoding is not available in codecs. N)codecslookupr'r<s r7r2z$_BaseXMLFormatter._validate_encodings  dmm$r9cN|j}|jr|j}|jTt j 5t j ddt|j|j}ddd|jdS#1swYxYw)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. NignorezDowncasting object dtype arrays)categoryr)orient) rr reset_indexr"warningscatch_warningsfilterwarnings FutureWarningfillnato_dict)r6dfs r7r/z$_BaseXMLFormatter._process_dataframesZZ ::!B ;; "((* ,''5* YYt{{+  ,zzz)) , ,s 8BB$cX|jsytt|j}|j|j Dcgc]}||j vs|}}|j r||j z|_|jr||jz|_yycc}w)zd Handle indexes. This method will add indexes into attr_cols or elem_cols. N)rnextiterr0keysr.r#r$)r6 first_keyxindexess r7r5z!_BaseXMLFormatter._handle_indexesszz d../0 '' 2779 Qdnn=TA   >>$t~~5DN >>$t~~5DN  s B'B'ct|)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. rr<s r7r3z!_BaseXMLFormatter._get_prefix_uris"$''r9ci}|jrL|jjDcic]'\}}||jddk7rd|dk(r|nd||)}}}|Scc}}w)z Define other namespaces. This method will build dictionary of namespaces attributes for root element, conditionally with optional namespaces and prefix. xmlns:)r%itemsr4)r6 nmsp_dictpns r7_other_namespacesz#_BaseXMLFormatter._other_namespacess{%' ??!OO113Aq"--QU!A30114I  s,Ac|js|S|jD]=}|j|} t||st|||j|<?|S#t $rt d|wxYw)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 strattribKeyError)r6delem_rowcol attr_names r7_build_attribsz _BaseXMLFormatter._build_attribss~~O>> :C//4I :AcF|14QsVHOOI.  : :!23%899 :s )AA5c:|}t|trpd|vr6dj|Dcgc] }t|c}j n5dj|Dcgc] }t|c}j }|j |Scc}wcc}w)Nr]_) isinstancetuplejoinrgstripr4)r6rlflat_colcs r7rfz$_BaseXMLFormatter._get_flat_col_name,s c5 !9-AQ-.446XXs3!s1v34::<  //"8*-- .3s BBct|rrr<s r7_sub_element_clsz"_BaseXMLFormatter._sub_element_cls7s !$''r9c|j}|jsy|jD]H}|j|} t||s||dk(rdn t ||}||||_Jy#t $rt d|wxYw)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]re)rxr$rfr rgtextri)r6rjrksub_element_clsrl elem_namevals r7 _build_elemsz_BaseXMLFormatter._build_elems;s//~~ >> :C//4I :"1S6lafldAcF >$--0779 9 .s BB")NTdatarowNNNNNzutf-8TTNinferN)"rrrz7FilePath | WriteBuffer[bytes] | WriteBuffer[str] | Nonerboolr str | Noner!rr"rr#list[str] | Noner$rr%zdict[str | None, str] | Noner&rr'rgr( bool | Noner)rr*z5FilePath | ReadBuffer[str] | ReadBuffer[bytes] | Noner+rrzStorageOptions | NonereturnNonerbytesrr)rzdict[int | str, dict[str, Any]]rrg)rdict)rjdict[str, Any]rkrrr)rlz str | tuplerrg)rjrrkrrr)rr)rA __module__ __qualname____doc__r8r=rr1r2r/r5r3rcrnrfr rxr~rr9r7rr,s 9|SW &$!&*&*37!'+$(LP*115#**P* *  *  **$*$*1***%*"*J* (!*"/#*$ %*X(  *  %  % * *0 6 6* (  &  ( . .(( : :( : :r9rc8eZdZdZddZddZedZddZy) EtreeXMLFormatter Class for formatting data in xml using Python standard library modules: `xml.etree.ElementTree` and `xml.dom.minidom`. cddlm}m}m}||j|j |j |_|jjD]}||j|j|j}|js=|js1t|j|_ |j||w|j!||}|j||||jd|j"|j$|_|j(r|j+|_|j, t/d|j&S)NrElement SubElementtostring)rhxml)methodr'r(zBTo use stylesheet, you need lxml installed and selected as parser.)xml.etree.ElementTreerrrr4r rcrootr0valuesr!r#r$listrTr~rnr'r(out_xmlr)_prettify_treer* ValueErrorr6rrrrjrks r7r=zEtreeXMLFormatter._build_treeis8  / 09O9O9Q  !!((* /A!$))/@-PQH>>$..!%affh!!!X. ..q(;!!!X. / II]] 00      ..0DL ?? &T ||r9cddlm}d}|jr|jjD]0\}}t |t st |t s(|||2|j r d|j|j d}|Sd|jvrd|jdd}|Sd}|S#t$rt|j dwxYw)Nr)register_namespacer]{} is not included in namespaces)rrr%r_rqrgr&ri)r6rurirarbs r7r3z!EtreeXMLFormatter._get_prefix_uris< ??--/ -1a%*Q*<&q!, -{{Stt{{;>$..!%affh!!!X. ..q(;!!!X. / II**]] 00    ?? &..0DL||r9c|jrGd|jjvr*|jjdd|jd<yyy)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%rTpopr<s r7rz'LxmlXMLFormatter._convert_empty_str_keysE ??rT__%9%9%;;$(OO$7$7I$FDOOD ! X#T]];K(BKK0$%%'..t}}=k = >7m dii(W~ > >s A*C,,C5rrr) rArrrr8r=rr3r rxr __classcell__)rs@r7rrs7 & %N G  &r9r)%r __future__rrCrtypingrrrrJ pandas.errorsrpandas.util._decoratorsr r pandas.core.dtypes.commonr pandas.core.dtypes.missingr pandas.core.shared_docsr pandas.io.commonr pandas.io.xmlrrpandas._typingrrrrrpandasrrrrrr9r7rs#  - 3+0' ! !23$%:;>NNp:p: p:f RD)RDjx(xr9