Sindbad~EG File Manager

Current Path : /usr/local/lib/python3.12/site-packages/pandas/io/formats/__pycache__/
Upload File :
Current File : //usr/local/lib/python3.12/site-packages/pandas/io/formats/__pycache__/xml.cpython-312.pyc

�

Mٜg�>��4�dZddlmZddlZddlZddlmZmZmZddl	Z	ddl
mZddlm
Z
mZddlmZddlmZdd	lmZdd
lmZddlmZmZerddlmZmZmZmZmZdd
l m!Z!eededdz��Gd�d��Z"Gd�de"�Z#Gd�de"�Z$y)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)rrc�<�eZdZdZ															d																																	dd�Zdd�Zedd��Zedd��Zedd��Z	edd��Z
dd	�Zedd
��Zedd��Z
edd��Zed
��Zedd��Zedd��Zy)�_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/�|_|j3�y�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)�selfrrrr r!r"r#r$r%r&r'r(r)r*r+rs                 �@/usr/local/lib/python3.12/site-packages/pandas/io/formats/xml.py�__init__z_BaseXMLFormatter.__init__ls���&��
�,�����
�"��� ��
����"���"���$������ ��
�.���(���$���/:���.������+�+�2�2�4����2�2�4������ ����!��.�.�0�������c��t|��)��
        Build tree from  data.

        This method initializes the root and builds attributes and elements
        with optional namespaces.
        r�r6s r7�_build_treez_BaseXMLFormatter._build_tree�s��"�$�'�'r9c�6�|jr@t|j�s+tt|j�j�d���|j
