� B�g���v�dZddlmZddlZddlmZddlmZmZm Z ddl Z ddl m Z ddl mZddlmZmZdd lmZdd lmZdd lmZdd lmZdd lmZddlmZmZmZm Z m!Z!m"Z"m#Z#ddl$m%Z%er.ddl&m'Z'ddl(m)Z)ddl*m+Z+ddl,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5ddl6m7Z7eededdz���Gd�d����Z8Gd�de8��Z9Gd�de8��Z:dNd(�Z;dOd*�Z<dPd,�Z=e j>fdQdE�Z?eededdz���dFddGdGdddddHdIdddJde j>dK�dRdM���Z@dS)Sz5 :mod:``pandas.io.xml`` is a module for reading XML. �)� annotationsN)�PathLike)� TYPE_CHECKING�Any�Callable)�lib)�import_optional_dependency)�AbstractMethodError� ParserError)�doc)�find_stack_level)�check_dtype_backend)� is_list_like)� _shared_docs)� file_exists� get_handle�infer_compression� is_file_like� is_fsspec_url�is_url�stringify_path)� TextParser)�Sequence)�Element)�etree) �CompressionOptions� ConvertersArg�DtypeArg� DtypeBackend�FilePath� ParseDatesArg� ReadBuffer�StorageOptions� XMLParsers)� DataFrame�storage_options�decompression_options�path_or_buffer)r&r'c�J�eZdZdZd-d�Zd.d!�Zd/d$�Zd0d&�Zd1d'�Zd2d(�Z d3d+�Z d,S)4�_XMLFrameParsera� Internal subclass to parse XML into DataFrames. Parameters ---------- path_or_buffer : a valid JSON ``str``, path object or file-like object Any valid string path is acceptable. The string could be a URL. Valid URL schemes include http, ftp, s3, and file. xpath : str or regex The ``XPath`` expression to parse required set of nodes for migration to :class:`~pandas.DataFrame`. ``etree`` supports limited ``XPath``. namespaces : dict The namespaces defined in XML document (``xmlns:namespace='URI'``) as dicts with key being namespace and value the URI. elems_only : bool Parse only the child elements at the specified ``xpath``. attrs_only : bool Parse only the attributes at the specified ``xpath``. names : list Column names for :class:`~pandas.DataFrame` of parsed XML data. dtype : dict Data type for data or columns. E.g. {{'a': np.float64, 'b': np.int32, 'c': 'Int64'}} .. versionadded:: 1.5.0 converters : dict, optional Dict of functions for converting values in certain columns. Keys can either be integers or column labels. .. versionadded:: 1.5.0 parse_dates : bool or list of int or names or list of lists or dict Converts either index or select columns to datetimes .. versionadded:: 1.5.0 encoding : str Encoding of xml object or document. stylesheet : str or file-like URL, file, file-like object, or a raw string containing XSLT, ``etree`` does not support XSLT but retained for consistency. iterparse : dict, optional Dict with row element as key and list of descendant elements and/or attributes as value to be retrieved in iterparsing of XML document. .. versionadded:: 1.5.0 {decompression_options} .. versionchanged:: 1.4.0 Zstandard support. {storage_options} See also -------- pandas.io.xml._EtreeFrameParser pandas.io.xml._LxmlFrameParser Notes ----- To subclass this class effectively you must override the following methods:` * :func:`parse_data` * :func:`_parse_nodes` * :func:`_iterparse_nodes` * :func:`_parse_doc` * :func:`_validate_names` * :func:`_validate_path` See each method's respective documentation for details on their functionality. r(�.FilePath | ReadBuffer[bytes] | ReadBuffer[str]�xpath�str� namespaces�dict[str, str] | None� elems_only�bool� attrs_only�names�Sequence[str] | None�dtype�DtypeArg | None� converters�ConvertersArg | None� parse_dates�ParseDatesArg | None�encoding� str | None� stylesheet�5FilePath | ReadBuffer[bytes] | ReadBuffer[str] | None� iterparse�dict[str, list[str]] | None� compressionrr&r#�return�Nonec���||_||_||_||_||_||_||_||_| |_| |_ | |_ | |_ d|_ | |_ ||_dS�N)r(r,r.r0r2r3r5r7r9r;r=r?�is_stylerAr&)�selfr(r,r.r0r2r3r5r7r9r;r=r?rAr&s �]/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/pandas/io/xml.py�__init__z_XMLFrameParser.__init__�sw��"-����� �$���$���$����� ��� �$���&��� �� �$���"����� �/:���.������list[dict[str, str | None]]c� �t|���)z� Parse xml data. This method will call the other internal methods to validate ``xpath``, names, parse and return specific nodes. �r �rGs rH� parse_dataz_XMLFrameParser.parse_data�s��"�$�'�'�'rJ�elems� list[Any]c������jr�jrtd����jr#�jr�fd�|D��}nCd�|D��}n6�jr d�|D��}n"�jr�fd�|D��}n d�|D��}d�|D��}t t �d�|D��������fd �|D��}�jr�fd �|D��}|S) aA Parse xml nodes. This method will parse the children and attributes of elements in ``xpath``, conditionally for only elements, only attributes or both while optionally renaming node names. Raises ------ ValueError * If only elements and only attributes are specified. Notes ----- Namespace URIs will be removed from return node values. Also, elements with missing children or attributes compared to siblings will have optional keys filled with None values. z4Either element or attributes can be parsed not both.c ����g|]f}i|jr'|j���s|j|jini�d�t�j|�d����D�����gS)c�6�i|]\}}||jr|jnd��SrE��text��.0�nm�chs rH� <dictcomp>z;_XMLFrameParser._parse_nodes.<locals>.<listcomp>.<dictcomp>�s;����� &��B��2�7� <�������rJ�*)rV�isspace�tag�zipr3�findall�rX�elrGs �rH� <listcomp>z0_XMLFrameParser._parse_nodes.<locals>.<listcomp>�s���� � � �� � "�w�$�/1�w���/@�/@�$�R�V�R�W�-�-�!#� � ��*-�d�j�"�*�*�S�/�/�*J�*J���� � � � rJc�L�g|]!}d�|�d��D����"S)c�:�i|]}|j|jr|jnd��SrE�r^rV�rXrZs rHr[z;_XMLFrameParser._parse_nodes.<locals>.<listcomp>.<dictcomp>�s)��T�T�T�b�R�V���9�R�W�W�T�T�T�TrJr\�r`�rXrbs rHrcz0_XMLFrameParser._parse_nodes.<locals>.<listcomp>�sA������U�T�B�J�J�s�O�O�T�T�T���rJc�T�g|]%}d�|j���D����&S)c�"�i|] \}}||r|nd�� SrE��rX�k�vs rHr[z;_XMLFrameParser._parse_nodes.<locals>.<listcomp>.<dictcomp>�s'��C�C�C���A���$�A�A��C�C�CrJ��attrib�itemsris rHrcz0_XMLFrameParser._parse_nodes.<locals>.<listcomp>�s@�����HJ�C�C�����1B�1B�C�C�C���rJc ����g|]m}i|j�|jr'|j���s|j|jini�d�t �j|�d����D�����nS)c�6�i|]\}}||jr|jnd��SrErUrWs rHr[z;_XMLFrameParser._parse_nodes.<locals>.<listcomp>.<dictcomp>�s;�����"�B���r�w�8�B�G�G�D���rJr\)rqrVr]r^r_r3r`ras �rHrcz0_XMLFrameParser._parse_nodes.<locals>.<listcomp>�s���� � � ����i��,.�G�U�B�G�O�O�<M�<M�U�����(�(�SU����&)�$�*�b�j�j��o�o�&F�&F����� � � rJc��g|]Z}i|j�|jr'|j���s|j|jini�d�|�d��D�����[S)c�:�i|]}|j|jr|jnd��SrErfrgs rHr[z;_XMLFrameParser._parse_nodes.<locals>.<listcomp>.<dictcomp>s)��V�V�V��r�v�"�'�;�r�w�w�t�V�V�VrJr\)rqrVr]r^r`ris rHrcz0_XMLFrameParser._parse_nodes.<locals>.<listcomp>s������ � ��i��,.�G�U�B�G�O�O�<M�<M�U�����(�(�SU��W�V�b�j�j�QT�o�o�V�V�V����rJc�J�g|] }d�|���D����!S)c�X�i|]'\}}d|vr|�d��dn||��(S)�}�)�splitrms rHr[z;_XMLFrameParser._parse_nodes.<locals>.<listcomp>.<dictcomp> s8�� I� I� I�t�q�!��q���Q�W�W�S�\�\�!�_�_�a�� I� I� IrJ)rr�rX�ds rHrcz0_XMLFrameParser._parse_nodes.<locals>.<listcomp> s<�� � � �NO� I� I�q�w�w�y�y� I� I� I� � � rJc�@�g|]}|���D]}|���Srl��keys�rXr}rns rHrcz0_XMLFrameParser._parse_nodes.<locals>.<listcomp>�-��"F�"F�"F��Q�V�V�X�X�"F�"F��1�"F�"F�"F�"FrJc�.���g|]��fd��D����S)c�R��i|]#}||����vr�|nd��$SrEr�rXrnr}s �rHr[z;_XMLFrameParser._parse_nodes.<locals>.<listcomp>.<dictcomp>�3���C�C�C��!�Q�!�&�&�(�(�]�]�Q�q�T�T��C�C�CrJrl�rXr}r�s @�rHrcz0_XMLFrameParser._parse_nodes.<locals>.<listcomp>�/����S�S�S��C�C�C�C�d�C�C�C�S�S�SrJc �x��g|]6}tt�j|���������7Srl��dictr_r3�values�rXr}rGs �rHrcz0_XMLFrameParser._parse_nodes.<locals>.<listcomp>�5���F�F�F�1�T�#�d�j�!�(�(�*�*�5�5�6�6�F�F�FrJ)r0r2� ValueErrorr3�listr��fromkeys)rGrP�dictsr�s` @rH� _parse_nodesz_XMLFrameParser._parse_nodes�s�����, �?� U�t�� U��S�T�T� T� �?�0 ��z� � � � � �$� � � �����#������ �_� ���NS����E�E��Z� � � � � � � � � �E�E���  � ���E� � �SX� � � ���D�M�M�"F�"F�e�"F�"F�"F�G�G�H�H��S�S�S�S�U�S�S�S�� �:� G�F�F�F�F��F�F�F�E�� rJrc�6�� �g}d}t�jt��s)tt �j��j�d�����jr3t t�j�������nd}t�j|��s*tt �j|���d����t�j d��s�t�j ttf��rqt�j ��s]t�j ��sIt�j t��r�j �d��st#�j d���t%d���t'�j|��t't)�j|����k}|�j d � ��D�]�\}}d |jvr |j�d ��d n|j}|d kr||kri}|��jr�|r�t1�j|�j��D]x\} } || kr/|jr|jnd} | |���vr | |vr| || <| |jvr5|j| |���vr| |vr|j| || <�ynB�j|D]4} || kr|jr|jnd|| <| |jvr|j| || <�5|dkr�||kr|�|�|��d}|���t|d��re|����Q|����=|���d=|����|����=���|gkrt%d���tAt�!d�|D������� � fd�|D��}�jr�fd�|D��}|S)a# Iterparse xml nodes. This method will read in local disk, decompressed XML files for elements and underlying descendants using iterparse, a method to iterate through an XML tree without holding entire XML tree in memory. Raises ------ TypeError * If ``iterparse`` is not a dict or its dict value is not list-like. ParserError * If ``path_or_buffer`` is not a physical file on disk or file-like object. * If no data is returned from selected items in ``iterparse``. Notes ----- Namespace URIs will be removed from return node values. Also, elements with missing children or attributes in submitted list will have optional keys filled with None values. Nz" is not a valid type for iterparse�z+ is not a valid type for value in iterparse�read�z<?xml�<�inferziterparse is designed for large XML files that are fully extracted on local disk and not as compressed files or online sources.)�start�end)�eventsryrzr�r�� getpreviousrz+No result from selected items in iterparse.c�@�g|]}|���D]}|���Srlrr�s rHrcz4_XMLFrameParser._iterparse_nodes.<locals>.<listcomp>xr�rJc�.���g|]��fd��D����S)c�R��i|]#}||����vr�|nd��$SrErr�s �rHr[z?_XMLFrameParser._iterparse_nodes.<locals>.<listcomp>.<dictcomp>yr�rJrlr�s @�rHrcz4_XMLFrameParser._iterparse_nodes.<locals>.<listcomp>yr�rJc �x��g|]6}tt�j|���������7Srlr�r�s �rHrcz4_XMLFrameParser._iterparse_nodes.<locals>.<listcomp>|r�rJ)"� isinstancer?r�� TypeError�type�__name__�next�iterr�r�hasattrr(r-rrr� startswithrr �len�setr^r{r3r_rVr�rq�append�clearr�� getparentr�r�) rGr?r��row�row_node�iterparse_repeats�event�elem� curr_elem�colrY�elem_valr�s ` @rH�_iterparse_nodesz _XMLFrameParser._iterparse_nodessk����..0��,0���$�.�$�/�/� �����'�'�0�T�T�T��� �9=��N�4��T�^�0�0�2�2�3�3�4�4�4�B���D�N�8�4�5�5� �����x�0�1�1�)�)�)��� � ��+�V�4�4� ��4�.��h��@�@� ��d�)�*�*� ��T�0�1�1� � �4�.��4�4� � �'�2�2�>�B�B� �!��!4�g�>�>�J��L��� �  ���x� 8�9�9�S� ���x�(� )� )�> �> � ��%�9�T�%8�AQ�R�R�R�# 0�# 0�K�E�4�25���/�/�����s�+�+�A�.�.�t�x�I�������(�(��C����:�8�"3�8�#&�t�~�h�'?���#L�#L�;�;���R�$��+�+�48�I�'G�t�y�y�4�H�'�s�z�z�|�|�;�;��#� � �*2��B���$�+�-�-�#�{�3�/�s�z�z�|�|�C�C��RU� � �*.�+�c�*:��B���;� $�~�h�7�8�8��$��+�+�48�I�'G�t�y�y�4�C��H��$�+�-�-�'+�{�3�'7�C��H����~�~���(�(�S�_��L�L��%�%�%��C�� � � � � ��4��/�/�0��(�(�*�*�6�4�>�>�;K�;K�;W� �N�N�,�,�Q�/��(�(�*�*�6�4�>�>�;K�;K�;W�� �B�;�;��K�L�L� L��D�M�M�"F�"F�e�"F�"F�"F�G�G�H�H��S�S�S�S�U�S�S�S�� �:� G�F�F�F�F��F�F�F�E�� rJc� �t|���)a* Validate ``xpath``. This method checks for syntax, evaluation, or empty nodes return. Raises ------ SyntaxError * If xpah is not supported or issues with namespaces. ValueError * If xpah does not return any nodes. rMrNs rH�_validate_pathz_XMLFrameParser._validate_path�s��"�$�'�'�'rJc� �t|���)z� Validate names. This method will check if names is a list-like and aligns with length of parse nodes. Raises ------ ValueError * If value is not a list and less then length of nodes. rMrNs rH�_validate_namesz_XMLFrameParser._validate_names�s��"�$�'�'�'rJ�raw_doc�Element | etree._Elementc� �t|���)z� Build tree from path_or_buffer. This method will parse XML object into tree either from string/bytes or file location. rM)rGr�s rH� _parse_docz_XMLFrameParser._parse_doc�s��"�$�'�'�'rJN)r(r+r,r-r.r/r0r1r2r1r3r4r5r6r7r8r9r:r;r<r=r>r?r@rArr&r#rBrC�rBrK)rPrQrBrK)r?rrBrK�rBrQ�rBrC)r�r+rBr�) r�� __module__� __qualname__�__doc__rIrOr�r�r�r�r�rlrJrHr*r*>s������� Q�Q�f/�/�/�/�B(�(�(�(�T�T�T�T�lg�g�g�g�R(�(�(�(�" (� (� (� (� (� (� (� (� (� (rJr*c�2�eZdZdZdd�Zdd�Zdd�Zdd �Zd S)�_EtreeFrameParserz Internal class to parse XML into DataFrames with the Python standard library XML module: `xml.etree.ElementTree`. rBrKc�<�ddlm}|j�td���|j�3|�|j��|_|���}|���|j�|� |��n|� |��}|S)Nr�r?zBTo use stylesheet, you need lxml installed and selected as parser.) �xml.etree.ElementTreer?r=r�r�r(�xml_docr�r�r�r��rGr?rP� xml_dictss rHrOz_EtreeFrameParser.parse_data�s���3�3�3�3�3�3� �?� &��T��� � �>� !��?�?�4�+>�?�?�D�L��'�'�)�)�E� �������~�%� � � �e� $� $� $��&�&�y�1�1� � �rJrQc��d} |j�|j|j���}d�|D��}d�|D��}|�t |���|�S|jr|gkrt |���|jr|ikrt |���|gkr|ikrt |���n$#ttf$rtd���wxYw|S)z� Notes ----- ``etree`` supports limited ``XPath``. If user attempts a more complex expression syntax error will raise. ��xpath does not return any nodes or attributes. Be sure to specify in `xpath` the parent nodes of children and attributes to parse. If document uses namespaces denoted with xmlns, be sure to define namespaces and use them in xpath.�r.c�B�g|]}|�d��D]}|���S�r\rh�rXrbrZs rHrcz4_EtreeFrameParser._validate_path.<locals>.<listcomp>�s/��E�E�E�r�R�Z�Z��_�_�E�E�r��E�E�E�ErJc�R�i|]$}|j���D]\}}||�� �%Srlrp�rXrbrnros rHr[z4_EtreeFrameParser._validate_path.<locals>.<dictcomp>�s7��H�H�H�b�b�i�o�o�6G�6G�H�H�d�a��Q��H�H�H�HrJNzxYou have used an incorrect or unsupported XPath expression for etree library or you used an undeclared namespace prefix.) r�r`r,r.r�r0r2�KeyError� SyntaxError�rG�msgrP�children�attrss rHr�z _EtreeFrameParser._validate_path�s�� !� � ��L�(�(�����(�P�P�E�E�E�U�E�E�E�H�H�H�E�H�H�H�E��}� ��o�o�%�� ��?�*�x�2�~�~�$�S�/�/�)��?�*�u��{�{�$�S�/�/�)��r�>�>�e�r�k�k�$�S�/�/�)����+�&� � � ��/��� � ����� s �B$B)�)!C rCc���|jr�|jr-|jtt|j����}n?|j�|j|j���}|�|�d��ng}t|j��r6t|j��t|��krtd���dStt|j��j�d����dS)Nr�r\�7names does not match length of child elements in xpath.� is not a valid type for names)r3r?r�r�r��findr,r.r`rr�r�r�r�r�)rGr��parents rHr�z!_EtreeFrameParser._validate_names�s��� �:� ��~� M��>�$�t�D�N�/C�/C�*D�*D�E�����*�*�4�:�$�/�*�R�R��28�2D�6�>�>�#�.�.�.�"���D�J�'�'� ��t�z�?�?�S��]�]�2�2�$�Q����3�2�  ��D�J�'�'�0�P�P�P���� � rJr�r+rc��ddlm}m}t||j|j|j���}t|��5}||j���}|||���}ddd��n #1swxYwY|���S)Nr)� XMLParser�parse��filepath_or_bufferr;rAr&�r;��parser) r�r�r��get_data_from_filepathr;rAr&�preprocess_data�getroot)rGr�r�r�� handle_data�xml_data� curr_parser�documents rHr�z_EtreeFrameParser._parse_docs��� � � � � � � � � -�&��]��(� �0�  � � � ��[� )� )� ;�X�#�)�T�]�;�;�;�K��u�X�k�:�:�:�H� ;� ;� ;� ;� ;� ;� ;� ;� ;� ;� ;���� ;� ;� ;� ;����!�!�!s�A%�%A)�,A)Nr�r�r�)r�r+rBr)r�r�r�r�rOr�r�r�rlrJrHr�r��so�������� ����,'�'�'�'�R����("�"�"�"�"�"rJr�c�:�eZdZdZdd�Zdd�Zdd�Zdd �Zdd�ZdS)�_LxmlFrameParserz� Internal class to parse XML into :class:`~pandas.DataFrame` with third-party full-featured XML library, ``lxml``, that supports ``XPath`` 1.0 and XSLT 1.0. rBrKc��ddlm}|j�r|�|j��|_|jr8|�|j��|_|���|_|���}|� ��|j�|� |��n|� |��}|S)z� Parse xml data. This method will call the other internal methods to validate ``xpath``, names, optionally parse and run XSLT, and parse original or transformed XML and return specific nodes. rr�) � lxml.etreer?r�r(r�r=�xsl_doc�_transform_docr�r�r�r�r�s rHrOz_LxmlFrameParser.parse_data!s��� )�(�(�(�(�(� �>� !��?�?�4�+>�?�?�D�L��� 5�#���t��?�?�� �#�2�2�4�4�� ��'�'�)�)�E� �������~�%� � � �e� $� $� $��&�&�y�1�1� � �rJrQc�b�d}|j�|j|j���}d�|D��}d�|D��}|gkrt|���|gkrS|jr|gkrt|���|jr|ikrt|���|gkr|ikrt|���|S)Nr�r�c�B�g|]}|�d��D]}|���Sr�)r,r�s rHrcz3_LxmlFrameParser._validate_path.<locals>.<listcomp>Is/��?�?�?�2����#���?�?�2�B�?�?�?�?rJc�R�i|]$}|j���D]\}}||�� �%Srlrpr�s rHr[z3_LxmlFrameParser._validate_path.<locals>.<dictcomp>Js7��D�D�D�"�"�)�/�/�2C�2C�D�D�$�!�Q��A�D�D�D�DrJ)r�r,r.r�r0r2r�s rHr�z_LxmlFrameParser._validate_path>s��� !� �� �"�"�4�:�$�/�"�J�J��?�?��?�?�?��D�D��D�D�D�� �B�;�;��S�/�/� !� �B�;�;��� &�8�r�>�>� ��o�o�%��� &�5�B�;�;� ��o�o�%��2�~�~�%�2�+�+� ��o�o�%�� rJrCc��|jr�|jr-|jtt|j����}n)|j�|jdz|j���}t|j��r6t|j��t|��krtd���dStt|j��j �d����dS)Nz[1]/*r�r�r�) r3r?r�r�r�r,r.rr�r�r�r�r�)rGr�s rHr�z _LxmlFrameParser._validate_namesYs��� �:� ��~� ��>�$�t�D�N�/C�/C�*D�*D�E����<�-�-��J��(�T�_�.�����D�J�'�'� ��t�z�?�?�S��]�]�2�2�$�Q����3�2�  ��D�J�'�'�0�P�P�P���� � rJr�r+�etree._Elementc��ddlm}m}m}t ||j|j|j���}t|��5}||j���}t|tj ��rN|j�td���||� ���|j��|���}n |||���}ddd��n #1swxYwY|S)Nr)r�� fromstringr�r�r�z2Can not pass encoding None when input is StringIO.r�)r�r�r�r�r�r;rAr&r�r��io�StringIOr��getvalue�encode) rGr�r�r�r�r�r�r�r�s rHr�z_LxmlFrameParser._parse_docns]�� � � � � � � � � � � -�&��]��(� �0�  � � � ��[� )� )� ?�X�#�)�T�]�;�;�;�K��(�B�K�0�0� ?��=�(�#�L����&�:��%�%�'�'�.�.�t�}�=�=�k������!�5��+�>�>�>�� ?� ?� ?� ?� ?� ?� ?� ?� ?� ?� ?���� ?� ?� ?� ?��s�BC�C�C�etree._XSLTResultTreec�R�ddlm}||j��}||j��}|S)z� Transform original tree using stylesheet. This method will transform original xml using XSLT script into am ideally flatter xml document for easier parsing and migration to Data Frame. r)�XSLT)r�rr�r�)rGr� transformer�new_docs rHr�z_LxmlFrameParser._transform_doc�s=�� $�#�#�#�#�#��d�4�<�(�(� ��+�d�l�+�+���rJNr�r�r�)r�r+rBr�)rBr) r�r�r�r�rOr�r�r�r�rlrJrHr�r�s��������� ����:����6����*����B � � � � � rJr�r��6FilePath | bytes | ReadBuffer[bytes] | ReadBuffer[str]r;r<rArr#rB�1str | bytes | ReadBuffer[bytes] | ReadBuffer[str]c���t|t��st|��}t|t��r�|�d��s�t|t��r-t |��st |��st|��rat|d|||���5}t|j d��r|j � ��n|j }ddd��n #1swxYwY|S)aG Extract raw XML data. The method accepts three input types: 1. filepath (string-like) 2. file-like object (e.g. open file object, StringIO) 3. XML string or bytes This method turns (1) into (2) to simplify the rest of the processing. It returns input types (2) and (3) unchanged. r��r)r;rAr&r�N) r��bytesrr-r�rrrrr��handler�)r�r;rAr&� handle_objs rHr�r��sY��" �(�%� 0� 0�@�+�,>�?�?�� �%�s�+�+��"�-�-�n�=�=�� �)�3� /� /� � �$� %� %� � �+� ,� ,� � �)� *� *��� � ��#�+�  � � � � ��:�,�f�5�5�'� �!�&�&�(�(�(��&� � � � � � � � � � � � ���� � � � � �s�%6C'�'C+�.C+�io.StringIO | io.BytesIOc��t|t��rtj|��}n)t|t��rtj|��}|S)z� Convert extracted raw data. This method will return underlying data of extracted XML content. The data either has a `read` attribute (e.g. a file object or a StringIO/BytesIO) or is a string or bytes that is an XML document. )r�r-r�r�r �BytesIO)�datas rHr�r��sM���$���� ��{�4� � ��� �D�%� � � ��z�$���� �KrJr%c ��tt|����}d�|D��} t|fd|i|��5}|���cddd��S#1swxYwYdS#t$rt d���wxYw)z� Convert parsed data to Data Frame. This method will bind xml dictionary data of keys and values into named columns of Data Frame using the built-in TextParser class that build Data Frame and infers specific dtypes. c�P�g|]#}t|�������$Srl)r�r�r|s rHrcz"_data_to_frame.<locals>.<listcomp>�s(�� ,� ,� ,�!�T�!�(�(�*�*� � � ,� ,� ,rJr3NzqXML document may be too complex for import. Try to flatten document and use distinct element and attribute names.)r�r�rr�r )r�kwargs�tags�nodes�tps rH�_data_to_framer�s��� ��T� � � � �D� ,� ,�t� ,� ,� ,�E� � �� 4� 4�T� 4�V� 4� 4� ���7�7�9�9� � � � � � � � � � � � ���� � � � � � �� � � � �� +� � � � ���s.�A'�A� A'�A�A'�!A�"A'�'Br+r,r-r.r/r0r1r2r3r4r5r6r7r8r9r:r�r$r=r>r?r@� dtype_backend�DtypeBackend | lib.NoDefaultc �D�t|t��rott|��t |��t |��t |��g��s(tjdtt�����| dkr?tdd���}|�t|||||||||| | | | |��}nAtd���| d krt|||||||||| | | | |��}ntd ���|���}t#d |||||d �|��S) a Call internal parsers. This method will conditionally call internal parsers: LxmlFrameParser and/or EtreeParser. Raises ------ ImportError * If lxml is not installed if selected as parser. ValueError * If parser is not lxml or etree. z�Passing literal xml to 'read_xml' is deprecated and will be removed in a future version. To read from a literal string, wrap it in a 'StringIO' object.)� stacklevel�lxmlz lxml.etree�ignore)�errorsNz7lxml not found, please install or use the etree parser.rz,Values for parser can only be lxml or etree.)rr5r7r9rrl)r�r-�anyrrrr�warnings�warn� FutureWarningr r r�� ImportErrorr�r�rOr)r(r,r.r0r2r3r5r7r9r;r�r=r?rAr&rrr�p� data_dictss rH�_parser&�s���H�.�#�&�&� �s� �� (� (� �� '� '� �>� "� "� �.� )� )�  �0�0� � � � >� �'�)�)�  � � � �����)�,�x�H�H�H�� � � �����������������A�A�"�W�X�X� X� �7� � � � � � � � � � � � � � � � � � � ���"�G�H�H�H������J� � � ����#�  � � �  � �rJz./*Fzutf-8rr�)r,r.r0r2r3r5r7r9r;r�r=r?rAr&r�StorageOptions | Nonec��t|��tdid|�d|�d|�d|�d|�d|�d|�d|�d |�d | �d | �d | �d | �d| �d|�d|��S)aE' Read XML document into a :class:`~pandas.DataFrame` object. .. versionadded:: 1.3.0 Parameters ---------- path_or_buffer : str, path object, or file-like object String, path object (implementing ``os.PathLike[str]``), or file-like object implementing a ``read()`` function. The string can be any valid XML string or a path. The string can further be a URL. Valid URL schemes include http, ftp, s3, and file. .. deprecated:: 2.1.0 Passing xml literal strings is deprecated. Wrap literal xml input in ``io.StringIO`` or ``io.BytesIO`` instead. xpath : str, optional, default './\*' The ``XPath`` to parse required set of nodes for migration to :class:`~pandas.DataFrame`.``XPath`` should return a collection of elements and not a single element. Note: The ``etree`` parser supports limited ``XPath`` expressions. For more complex ``XPath``, use ``lxml`` which requires installation. namespaces : dict, optional The namespaces defined in XML document as dicts with key being namespace prefix and value the URI. There is no need to include all namespaces in XML, only the ones used in ``xpath`` expression. Note: if XML document uses default namespace denoted as `xmlns='<URI>'` without a prefix, you must assign any temporary namespace prefix such as 'doc' to the URI in order to parse underlying nodes and/or attributes. For example, :: namespaces = {{"doc": "https://example.com"}} elems_only : bool, optional, default False Parse only the child elements at the specified ``xpath``. By default, all child elements and non-empty text nodes are returned. attrs_only : bool, optional, default False Parse only the attributes at the specified ``xpath``. By default, all attributes are returned. names : list-like, optional Column names for DataFrame of parsed XML data. Use this parameter to rename original element names and distinguish same named elements and attributes. dtype : Type name or dict of column -> type, optional Data type for data or columns. E.g. {{'a': np.float64, 'b': np.int32, 'c': 'Int64'}} Use `str` or `object` together with suitable `na_values` settings to preserve and not interpret dtype. If converters are specified, they will be applied INSTEAD of dtype conversion. .. versionadded:: 1.5.0 converters : dict, optional Dict of functions for converting values in certain columns. Keys can either be integers or column labels. .. versionadded:: 1.5.0 parse_dates : bool or list of int or names or list of lists or dict, default False Identifiers to parse index or columns to datetime. The behavior is as follows: * boolean. If True -> try parsing the index. * list of int or names. e.g. If [1, 2, 3] -> try parsing columns 1, 2, 3 each as a separate date column. * list of lists. e.g. If [[1, 3]] -> combine columns 1 and 3 and parse as a single date column. * dict, e.g. {{'foo' : [1, 3]}} -> parse columns 1, 3 as date and call result 'foo' .. versionadded:: 1.5.0 encoding : str, optional, default 'utf-8' Encoding of XML document. parser : {{'lxml','etree'}}, default 'lxml' Parser module to use for retrieval of data. Only 'lxml' and 'etree' are supported. With 'lxml' more complex ``XPath`` searches and ability to use XSLT stylesheet are supported. stylesheet : str, path object or file-like object A URL, file-like object, or a raw string containing an XSLT script. This stylesheet should flatten complex, deeply nested XML documents for easier parsing. To use this feature you must have ``lxml`` module installed and specify 'lxml' as ``parser``. The ``xpath`` must reference nodes of transformed XML document generated after XSLT transformation and not the original XML document. Only XSLT 1.0 scripts and not later versions is currently supported. iterparse : dict, optional The nodes or attributes to retrieve in iterparsing of XML document as a dict with key being the name of repeating element and value being list of elements or attribute names that are descendants of the repeated element. Note: If this option is used, it will replace ``xpath`` parsing and unlike ``xpath``, descendants do not need to relate to each other but can exist any where in document under the repeating element. This memory- efficient method should be used for very large XML files (500MB, 1GB, or 5GB+). For example, :: iterparse = {{"row_element": ["child_elem", "attr", "grandchild_elem"]}} .. versionadded:: 1.5.0 {decompression_options} .. versionchanged:: 1.4.0 Zstandard support. {storage_options} dtype_backend : {{'numpy_nullable', 'pyarrow'}}, default 'numpy_nullable' Back-end data type applied to the resultant :class:`DataFrame` (still experimental). Behaviour is as follows: * ``"numpy_nullable"``: returns nullable-dtype-backed :class:`DataFrame` (default). * ``"pyarrow"``: returns pyarrow-backed nullable :class:`ArrowDtype` DataFrame. .. versionadded:: 2.0 Returns ------- df A DataFrame. See Also -------- read_json : Convert a JSON string to pandas object. read_html : Read HTML tables into a list of DataFrame objects. Notes ----- This method is best designed to import shallow XML documents in following format which is the ideal fit for the two-dimensions of a ``DataFrame`` (row by column). :: <root> <row> <column1>data</column1> <column2>data</column2> <column3>data</column3> ... </row> <row> ... </row> ... </root> As a file format, XML documents can be designed any way including layout of elements and attributes as long as it conforms to W3C specifications. Therefore, this method is a convenience handler for a specific flatter design and not all possible XML structures. However, for more complex XML documents, ``stylesheet`` allows you to temporarily redesign original document with XSLT (a special purpose language) for a flatter version for migration to a DataFrame. This function will *always* return a single :class:`DataFrame` or raise exceptions due to issues with XML document, ``xpath``, or other parameters. See the :ref:`read_xml documentation in the IO section of the docs <io.read_xml>` for more information in using this method to parse XML files to DataFrames. Examples -------- >>> from io import StringIO >>> xml = '''<?xml version='1.0' encoding='utf-8'?> ... <data xmlns="http://example.com"> ... <row> ... <shape>square</shape> ... <degrees>360</degrees> ... <sides>4.0</sides> ... </row> ... <row> ... <shape>circle</shape> ... <degrees>360</degrees> ... <sides/> ... </row> ... <row> ... <shape>triangle</shape> ... <degrees>180</degrees> ... <sides>3.0</sides> ... </row> ... </data>''' >>> df = pd.read_xml(StringIO(xml)) >>> df shape degrees sides 0 square 360 4.0 1 circle 360 NaN 2 triangle 180 3.0 >>> xml = '''<?xml version='1.0' encoding='utf-8'?> ... <data> ... <row shape="square" degrees="360" sides="4.0"/> ... <row shape="circle" degrees="360"/> ... <row shape="triangle" degrees="180" sides="3.0"/> ... </data>''' >>> df = pd.read_xml(StringIO(xml), xpath=".//row") >>> df shape degrees sides 0 square 360 4.0 1 circle 360 NaN 2 triangle 180 3.0 >>> xml = '''<?xml version='1.0' encoding='utf-8'?> ... <doc:data xmlns:doc="https://example.com"> ... <doc:row> ... <doc:shape>square</doc:shape> ... <doc:degrees>360</doc:degrees> ... <doc:sides>4.0</doc:sides> ... </doc:row> ... <doc:row> ... <doc:shape>circle</doc:shape> ... <doc:degrees>360</doc:degrees> ... <doc:sides/> ... </doc:row> ... <doc:row> ... <doc:shape>triangle</doc:shape> ... <doc:degrees>180</doc:degrees> ... <doc:sides>3.0</doc:sides> ... </doc:row> ... </doc:data>''' >>> df = pd.read_xml(StringIO(xml), ... xpath="//doc:row", ... namespaces={{"doc": "https://example.com"}}) >>> df shape degrees sides 0 square 360 4.0 1 circle 360 NaN 2 triangle 180 3.0 >>> xml_data = ''' ... <data> ... <row> ... <index>0</index> ... <a>1</a> ... <b>2.5</b> ... <c>True</c> ... <d>a</d> ... <e>2019-12-31 00:00:00</e> ... </row> ... <row> ... <index>1</index> ... <b>4.5</b> ... <c>False</c> ... <d>b</d> ... <e>2019-12-31 00:00:00</e> ... </row> ... </data> ... ''' >>> df = pd.read_xml(StringIO(xml_data), ... dtype_backend="numpy_nullable", ... parse_dates=["e"]) >>> df index a b c d e 0 0 1 2.5 True a 2019-12-31 1 1 <NA> 4.5 False b 2019-12-31 r(r,r.r0r2r3r5r7r9r;r�r=r?rAr&rrl)rr&)r(r,r.r0r2r3r5r7r9r;r�r=r?rAr&rs rH�read_xmlr)`s���L � �&�&�&� � � � �%�~� ��e� ��:� ��:�  � �:�  � �e�  ��e� ��:� � �K� ��� ��v� ��:� ��)� � �K� �(�� � $�m�! �rJ) r�rr;r<rArr&r#rBr)rBr )rBr%)"r(r+r,r-r.r/r0r1r2r1r3r4r5r6r7r8r9r:r;r<r�r$r=r>r?r@rArr&r#rrrBr%)"r(r+r,r-r.r/r0r1r2r1r3r4r5r6r7r8r9r:r;r<r�r$r=r>r?r@rArr&r'rrrBr%)Ar�� __future__rr��osr�typingrrrr � pandas._libsr�pandas.compat._optionalr � pandas.errorsr r �pandas.util._decoratorsr �pandas.util._exceptionsr �pandas.util._validatorsr�pandas.core.dtypes.commonr�pandas.core.shared_docsr�pandas.io.commonrrrrrrr�pandas.io.parsersr�collections.abcrr�rrr�pandas._typingrrrrr r!r"r#r$�pandasr%r*r�r�r�r�r� no_defaultr&r)rlrJrH�<module>r;s����#�"�"�"�"�"� � � � ����������������� ����������>�>�>�>�>�>���������(�'�'�'�'�'�4�4�4�4�4�4�7�7�7�7�7�7�2�2�2�2�2�2�0�0�0�0�0�0�������������������)�(�(�(�(�(��!�(�(�(�(�(�(�-�-�-�-�-�-������� � � � � � � � � � � � � � � � � � � � � � �!� � � � � ��� �!2�3�&�'>�?�BR�R����f(�f(�f(�f(�f(�f(�f(� ��f(�R l"�l"�l"�l"�l"��l"�l"�l"�^B�B�B�B�B��B�B�B�J*�*�*�*�Z����$ � � � �N36�.�!h�h�h�h�h�V�� �!2�3�&�'>�?�BR�R�����(,���"&�!�'+�(,�"��HL�-1�&-�-1�25�.�%u�u�u�u�u� ��u�u�urJ
Memory