� c��j V � � � d Z ddlZddlZddlmZ dgZ ej d� Z ej d� Z ej d� Z ej d� Z ej d � Z ej d � Z ej d� Z ej d� Z ej d � Z ej d� Z ej dej" � Z ej dej" � Z ej dej" � Z ej d� Z ej d� Z G d� 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 [a-zA-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#\s*([a-zA-Z][-.a-zA-Z0-9:_]*)\s*>c �� � � e Zd ZdZdZdZddd�� fd� Z� fd�Zd � Zd � Z dZ d� Zdd �d�Zd� 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 )%r aE Find 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)az Initialize 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__r r �reset)�selfr r � __class__s ��$/usr/lib64/python3.12/html/parser.pyr zHTMLParser.__init__v s( �� � ���� 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_thresholdr r )r r s �r r zHTMLParser.reset� sO �� �������-������"�������� ���� !��� �� �r c � � | xj t |� z c_ | j | j k r| j j |� y| j s| xj |z c_ nc| j j |� | xj dj | j � z c_ | j j � d| _ t | j � }| j d� t | j � |k rd| _ 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'). r r r N) 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��%r c �� � | j rO| xj dj | j � z c_ | j j � d| _ | j d� y)zHandle any buffered data.r r r N)r# r r) r* r$ r+ �r s r �closezHTMLParser.close� sG � ��=�=��L�L�B�G�G�D�M�M�2�2�L��M�M���!� !�D�����Q�r Nc � � | j S )z)Return full source of start tag: '<...>'.)�_HTMLParser__starttag_textr0 s r �get_starttag_textzHTMLParser.get_starttag_text� s � ��#�#�#r �� escapablec �� � |j � | _ || _ | j dk( rt j d� | _ y |rT| j sHt j d| j z t j t j z � | _ y t j d| j z t j t j z � | _ y )N� plaintextz\Zz&|%s(?=[\t\n\r\f />])z%s(?=[\t\n\r\f />])) �lowerr r" �re�compiler r � IGNORECASE�ASCII)r �elemr6 s 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�r c �6 � t | _ d | _ d| _ y )NT)r r r r" r0 s r �clear_cdata_modezHTMLParser.clear_cdata_mode� s � �-��������r c � � || _ y)a Enable 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 � � #��r c � � | j }d}t |� }||k �r9| j rq| j se|j d|� }|dk r�|j dt ||dz � � }|dk\ r't j d� j ||� s�n�|}n?| j j ||� }|r|j � }n| j r�n|}||k rJ| j r*| j r| j t ||| � � 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 |k s|r| j d� |d z } n�nH| dk �rl|s�n>t" j% ||� r�nN |d|� rK|dz |k( r| j d� �n*t0 j% ||� r�n| j3 ||dz d � n� |d|� rF|}dD ]' } |j5 | |d z � s�|t | � z } n | j3 ||d z | � n� |d|� r$| j6 r| j9 ||dz d � n~|||dz j; � dk( r| j= ||dz d � nM |d |� r| j3 ||dz d � n, |d|� r| j? ||dz d � ntA d� �|} | j || � }�n� |d|� r�tB j% ||� }|rY|jE � dd }| jG |� |jI � } |d| d z � s| d z } | j || � }���d||d v r,| j |||dz � | j ||dz � }�n |d|� r�tJ j% ||� }|rW|jE d � }| jM |� |jI � } |d| d z � s| d z } | j || � }���tN j% ||� }|rE|rB|jE � ||d k( r,|jI � } | |k r|} | j ||d z � }n>|d z |k r'| j d� | j ||d z � }nnJ d� �||k r��9|ra||k r\| j r*| j r| j t ||| � � n| j ||| � | j ||� }||d | _ y )Nr �<�&�" z[\t\n\r\f ;]�ú