� K�g�=���ddlmZmZmZddlmZddlZddlmZm Z ddl m Z m Z m Z ddl mZmZmZddlmZmZdd lmZd �e ��d zZejd ezd z��Zejd ezdz��ZiZed��dkZeej����D]v\Z Z!eree!��dksesee!��dkr�(e!dkrHee!��dkrej"e!��Z!n e#e!��Z!e!evse �$��re ee!<�wd�Z%ede%��dd�Z&Gd�de'��Z(Gd�de)��Z*dS)�)�absolute_import�division�unicode_literals)� text_typeN)�register_error�xmlcharrefreplace_errors�)� voidElements�booleanAttributes�spaceCharacters)�rcdataElements�entities� xmlEntities)� treewalkers�_utils)�escape�z"'=<>`�[�]u_  /`  ᠎᠏           

   ]u􏿿��&c �`�t|ttf���r�g}g}d}t|j|j|j���D]�\}}|rd}� ||jz}tj|j|t|j|dzg�����r'tj |j||dz���}d}nt|��}|� |����|D]�}t�|��} | rU|� d��|� | ��| �d��s|� d���s|� dt!|��dd�z����d�|��|jfSt%|��S)NFrTr�;z&#x%s;r)� isinstance�UnicodeEncodeError�UnicodeTranslateError� enumerate�object�start�endr�isSurrogatePair�min�surrogatePairToCodepoint�ord�append�_encode_entity_map�get�endswith�hex�joinr) �exc�res� codepoints�skip�i�c�index� codepoint�cp�es �c/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/html5lib/serializer.py�htmlentityreplace_errorsr6*s����#�*�,A�B�C�C�-���� ����c�j���3�7�):�;�<�<� )� )�D�A�q�� ������ �M�E��%�c�j��s�C�G�U�Q�Y�;O�7P�7P�1P�&Q�R�R� #�"�;�C�J�u�U�UV�Y��<W�X�X� ������F�F� � � � �i� (� (� (� (�� 5� 5�B�"�&�&�r�*�*�A�� 5�� � �3����� � �1� � � ��z�z�#���$��J�J�s�O�O�O��� � �8�s�2�w�w�q�r�r�{�3�4�4�4�4����� � �c�g�&�&�'��,�,�,��htmlentityreplace�etreec ��tj|��}tdi|��}|�||��|��S)a�Serializes the input token stream using the specified treewalker :arg input: the token stream to serialize :arg tree: the treewalker to use :arg encoding: the encoding to use :arg serializer_opts: any options to pass to the :py:class:`html5lib.serializer.HTMLSerializer` that gets created :returns: the tree serialized as a string Example: >>> from html5lib.html5parser import parse >>> from html5lib.serializer import serialize >>> token_stream = parse('<html><body><p>Hi!</p></body></html>') >>> serialize(token_stream, omit_optional_tags=False) '<html><head></head><body><p>Hi!</p></body></html>' �)r� getTreeWalker�HTMLSerializer�render)�input�tree�encoding�serializer_opts�walker�ss r5� serializerEKsC��0� &�t� ,� ,�F��)�)��)�)�A� �8�8�F�F�5�M�M�8� ,� ,�,r7c�t�eZdZdZdZdZdZdZdZdZ dZ dZ dZ dZ dZdZdZdZd�Zd�Zd�Zdd �Zdd �Zdd �Zd S)r=�legacy�"TF)�quote_attr_values� quote_char�use_best_quote_char�omit_optional_tags�minimize_boolean_attributes�use_trailing_solidus�space_before_trailing_solidus�escape_lt_in_attrs� escape_rcdata�resolve_entities�alphabetical_attributes�inject_meta_charset�strip_whitespace�sanitizec �x�t|��t|j��z }t|��dkr,tdt t |����z���d|vrd|_|jD]5}t|||�|t||�������6g|_ d|_ dS)aB Initialize HTMLSerializer :arg inject_meta_charset: Whether or not to inject the meta charset. Defaults to ``True``. :arg quote_attr_values: Whether to quote attribute values that don't require quoting per legacy browser behavior (``"legacy"``), when required by the standard (``"spec"``), or always (``"always"``). Defaults to ``"legacy"``. :arg quote_char: Use given quote character for attribute quoting. Defaults to ``"`` which will use double quotes unless attribute value contains a double quote, in which case single quotes are used. :arg escape_lt_in_attrs: Whether or not to escape ``<`` in attribute values. Defaults to ``False``. :arg escape_rcdata: Whether to escape characters that need to be escaped within normal elements within rcdata elements such as style. Defaults to ``False``. :arg resolve_entities: Whether to resolve named character entities that appear in the source tree. The XML predefined entities &lt; &gt; &amp; &quot; &apos; are unaffected by this setting. Defaults to ``True``. :arg strip_whitespace: Whether to remove semantically meaningless whitespace. (This compresses all whitespace to a single space except within ``pre``.) Defaults to ``False``. :arg minimize_boolean_attributes: Shortens boolean attributes to give just the attribute value, for example:: <input disabled="disabled"> becomes:: <input disabled> Defaults to ``True``. :arg use_trailing_solidus: Includes a close-tag slash at the end of the start tag of void elements (empty elements whose end tag is forbidden). E.g. ``<hr/>``. Defaults to ``False``. :arg space_before_trailing_solidus: Places a space immediately before the closing slash in a tag using a trailing solidus. E.g. ``<hr />``. Requires ``use_trailing_solidus=True``. Defaults to ``True``. :arg sanitize: Strip all unsafe or unknown constructs from output. See :py:class:`html5lib.filters.sanitizer.Filter`. Defaults to ``False``. :arg omit_optional_tags: Omit start/end tags that are optional. Defaults to ``True``. :arg alphabetical_attributes: Reorder attributes to be in alphabetical order. Defaults to ``False``. rz2__init__() got an unexpected keyword argument '%s'rJFN) � frozenset�options�len� TypeError�next�iterrK�setattrr'�getattr�errors�strict)�self�kwargs�unexpected_args�attrs r5�__init__zHTMLSerializer.__init__�s���^$�F�+�+�i�� �.E�.E�E�� �� � �!� #� #��P�SW�X\�]l�Xm�Xm�Sn�Sn�n�o�o� o� �6� !� !�',�D� $��L� G� G�D� �D�$�� � �4���t�1D�1D� E� E� F� F� F� F��� ��� � � r7c�x�t|t��sJ�|jr|�|jd��S|S)Nr8�rrrA�encode�rb�strings r5rizHTMLSerializer.encode�s>���&�)�,�,�-�-�,� �=� ��=�=���0C�D�D� D��Mr7c�x�t|t��sJ�|jr|�|jd��S|S)Nrarhrjs r5� encodeStrictzHTMLSerializer.encodeStrict�s=���&�)�,�,�-�-�,� �=� ��=�=����9�9� 9��Mr7Nc#�� K�||_d}g|_|r|jrddlm}|||��}|jrddlm}||��}|jrddlm}||��}|j rddl m}||��}|j rddl m}||��}|D�]h}|d}|dkr�d|dz}|dr|d |dzz }n |d r|d z }|d rj|d � d ��d kr7|d � d��d kr|�d��d}nd }|d|�|d �|��z }|dz }|�|��V���|dvr�|dks|rU|r4|d� d��d kr|�d��|�|d��V���0|�t#|d����V���\|dv�r�|d} |�d| z��V�| t$vr |jsd}n|r|�d��|d���D�] \\} } } | } | }|�d��V�|�| ��V�|jrH| t-j| t1����v�r�| t-jdt1����v�r�|�d��V�|jdkst5|��d krd}n_|jdkrt6�|��du}n7|jdkrt:�|��du}nt=d ���|�d!d"��}|j r|�d#d$��}|r�|j!}|j"rd|vrd |vrd }n d |vrd|vrd}|dkr|�dd%��}n|�d d&��}|�|��V�|�|��V�|�|��V����|�|��V��� | tFvr=|j$r6|j%r|�d'��V�n|�d(��V�|�d��V���2|d)krG|d} | t$vrd}n|r|�d��|�d*| z��V���|d+krX|d}|� d,��d kr|�d-��|�d.|dz��V����|d/krj|d} | d0z}|tLvr|�d1| z��|j'r|tPvrtL|}nd2| z}|�|��V���M|�|d����jdS)3NFr )�Filter�type�Doctypez <!DOCTYPE %s�name�publicIdz PUBLIC "%s"�systemIdz SYSTEMrHr�'zBSystem identifier contains both single and double quote characters� �>)� Characters�SpaceCharactersry�dataz</zUnexpected </ in CDATA)�StartTag�EmptyTagz<%sTz+Unexpected child element of a CDATA elementr�=�always�specrGz?quote_attr_values must be one of: 'always', 'spec', or 'legacy'rz&amp;�<z&lt;z&#39;z&quot;z /�/�EndTagz</%s>�Commentz--zComment contains --z <!--%s-->�EntityrzEntity %s not recognizedz&%s;))rAr`rT�filters.inject_meta_charsetrorS�filters.alphabeticalattributesrU�filters.whitespacerV�filters.sanitizerrL�filters.optionaltags�find�serializeErrorrmrirr rQ�itemsrMr r'�tuplerIrZ�_quoteAttributeSpec�search�_quoteAttributeLegacy� ValueError�replacerPrJrKr rNrOrrRr)rb� treewalkerrA�in_cdataro�tokenrp�doctyperJrr�_� attr_name� attr_value�k�v� quote_attrrz�keys r5rEzHTMLSerializer.serialize�su���� �� ����� � � 6��0� 6� ;� ;� ;� ;� ;� ;��� �H�5�5�J� � '� ,� >� >� >� >� >� >��� �+�+�J� � � ,� 2� 2� 2� 2� 2� 2��� �+�+�J� �=� ,� 1� 1� 1� 1� 1� 1��� �+�+�J� � "� ,� 4� 4� 4� 4� 4� 4��� �+�+�J��l 3�l 3�E���=�D��y� � �(�5��=�8����$�)��~��j�0A�A�A�G�G��:�&�)��y�(�G���$�W��Z�(�-�-�c�2�2�a�7�7� ��,�1�1�#�6�6�!�;�;� �/�/�0t�u�u�u�%(� � �%(� ��G�J�J��j�8I�8I�:�:�V�V�G��3����'�'��0�0�0�0�0�0��:�:�:��,�,�,��,��F�E�&�M�$6�$6�t�$<�$<��$A�$A��+�+�,D�E�E�E��+�+�e�F�m�4�4�4�4�4�4��+�+�f�U�6�]�&;�&;�<�<�<�<�<�<��1�1�1��V�}���'�'��� �5�5�5�5�5��>�)�)�$�2D�)�#�H�H��W��'�'�(U�V�V�V�27��-�2E�2E�2G�2G�&1�&1�.�N�Q� �J�!�A�"�A��+�+�C�0�0�0�0�0��+�+�A�.�.�.�.�.��;�1��"3�"7��e�g�g�"F�"F�F�F��"3�"7��E�G�G�"D�"D�D�D�"�/�/��4�4�4�4�4��1�X�=�=��Q���1���)-�J�J�!�3�v�=�=�)<�)C�)C�A�)F�)F�d�)R�J�J�!�3�x�?�?�)>�)E�)E�a�)H�)H�PT�)T�J�J�",�.M�#N�#N�N��I�I�c�7�3�3���2�7� !� � �#�v� 6� 6�A�%�1�)-��J�#�7�5�#&�!�8�8��1� � �14�J�J�%(�A�X�X�#�Q�,�,�14�J�)�S�0�0�$%�I�I�c�7�$;�$;���$%�I�I�c�8�$<�$<��"&�"3�"3�J�"?�"?�?�?�?�"&�+�+�a�.�.�0�0�0�"&�"3�"3�J�"?�"?�?�?�?�?�"&�+�+�a�.�.�0�0�0���<�'�'�D�,E�'��9�5�"�/�/��5�5�5�5�5�5�"�/�/��4�4�4�4�4��k�k�#�&�&�&�&�&�&���!�!��V�}���>�)�)�$�H�H��W��'�'�(U�V�V�V��'�'��$��7�7�7�7�7�7���"�"��V�}���9�9�T�?�?�a�'�'��'�'�(=�>�>�>��'�'� �e�F�m�(C�D�D�D�D�D�D���!�!��V�}���S�j���h�&�&��'�'�(B�T�(I�J�J�J��(�)�S� �-C�-C�#�C�=�D�D�!�D�=�D��'�'��-�-�-�-�-�-��#�#�E�&�M�2�2�2�2�Yl 3�l 3r7c���|r6d�t|�||������Sd�t|�|������S)anSerializes the stream from the treewalker into a string :arg treewalker: the treewalker to serialize :arg encoding: the string encoding to use :returns: the serialized tree Example: >>> from html5lib import parse, getTreeWalker >>> from html5lib.serializer import HTMLSerializer >>> token_stream = parse('<html><body>Hi!</body></html>') >>> walker = getTreeWalker('etree') >>> serializer = HTMLSerializer(omit_optional_tags=False) >>> serializer.render(walker(token_stream)) '<html><head></head><body>Hi!</body></html>' r7r)r*�listrE)rbr�rAs r5r>zHTMLSerializer.renderwsZ��( � =��8�8�D���� �H�!E�!E�F�F�G�G� G��7�7�4����z� :� :�;�;�<�<� <r7�XXX ERROR MESSAGE NEEDEDc�V�|j�|��|jrt�dS�N)r`r%ra�SerializeError)rbrzs r5r�zHTMLSerializer.serializeError�s2�� � ���4� � � � �;� !� � � !� !r7r�)r�)�__name__� __module__� __qualname__rIrJrKrLrMrNrOrPrQrRrSrTrUrVrYrfrirmrEr>r�r;r7r5r=r=hs�������!���J�����"&�� ��$(�!����M���$�������H�/�G�W�W�W�r������G3�G3�G3�G3�R=�=�=�=�2!�!�!�!�!�!r7r=c��eZdZdZdS)r�zError in serialized treeN)r�r�r��__doc__r;r7r5r�r��s������"�"��Dr7r�)r9N)+� __future__rrr�sixr�re�codecsrr� constantsr r r r rrrrr�xml.sax.saxutilsrr*�_quoteAttributeSpecChars�compiler�r�r&rZ�_is_ucs4r�r�r�r�r#r$�islowerr6rErr=� Exceptionr�r;r7r5�<module>r�s���B�B�B�B�B�B�B�B�B�B������� � � � �;�;�;�;�;�;�;�;�G�G�G�G�G�G�G�G�G�G�<�<�<�<�<�<�<�<�<�<�!�!�!�!�!�!�!�!�#�#�#�#�#�#��7�7�?�3�3�i�?�� �b�j��'?�!?�#�!E�F�F��"�� �3�)A�#A�$-�$-�.�.���� �3�|� � �� !�� �D����!�!� "� "� &� &�D�A�q� ��c�c�!�f�f�q�j�j��!�!�c�!�f�f�q�j�j���C�x�x� �3�q�6�6�Q�;�;�/��/��2�2�A�A���A���A� �&� &� &�!�)�)�+�+� &�$%� �q� !��-�-�-�<��"�$<�=�=�=�-�-�-�-�:l!�l!�l!�l!�l!�V�l!�l!�l!�^  � � � � �Y� � � � � r7
Memory