� K�g�8� ��ddlmZmZmZddlmZddlmZmZm Z dZ e e��dfe ee ddfhz��dfe ee dd fe dd fhz��dfe e ddfe dd fg��dfe e dd fe dd fg��dfd�Z Gd�de ��ZGd�de��ZGd�de ��ZdS)�)�absolute_import�division�unicode_literals)� text_type�)�scopingElements�tableInsertModeElements� namespacesNF�html�button�ol�ul�table�optgroup�optionT)Nr �listr�selectc�P�eZdZdZd�Zd�Zd�Zd�Zd d�Zd�Z d �Z d �Z d �Z d �Z dS)�NodezRepresents an item in the treec�Z�||_d|_d|_i|_g|_g|_dS)zRCreates a Node :arg name: The tag name associated with the node N)�name�parent�value� attributes� childNodes�_flags)�selfrs �j/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/html5lib/treebuilders/base.py�__init__z Node.__init__s4���� ��� ��� ��������� � � �c��d�d�|j���D����}|rd|j�d|�d�Sd|jzS)N� c�$�g|] \}}|�d|�d���S)z="�"�)�.0rrs r� <listcomp>z Node.__str__.<locals>.<listcomp>.s9��";�";�";�&1�d�E�26���u�u�u�"=�";�";�";r �<�>�<%s>)�joinr�itemsr)r� attributesStrs r�__str__z Node.__str__-sp�����";�";�"&�/�"7�"7�"9�"9�";�";�";�<�<� � � (� (� $� � � �=�=�=�9� 9��T�Y�'� 'r c��d|jzS)Nr*)r�rs r�__repr__z Node.__repr__6s�����#�#r c��t�)z[Insert node as a child of the current node :arg node: the node to insert ��NotImplementedError�r�nodes r� appendChildzNode.appendChild9� �� "�!r Nc��t�)aBInsert data as text in the current node, positioned before the start of node insertBefore or to the end of the node's text. :arg data: the data to insert :arg insertBefore: True if you want to insert the text before the node and False if you want to insert it after the node r3)r�data� insertBefores r� insertTextzNode.insertTextA� ��"�!r c��t�)aInsert node as a child of the current node, before refNode in the list of child nodes. Raises ValueError if refNode is not a child of the current node :arg node: the node to insert :arg refNode: the child node to insert the node before r3)rr6�refNodes rr;zNode.insertBeforeMr=r c��t�)zhRemove node from the children of the current node :arg node: the child node to remove r3r5s r� removeChildzNode.removeChildYr8r c�R�|jD]}|�|���g|_dS)z�Move all the children of the current node to newParent. This is needed so that trees that don't store text as nodes move the text in the correct way :arg newParent: the node to move all this node's children to N)rr7)r� newParent�childs r�reparentChildrenzNode.reparentChildrenas7���_� )� )�E� � !� !�%� (� (� (� (�����r c��t�)z�Return a shallow copy of the current node i.e. a node with the same name and attributes but with no parent or child nodes r3r0s r� cloneNodezNode.cloneNodens ��"�!r c��t�)zFReturn true if the node has children or text, false otherwise r3r0s r� hasContentzNode.hasContentts ��"�!r �N)�__name__� __module__� __qualname__�__doc__rr.r1r7r<r;rArErGrIr%r rrrs�������(�(����((�(�(�$�$�$�"�"�"� "� "� "� "� "� "� "�"�"�"� � � �"�"�"� "�"�"�"�"r rc��eZdZd�Zd�ZdS)�ActiveFormattingElementsc���d}|tkrS|ddd�D]G}|tkrn9|�||��r|dz }|dkr|�|��n�Ht�||��dS)Nr�������)�Marker� nodesEqual�remover�append)rr6� equalCount�elements rrXzActiveFormattingElements.append{s���� � �6�>�>����"��:� � ���f�$�$��E��?�?�7�D�1�1�$��!�O�J���?�?��K�K��(�(�(��E�#� � � �D�$�����r c�N�|j|jksdS|j|jksdSdS)NFT)� nameTupler)r�node1�node2s rrVz#ActiveFormattingElements.nodesEqual�s1����%�/�1�1��5���5�#3�3�3��5��tr N)rKrLrMrXrVr%r rrPrPzs2������  �  �  �����r rPc��eZdZdZdZdZdZdZdZd�Z d�Z dd�Z d�Z d�Z d�Zd �Zd �Zdd �Zd �Zd �Zd�Zeee��Zd�Zd�Zdd�Zd�Zdd�Zd�Zd�Zd�ZdS)� TreeBuilderaBase treebuilder implementation * documentClass - the class to use for the bottommost node of a document * elementClass - the class to use for HTML Elements * commentClass - the class to use for comments * doctypeClass - the class to use for doctypes Nc�P�|rd|_nd|_|���dS)zmCreate a TreeBuilder :arg namespaceHTMLElements: whether or not to namespace HTML elements zhttp://www.w3.org/1999/xhtmlN)�defaultNamespace�reset)r�namespaceHTMLElementss rrzTreeBuilder.__init__�s0�� !� )�$B�D� !� !�$(�D� !� � � � � � � � r c��g|_t��|_d|_d|_d|_|���|_dS)NF)� openElementsrP�activeFormattingElements� headPointer� formPointer�insertFromTable� documentClass�documentr0s rrczTreeBuilder.reset�sI�����(@�(B�(B��%� ������$����*�*�,�,�� � � r c�B�t|d��}|s;t|t��rtd|f}t|t��sJ�t |\}}t |j��D],}|r ||krdS|s|j|krdS||j|vz rdS�-J�)Nr\r TF) �hasattr� isinstancerr �tuple�listElementsMap�reversedrfr\)r�target�variant� exactNode� listElements�invertr6s r�elementInScopezTreeBuilder.elementInScope�s����F�K�0�0� �� -��&�)�,�,� 6�$�V�,�f�5���f�e�,�,� ,� ,�,�.�w�7�� �f��T�.�/�/� � �D�� �T�V�^�^��t�t�� �4�>�V�#;�#;��t�t��D�N�l�:�;� ��u�u� � �ur c���|jsdSt|j��dz }|j|}|tks ||jvrdS|tkr8||jvr/|dkrd}n&|dz}|j|}|tkr ||jv�/ |dz }|j|}|���}|�d|j|j|jd���}||j|<||jdkrdS�m)NrSrrRT�StartTag)�typer� namespacer:) rg�lenrUrfrG� insertElementrr|r)r�i�entry�clonerZs r�#reconstructActiveFormattingElementsz/TreeBuilder.reconstructActiveFormattingElements�s;�� �,� � �F� ��-� .� .�� 2���-�a�0�� �F�?�?�e�t�'8�8�8� �F��v�o�o�%�t�/@�"@�"@��A�v�v���� ��F�A��1�!�4�E��v�o�o�%�t�/@�"@�"@� � ��F�A��1�!�4�E��O�O�%�%�E��(�(�*�27�*�7<��27�2B�*D�*D�E�E�G� 07�D� )�!� ,��$�7��;�;�;���' r c��|j���}|jr8|tkr1|j���}|jr|tk�+dSdSdSdSrJ)rg�poprU)rr�s r�clearActiveFormattingElementsz)TreeBuilder.clearActiveFormattingElementssn���-�1�1�3�3���+� 8������1�5�5�7�7�E��+� 8������� 8� 8� 8� 8��r c�d�|jddd�D]}|tkrn|j|kr|cS�dS)z�Check if an element exists between the end of the active formatting elements and the last marker. If it does, return it, else return falseNrRF)rgrUr)rr�items r�!elementInActiveFormattingElementsz-TreeBuilder.elementInActiveFormattingElements sQ�� �1�$�$�B�$�7� � �D��v�~�~�����d�"�"�� � � �#��ur c��|�|��}|j�|��|j�|��dSrJ)� createElementrfrXrlr7)r�tokenrZs r� insertRootzTreeBuilder.insertRootsH���$�$�U�+�+�� �� � ��)�)�)� � �!�!�'�*�*�*�*�*r c��|d}|d}|d}|�|||��}|j�|��dS)Nr�publicId�systemId)� doctypeClassrlr7)rr�rr�r��doctypes r� insertDoctypezTreeBuilder.insertDoctype sR���V�}����$����$���#�#�D�(�H�=�=�� � �!�!�'�*�*�*�*�*r c��|� |jd}|�|�|d����dS)NrRr:)rfr7� commentClass)rr�rs r� insertCommentzTreeBuilder.insertComment(s@�� �>��&�r�*�F����4�,�,�U�6�]�;�;�<�<�<�<�<r c��|d}|�d|j��}|�||��}|d|_|S)z.Create an element but don't insert it anywhererr|r:)�getrb� elementClassr�rr�rr|rZs rr�zTreeBuilder.createElement-sG���V�}���I�I�k�4�+@�A�A� ��#�#�D�)�4�4��"�6�]����r c��|jSrJ)�_insertFromTabler0s r�_getInsertFromTablezTreeBuilder._getInsertFromTable5s ���$�$r c�L�||_|r|j|_dS|j|_dS)zsSwitch the function used to insert an element from the normal one to the misnested table one and back againN)r��insertElementTabler~�insertElementNormal)rrs r�_setInsertFromTablezTreeBuilder._setInsertFromTable8s6��!&��� � :�!%�!8�D� � � �!%�!9�D� � � r c�J�|d}t|t��s Jd|z���|�d|j��}|�||��}|d|_|jd�|��|j�|��|S)NrzElement %s not unicoder|r:rR) rorr�rbr�rrfr7rXr�s rr�zTreeBuilder.insertElementNormalCs����V�}���$� �*�*�K�K�,D�t�,K�K�K�*��I�I�k�4�+@�A�A� ��#�#�D�)�4�4��"�6�]��� ��"��)�)�'�2�2�2� �� � ��)�)�)��r c�J�|�|��}|jdjtvr|�|��S|���\}}|�|�|��n|�||��|j�|��|S)z-Create an element and insert it into the treerR) r�rfrr r��getTableMisnestedNodePositionr7r;rX)rr�rZrr;s rr�zTreeBuilder.insertElementTableMs����$�$�U�+�+�� � �R� � %�-D� D� D��+�+�E�2�2� 2�$(�#E�#E�#G�#G� �F�L��#��"�"�7�+�+�+�+��#�#�G�\�:�:�:� � � $� $�W� -� -� -��r c���|� |jd}|jr |jr0|jdjtvr|�|��dS|���\}}|�||��dS)zInsert text data.NrR)rfrjrr r<r�)rr:rr;s rr<zTreeBuilder.insertText]s��� �>��&�r�*�F��$� 2��)=� 2�)-�):�2�)>�)C�0G�*H�*H� � � �d� #� #� #� #� #�$(�#E�#E�#G�#G� �F�L� � � �d�L� 1� 1� 1� 1� 1r c���d}d}d}|jddd�D]}|jdkr|}n�|r:|jr |j}|}n6|j|j�|��dz }n |jd}||fS)zsGet the foster parent element, and sibling to insert before (or None) when inserting a misnested table nodeNrRrrSr)rfrr�index)r� lastTable� fosterParentr;�elms rr�z)TreeBuilder.getTableMisnestedNodePositionls��� � �� �� ��$�T�T�r�T�*� � �C��x�7�"�"�� ���#� � 0��� <�(�/� �(� � �#�0��%�+�+�I�6�6��:� <� � � �,�Q�/�L��\�)�)r c��|jdj}|td��vr6||kr2|j���|�|��dSdSdS)NrR)�dd�dt�lirr�p�rp�rt)rfr� frozensetr��generateImpliedEndTags)r�excluders rr�z"TreeBuilder.generateImpliedEndTags�sn��� ��$�)�� �I�W�X�X� X� X����� � � !� !� #� #� #� � '� '�� 0� 0� 0� 0� 0� Y� X��r c��|jS)zReturn the final tree)rlr0s r� getDocumentzTreeBuilder.getDocument�s ���}�r c�n�|���}|jd�|��|S)zReturn the final fragmentr)� fragmentClassrfrE)r�fragments r� getFragmentzTreeBuilder.getFragment�s6���%�%�'�'�� ��!��-�-�h�7�7�7��r c��t�)z�Serialize the subtree of node in the format required by unit tests :arg node: the node from which to start serializing r3r5s r�testSerializerzTreeBuilder.testSerializer�r8r rJ)rKrLrMrNrkr�r�r�r�rrcrxr�r�r�r�r�r�r�r�r��propertyrjr�r�r<r�r�r�r�r�r%r rr`r`�s����������M��L��L��L��M� � � � -� -� -�����,,�,�,�\8�8�8� � � �+�+�+� +�+�+�=�=�=�=� ���%�%�%�:�:�:��h�2�4G�H�H�O������� 2� 2� 2� 2�*�*�*�41�1�1�1�������"�"�"�"�"r r`)� __future__rrr�sixr� constantsrr r rUr�rq�objectrrrPr`r%r r�<module>r�s���B�B�B�B�B�B�B�B�B�B�������L�L�L�L�L�L�L�L�L�L� �� �9�_� %� %�u� -��y��Z��-?��,J�+K�K�L�L�e�T� �Y��:�f�+=�t�*D�+5�f�+=�t�*D�*F�F�G�G�HM� O��i�*�V�,�f�5�$�V�,�g�6�8�9�9�:?�A��y�:�f�-�z�:�%�f�-�x�8�:�;�;�<@�B� � ��`"�`"�`"�`"�`"�6�`"�`"�`"�F�����t����0O"�O"�O"�O"�O"�&�O"�O"�O"�O"�O"r
Memory