� c��j V���dZddlZddlZddlmZdgZej d�Zej d�Zej d�Z ej d�Z ej d �Z ej d �Z ej d �Z ej d �Zej d �Zej d�Zej dej"�Zej dej"�Zej dej"�Zej d �Zej d�ZGd�dej.�Zy)zA parser for HTML and XHTML.�N)�unescape� HTMLParserz[&<]z &[a-zA-Z#]z%&([a-zA-Z][-.a-zA-Z0-9]*)[^a-zA-Z0-9]z)&#(?:[0-9]+|[xX][0-9a-fA-F]+)[^0-9a-fA-F]z <[a-zA-Z]z z--!?>z-?>z0([a-zA-Z][^\t\n\r\f />]*)(?:[\t\n\r\f ]|/(?!>))*a{ ( (?<=['"\t\n\r\f /])[^\t\n\r\f />][^\t\n\r\f /=>]* # attribute name ) ([\t\n\r\f ]*=[\t\n\r\f ]* # value indicator ('[^']*' # LITA-enclosed value |"[^"]*" # LIT-enclosed value |(?!['"])[^>\t\n\r\f ]* # bare value ) )? (?:[\t\n\r\f ]|/(?!>))* # possibly followed by a space a [a-zA-Z][^\t\n\r\f />]* # tag name [\t\n\r\f /]* # optional whitespace before attribute name (?:(?<=['"\t\n\r\f /])[^\t\n\r\f />][^\t\n\r\f /=>]* # attribute name (?:[\t\n\r\f ]*=[\t\n\r\f ]* # value indicator (?:'[^']*' # LITA-enclosed value |"[^"]*" # LIT-enclosed value |(?!['"])[^>\t\n\r\f ]* # bare value ) )? [\t\n\r\f /]* # possibly followed by a space )* >? aF <[a-zA-Z][^\t\n\r\f />\x00]* # tag name (?:[\s/]* # optional whitespace before attribute name (?:(?<=['"\s/])[^\s/>][^\s/=>]* # attribute name (?:\s*=+\s* # value indicator (?:'[^']*' # LITA-enclosed value |"[^"]*" # LIT-enclosed value |(?!['"])[^>\s]* # bare value ) \s* # possibly followed by a space )?(?:\s|/(?!>))* )* )? \s* # trailing whitespace z#c����eZdZdZdZdZddd��fd� Z�fd�Zd �Zd �Z d Z d �Z dd �d�Z d�Z d#d�Zd�Zd�Zd#d�Zd$d�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd �Zd!�Zd"�Z �xZ!S)%raEFind tags and other markup and call handler functions. Usage: p = HTMLParser() p.feed(data) ... p.close() Start tags are handled by calling self.handle_starttag() or self.handle_startendtag(); end tags by self.handle_endtag(). The data between tags is passed from the parser to the derived class by calling self.handle_data() with the data as argument (the data may be split up in arbitrary chunks). If convert_charrefs is True the character references are converted automatically to the corresponding Unicode character (and self.handle_data() is no longer split in chunks), otherwise they are passed by calling self.handle_entityref() or self.handle_charref() with the string containing respectively the named or numeric reference as the argument. )�script�style�xmp�iframe�noembed�noframes)�textarea�titleTF)�convert_charrefs� scriptingc�^��t�|��||_||_|j �y)azInitialize and reset this instance. If convert_charrefs is true (the default), all character references are automatically converted to the corresponding Unicode characters. If *scripting* is false (the default), the content of the ``noscript`` element is parsed normally; if it's true, it's returned as is without being parsed. N)�super�__init__rr�reset)�selfrr� __class__s ��$/usr/lib64/python3.12/html/parser.pyrzHTMLParser.__init__vs(��� ���� 0���"��� � � � �c���d|_d|_t|_d|_d|_d|_g|_d|_d|_ t�|�-�y)z1Reset this instance. Loses all unprocessed data.�z???NTr�) �rawdata�lasttag�interesting_normal� interesting� cdata_elem�_support_cdata� _escapable�_pending� _pending_len�_parse_thresholdrr)rrs �rrzHTMLParser.reset�sO����� ��� �-������"�������� ���� !��� �� �rc��|xjt|�z c_|j|jkr|jj |�y|js|xj |z c_nc|jj |�|xj dj |j�z c_|jj�d|_t|j �}|jd�t|j �|krd|_yt|j �|_y)z�Feed data to the parser. Call this as often as you want, with as little or as much text as you want (may include '\n'). rrrN) r$�lenr%r#�appendr�join�clear�goahead)r�data�ns r�feedzHTMLParser.feed�s��� ���S��Y�&�� � � �t�4�4� 4� �M�M� � �� &��=�=�� � ��$� �� � �$�$�T�*�� � ����� � � 6�6� �� � �#�#�%� !�D� ��D�L�L�!�A� �L�L��O��4�<�<� �1�$�()��%�),�D�L�L�(9��%rc���|jrO|xjdj|j�z c_|jj�d|_|j d�y)zHandle any buffered data.rrrN)r#rr)r*r$r+�rs r�closezHTMLParser.close�sG�� �=�=� �L�L�B�G�G�D�M�M�2� 2�L� �M�M� � � !� !�D� � � � �Q�rNc��|jS)z)Return full source of start tag: '<...>'.)�_HTMLParser__starttag_textr0s r�get_starttag_textzHTMLParser.get_starttag_text�s���#�#�#r�� escapablec���|j�|_||_|jdk(rtjd�|_y|rT|j sHtjd|jztjtjz�|_ytjd|jztjtjz�|_y)N� plaintextz\Zz&|])z])) �lowerr r"�re�compilerr� IGNORECASE�ASCII)r�elemr6s r�set_cdata_modezHTMLParser.set_cdata_mode�s����*�*�,���#��� �?�?�k� )�!�z�z�%�0�D� � �t�4�4�!�z�z�*D�t���*V�*,�-�-����*@� B�D� � "�z�z�*B�T�_�_�*T�*,�-�-����*@� B�D� rc�6�t|_d|_d|_y)NT)rrr r"r0s r�clear_cdata_modezHTMLParser.clear_cdata_mode�s��-��������rc��||_y)aEnable or disable support of the CDATA sections. If enabled, "<[CDATA[" starts a CDATA section which ends with "]]>". If disabled, "<[CDATA[" starts a bogus comments which ends with ">". This method is not called by default. Its purpose is to be called in custom handle_starttag() and handle_endtag() methods, with value that depends on the adjusted current node. See https://html.spec.whatwg.org/multipage/parsing.html#markup-declaration-open-state for details. N)r!)r�flags r�_set_support_cdatazHTMLParser._set_support_cdata�s ��#��rc� �|j}d}t|�}||k�r9|jrq|jse|j d|�}|dkr�|j dt ||dz ��}|dk\r'tjd�j||�s�n�|}n?|jj||�}|r|j�}n|jr�n|}||krJ|jr*|jr|jt|||��n|j|||�|j||�}||k(r�n|j }|d|��r=t"j%||�r|j'|�} n�|d|�r|j)|�} nt|d|�r|j+|�} nY|d|�r|j-|�} n>|d |�r|j/|�} n#|d z|ks|r|jd�|d z} n�nH| dk�rl|s�n>t"j%||�r�nN|d|�rK|d z|k(r|jd��n*t0j%||�r�n|j3||d zd�n�|d|�rF|}d D]'} |j5| |d z�s�|t| �z}n|j3||d z|�n�|d|�r$|j6r|j9||dzd�n~|||dzj;�dk(r|j=||d zd�nM|d |�r|j3||d zd�n,|d|�r|j?||d zd�n tAd��|} |j|| �}�n�|d|�r�tBj%||�}|rY|jE�d d} |jG| �|jI�} |d| d z �s| d z } |j|| �}���d||dvr,|j|||d z�|j||d z�}�n|d|�r�tJj%||�}|rW|jEd �} |jM| �|jI�} |d| d z �s| d z } |j|| �}���tNj%||�}|rE|rB|jE�||dk(r,|jI�} | |kr|} |j||d z�}n>|d z|kr'|jd�|j||d z�}nnJd��||kr��9|ra||kr\|jr*|jr|jt|||��n|j|||�|j||�}||d|_y)Nr�<�&�"z [\t\n\r\f ;]��>�w��O���A��(�(�/�/���;���� � � �A������A��1�u��(�(�T�_�_��$�$�X�g�a��l�%;�<��$�$�W�Q�q�\�2����q�!�$�A��A�v�u� �+�+�J��#�q�!��%�%�g�q�1��+�+�A�.�A���a�(��)�)�!�,�A����*��*�*�1�-�A���a�(�� � �a�(�A���a�(��3�3�A�6�A��!�e�q�[�C��$�$�S�)��A��A���q�5���#�)�)�'�1�5��#�D�!�,��q�5�A�:� �,�,�T�2�'�-�-�g�q�9� �!�/�/���!��� �>�#�F�A�.���&8�F�&�/�/���!��<� !�S��[� 0�� %�'9��+�+�G�A�a�C��N�;�#�K��3��8K�8K��)�)�'�!�A�#�$�-�8� ��1�Q�3��-�-�/�;�>��(�(���1����7�#�D�!�,��+�+�G�A�a�C�D�M�:�#�D�!�,����w�q��s�t�}�5�,�-F�G�G��A��N�N�1�a�(���D�!�$�� � �g�q�1��� �;�;�=��2�.�D��'�'��-�� � � �A�%�c�1�Q�3�/���E�����q�!�,�A���g�a�b�k�)��(�(���1�Q�3��8� �N�N�1�a��c�2����C��#�!�����3��� �;�;�q�>�D��)�)�$�/�� � � �A�%�c�1�Q�3�/���E�����q�!�,�A��"�(�(��!�4����u�{�{�}���� �;�!�I�I�K����6� !�A� �N�N�1�a�!�e�4����!�e�q�[��$�$�S�)����q�!�a�%�0�A��5�5�5�q�w�!�e�z �1�q�5��$�$����� � ��'�!�A�,�!7�8�� � ���1��.����q�!�$�A��q�r�{�� rc��|j}|||dzdk(sJd��|||dzdk(r|j|�S|||dzdk(rC|jr7|jd|dz�}|d kry |j ||d z|�|d zS|||dzj �d k(r7|jd |dz�}|d k(ry |j ||dz|�|dzS|||d zdk(ra|jd |d z�}|d kry ||dz dk(r|j ||d z|dz �|dzS|j||dz|�|dzS|j|�S)NrMrLz+unexpected call to parse_html_declaration()rOrJrRrPz]]>rrTrQrSrrz�V� #��%�%�a�(� (� �Q�q��s�^�{� *�t�/B�/B�� � �U�A�a�C�(�A��1�u�� � � �g�a��c�1�o� .��q�5�L� �Q�q��s�^� !� !� #�{� 2��L�L��a��c�*�E���{�� � � �W�Q�q�S��/� 0���7�N� �Q�q��s�^�u� $�� � �S�!�A�#�&�A��1�u���q��s�|�s�"��!�!�'�!�A�#�q��s�"3�4��q�5�L��#�#�G�A�a�C��O�4��q�5�L��+�+�A�.� .rc�,�|j}|jd|�sJd��tj||dz�}|stj ||dz�}|sy|r'|j �}|j||dz|�|j�S)NrJ�"unexpected call to parse_comment()rOrT) rr]� commentcloserY�commentabruptcloser_rZrfro)rrs�reportrr_rts rrbzHTMLParser.parse_comment�s����,�,���!�!�&�!�,�R�.R�R�,��#�#�G�Q�q�S�1���&�,�,�W�a��c�:�E��� �� � � �A� � � ���!��Q�� 0��y�y�{�rc��|j}|||dzdvsJd��|jd|dz�}|dk(ry|r|j||dz|�|dzS)NrM)rLrIr~rrTr)rrVrf)rrsr�r�poss rr{zHTMLParser.parse_bogus_comment�su���,�,���q��1��~��-� C�1B� C�-��l�l�3��!��$�� �"�9�� � � � ���!��C� 0� 1��Q�w�rc���|j}|||dzdk(sJd��tj||dz�}|sy|j�}|j ||dz|�|j �}|S)NrMrKzunexpected call to parse_pi()rT)r�picloserYrZrjro�rrsrr_rts rrczHTMLParser.parse_pi�st���,�,���q��1��~��%�F�'F�F�%����w��!��,���� �K�K�M�� ���w�q��s�A��'� �I�I�K���rc���d|_|j|�}|dkr|S|j}||||_g}tj ||dz�}|sJd��|j �}|j d�j�x|_}||kr�tj ||�}|sn�|j ddd�\} } } | sd} n,| dddcxk(r| ddk(sn| dddcxk(r| ddk(rnn| dd} | r t| �} |j| j�| f�|j �}||kr��|||j�} | d vr|j|||�|S| jd �r|j||�|S|j!||�||j"vs|j$r|d k(s|d k(r|j'|d ��|S||j(vr|j'|d��|S)Nrrz#unexpected call to parse_starttag()rMrQ�'rT�")r�/>r��noscriptr8Fr5T)r3�check_for_whole_start_tagr�tagfind_tolerantr_rormr9r�attrfind_tolerantrr(�stripr[rg�handle_startendtag�handle_starttag�CDATA_CONTENT_ELEMENTSrr?�RCDATA_CONTENT_ELEMENTS) rrs�endposr�attrsr_rv�tag�m�attrname�rest� attrvalueros rr`zHTMLParser.parse_starttag�s�� $����/�/��2�� �A�:��M��,�,��&�q��0����� �&�&�w��!��4���;�;�;�u� �I�I�K��"�[�[��^�1�1�3�3�� �s��&�j�!�'�'���3�A���()����1�a�(8� %�H�d�I�� � ��2�A��$�8�)�B�C�.�8��2�A��#�7��2�3��7�%�a��O� ��$�Y�/� � �L�L�(�.�.�*�I�6� 7�����A��&�j��a���%�%�'�� �k� !� � � �W�Q�v�.� /��M� �<�<�� � � #� #�C�� /�� � � � ��e� ,��t�2�2�2����C�:�$5��{�"��#�#�C�5�#�9�� ���4�4�4��#�#�C�4�#�8�� rc��|j}tj||dz�}|sJ�|j�}||dz dk7ry|S)NrrrT)r� locatetagendr_ror�s rr�z$HTMLParser.check_for_whole_start_tag�sK���,�,���"�"�7�A�a�C�0��� �u� �I�I�K�� �1�Q�3�<�3� ���rc��|j}|||dzdk(sJd��|jd|dz�dkrytj||�s$||dz|dzdk(r|dzS|j |�St j||dz�}|sJ�|j �}||dz dk7rytj||dz�}|sJ�|jd�j�}|j|�|j�|S) NrMrIzunexpected call to parse_endtagrrrTrQr) rrVrer_r{r�ror�rmr9� handle_endtagrA)rrsrr_rtr�s rrazHTMLParser.parse_endtag�s���,�,���q��1��~��%�H�'H�H�%� �<�<��Q�q�S� !�A� %�������+��q��s�1�Q�3��3�&���s� ��/�/��2�2��"�"�7�A�a�C�0��� �u� �I�I�K�� �1�Q�3�<�3� ��!�&�&�w��!��4��� �u��k�k�!�n�"�"�$�� ���3�� �����rc�J�|j||�|j|�y�N)r�r��rr�r�s rr�zHTMLParser.handle_startendtags �� ���S�%�(� ���3�rc��yr��r�s rr�zHTMLParser.handle_starttag��� rc��yr�r�)rr�s rr�zHTMLParser.handle_endtagr�rc��yr�r��rrxs rrnzHTMLParser.handle_charrefr�rc��yr�r�r�s rrqzHTMLParser.handle_entityrefr�rc��yr�r��rr,s rr[zHTMLParser.handle_data#r�rc��yr�r�r�s rrfzHTMLParser.handle_comment'r�rc��yr�r�)r�decls rrizHTMLParser.handle_decl+r�rc��yr�r�r�s rrjzHTMLParser.handle_pi/r�rc��yr�r�r�s rrhzHTMLParser.unknown_decl2r�r)T)r)"�__name__� __module__� __qualname__�__doc__r�r�rrr.r1r3r4r?rArDr+rdrbr{rcr`r�rar�r�r�rnrqr[rfrirjrh� __classcell__)rs@rrrZs�����0Y��3��+/�5� � �:�<��O�$�16� B�� #� G#�X/�D � � �.�d��< �  � � � � � � � � r)r�r:� _markupbase�htmlr�__all__r;rrrrprlr^rer�rr�r��VERBOSEr�r��locatestarttagend_tolerant� endendtag� endtagfind� ParserBaserr�rr�r�s[��"� ��� �.�� �R�Z�Z��'�� �R�Z�Z� � %� � �B�J�J�>� ?� � �"�*�*�@� A���r�z�z�+�&� � �R�Z�Z� � %� � �"�*�*�S�/���r�z�z�(�#� ��R�Z�Z��'���2�:�:�Q�R���B�J�J� ��Z�Z� ���r�z�z� ��Z�Z� � � (�R�Z�Z�)��Z�Z��� �B�J�J�s�O� � �R�Z�Z�>� ?� �Y ��'�'�Y r