rAt|j
�s+tt|j
�j�d���yy)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 r7r1z#_BaseXMLFormatter._validate_columns�s����>�>�,�t�~�~�">������'�0�0�1�1S�T��
��>�>�,�t�~�~�">������'�0�0�1�1S�T��
�#?�>r9c�B�tj|j�y)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 r7r2z$_BaseXMLFormatter._validate_encoding�s��	�
�
�d�m�m�$r9c�N�|j}|jr|j�}|j�Tt	j
�5t	jddt��|j|j�}ddd�|jd��S#1swY�xYw)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�ignorezDowncasting object dtype arrays)�categoryr)�orient)
rr�reset_indexr"�warnings�catch_warnings�filterwarnings�
FutureWarning�fillna�to_dict)r6�dfs  r7r/z$_BaseXMLFormatter._process_dataframe�s����Z�Z���:�:����!�B��;�;�"��(�(�*��'�'��5�*��
�Y�Y�t�{�{�+��
+��z�z��z�)�)�+�*�s�	8B�B$c�X�|jsytt|j��}|j|j	�D�cgc]}||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)r�next�iterr0�keysr.r#r$)r6�	first_key�x�indexess    r7r5z!_BaseXMLFormatter._handle_indexes�s����z�z����d�.�.�/�0�	��'�'�	�2�7�7�9�
�9�!�Q�d�n�n�=T�A�9�	�
��>�>�$�t�~�~�5�D�N��>�>�$�t�~�~�5�D�N���
s�B'�B'c��t|��)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_uri�s��"�$�'�'r9c���i}|jrL|jj�D��cic]'\}}||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_dict�p�ns    r7�_other_namespacesz#_BaseXMLFormatter._other_namespacess~��%'�	��?�?�!�O�O�1�1�3��3�D�A�q������"�-�-��Q��U��!�A�3��0�1�1�4�3�
�����
s�,Ac���|js|S|jD]=}|j|�}	t||�st||�|j|<�?|S#t
$rtd|����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�str�attrib�KeyError)r6�d�elem_row�col�	attr_names     r7�_build_attribsz _BaseXMLFormatter._build_attribss����~�~��O��>�>�C��/�/��4�I�
:��A�c�F�|�14�Q�s�V��H�O�O�I�.��	"�����
:��!2�3�%�8�9�9�
:�s�)A�A5c�:�|}t|t�rpd|vr6dj|D�cgc]
}t|���c}�j	�n5dj|D�cgc]
}t|���c}�j	�}|j
�|��Scc}wcc}w)Nr]�_)�
isinstance�tuple�joinrg�stripr4)r6rl�flat_col�cs    r7rfz$_BaseXMLFormatter._get_flat_col_name,s������c�5�!���9�����-��A��Q���-�.�4�4�6��X�X�s�3�s�!�s�1�v�s�3�4�:�:�<�
�
�/�/�"�8�*�-�-��	.��3s�B�Bc��t|��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rg�textri)r6rjrk�sub_element_clsrl�	elem_name�vals       r7�_build_elemsz_BaseXMLFormatter._build_elems;s����/�/���~�~���>�>�C��/�/��4�I�
:�"�1�S�6�l�a��f��l�d��A�c�F���<?���)�4�9�	"��
�
:��!2�3�%�8�9�9�
:�s�4A2�2B
c�J�|j�}|j�St|jd|j|jd��5}|j
j
|�ddd�y|j|j�j�S#1swYyxYw)N�wbF)r+r�is_text)
r=rrr+r�handle�write�decoder'�rstrip)r6�xml_doc�handless   r7�write_outputz_BaseXMLFormatter.write_outputPs����"�"�$�����*���#�#�� �,�,� $� 4� 4�������$�$�W�-����>�>�$�-�-�0�7�7�9�9���s�B�B")NT�data�rowNNNNNzutf-8TTN�inferN)"rrrz7FilePath | WriteBuffer[bytes] | WriteBuffer[str] | Noner�boolr �
str | Noner!r�r"r�r#�list[str] | Noner$r�r%zdict[str | None, str] | Noner&r�r'rgr(�bool | Noner)r�r*z5FilePath | ReadBuffer[str] | ReadBuffer[bytes] | Noner+rrzStorageOptions | None�return�None�r��bytes�r�r�)r�zdict[int | str, dict[str, Any]]�r�rg)r��dict)rj�dict[str, Any]rkrr�r)rlzstr | tupler�rg)rjr�rkrr�r�)r�r�)rA�
__module__�__qualname__�__doc__r8r=rr1r2r/r5r3rcrnrfr	rxr~r��r9r7rr,s���
9�|SW�� &�$�!�&*�&*�37�!��'+�$(�LP�*1�15�#*��*�P�*��	*�
�*��
*��*�$�*�$�*�1�*��*��*�%�*�"�*�J�*� (�!*�"/�#*�$
�%*�X(�����*�%��%��*��*�0�6��6�*(�����&����(�.��.��(��(��:��:�(�:��:r9rc�8�eZdZdZdd�Zdd�Zed��Zdd�Zy)	�EtreeXMLFormatter��
    Class for formatting data in xml using Python standard library
    modules: `xml.etree.ElementTree` and `xml.dom.minidom`.
    c���ddlm}m}m}||j�|j
��|j
���|_|jj�D]�}||j|j�|j���}|js=|js1t|j��|_|j||��w|j!||�}|j||���||jd|j"|j$��|_|j(r|j+�|_|j,�t/d��|j&S)Nr��Element�
SubElement�tostring)rh�xml)�methodr'r(zBTo use stylesheet, you need lxml installed and selected as parser.)�xml.etree.ElementTreer�r�r�r4r rc�rootr0�valuesr!r#r$�listrTr~rnr'r(�out_xmlr)�_prettify_treer*�
ValueError�r6r�r�r�rjrks      r7r=zEtreeXMLFormatter._build_treeis3��	
�	
���������/�0��9O�9O�9Q�
��	��!�!�(�(�*�A�!�$�)�)����/@�����-P�Q�H��>�>�$�.�.�!%�a�f�f�h�����!�!�!�X�.� �.�.�q�(�;���!�!�!�X�.�+� ��I�I���]�]� �0�0�	
�������.�.�0�D�L��?�?�&��T��
��|�|�r9c��ddlm}d}|jr�|jj�D]0\}}t	|t
�s�t	|t
�s�(|||��2|jr 	d|j|j�d�}|Sd|jvrd|jd�d�}|Sd}|S#t$rt|j�d���wxYw)Nr)�register_namespacer]�{�}� is not included in namespaces)r�r�r%r_rqrgr&ri)r6r��urirarbs     r7r3z!EtreeXMLFormatter._get_prefix_uri�s���<����?�?����-�-�/���1��a��%�*�Q��*<�&�q�!�,�0��{�{�S��t���t�{�{�;�<�B�?�C��
��t���&��4�?�?�2�.�/�r�2���
����
�� �S�"�d�k�k�]�2P�#Q�R�R�S�s�/B5�5"Cc��ddlm}|S�Nr)r�)r�r��r6r�s  r7rxz"EtreeXMLFormatter._sub_element_cls�s��4��r9c�l�ddlm}||j�}|jd|j��S)z�
        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')r6r��doms   r7r�z EtreeXMLFormatter._prettify_tree�s,��	0��$�,�,�'�����d�T�]�]��C�Cr9Nr�r�)	rAr�r�r�r=r3r	rxr�r�r9r7r�r�cs,���
%�N�(����
Dr9r�c�T��eZdZdZd�fd�Zd	d�Zdd�Zd
d�Zed��Z	d	d�Z
�xZS)�LxmlXMLFormatterr�c�D��t�|�|i|��|j�yr)�superr8�_convert_empty_str_key)r6�args�kwargs�	__class__s   �r7r8zLxmlXMLFormatter.__init__�s!���
���$�)�&�)��#�#�%r9c��ddlm}m}m}||j�|j
��|j��|_|jj�D]�}||j|j�|j���}|js=|js1t|j��|_|j||��w|j!||�}|j||���||j|j"d|j$|j&��|_|j*�|j-�|_|j(S)r;rr�)�nsmapr�)r)r�r'r()�
lxml.etreer�r�r�r4r r%r�r0r�r!r#r$r�rTr~rnr)r'r(r�r*�_transform_docr�s      r7r=zLxmlXMLFormatter._build_tree�s��	
�	
��t���/����/?�@����X��	��!�!�(�(�*�A�!�$�)�)����/@�����-P�Q�H��>�>�$�.�.�!%�a�f�f�h�����!�!�!�X�.� �.�.�q�(�;���!�!�!�X�.�+� ��I�I��*�*���]�]� �0�0�
����?�?�&��.�.�0�D�L��|�|�r9c��|jrGd|jj�vr*|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%rT�popr<s r7r�z'LxmlXMLFormatter._convert_empty_str_key�sE���?�?�r�T�_�_�%9�%9�%;�;�$(�O�O�$7�$7��I�$F�D�O�O�D�!� <�?r9c��d}|jrQ|jr 	d|j|j�d�}|Sd|jvrd|jd�d�}|Sd}|S#t$rt|j�d���wxYw)Nr]r�r�r�)r%r&ri)r6r�s  r7r3z LxmlXMLFormatter._get_prefix_uri�s������?�?��{�{�S��t���t�{�{�;�<�B�?�C��
��t���&��4�?�?�2�.�/�r�2���
����
�� �S�"�d�k�k�]�2P�#Q�R�R�S�s�A"�""Bc��ddlm}|Sr�)r�r�r�s  r7rxz!LxmlXMLFormatter._sub_element_clss��)��r9c���ddlm}m}m}m}|j
}|�J�t
||j|j|j��}t|�5}||j��}t|tj�r2||j�j|j�|��}	n
|||��}	ddd�|	�}
|
|j �}t#|�S#1swY�.xYw)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*rr'r+rrrq�io�StringIO�getvalue�encoder�r�)r6r�r�r�r��	style_doc�handle_data�xml_data�curr_parser�xsl_doc�transformer�new_docs            r7r�zLxmlXMLFormatter._transform_doc
s���	
�	
��O�O�	��$�$�$�,�(��]�]��(�(� �0�0�	
���[�
)�X�#�T�]�]�;�K��(�B�K�K�0�$��%�%�'�.�.�t�}�}�=�k��� ���=��*��7�m���d�i�i�(���W�~��*�
)�s
�A*C,�,C5r�r�r�)rAr�r�r�r8r=r�r3r	rxr��
__classcell__)r�s@r7r�r��s7����
&�
%�N	G�
�����
&r9r�)%r��
__future__rrCr��typingrrrrJ�
pandas.errorsr�pandas.util._decoratorsr	r
�pandas.core.dtypes.commonr�pandas.core.dtypes.missingr�pandas.core.shared_docsr
�pandas.io.commonr�
pandas.io.xmlrr�pandas._typingrrrrr�pandasrrr�r�r�r9r7�<module>r�s����#�
�	���
�-��
3�+�0�'��
���!�� �!2�3�$�%:�;�>N�N��p:�p:�	�p:�f	RD�)�RD�jx�(�xr9

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists