Wj 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 fdZd Zd Z dZ d Zdd dZd Z d#dZd Zd Zd#dZd$dZd 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. )scriptstylexmpiframenoembednoframes)textareatitleTF)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 )rawdatalasttaginteresting_normalinteresting 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)zFeed 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 joincleargoahead)r datans r feedzHTMLParser.feed s SY&t444MM &==$ $$T* 66 ##% !DDLL!ALLO4<< 1$()% ),DLL(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 ==LLBGGDMM22LMM! !DQr 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" recompiler r IGNORECASEASCII)r elemr6 s r set_cdata_modezHTMLParser.set_cdata_mode s **,#??k)!zz%0D t44!zz*Dt*V*,--*@ BD "zz*BT__*T*,--*@ BDr 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 || sn|}n?| j j || }|r|j }n| j rn|}||k rJ| j r*| j r| j t ||| n| j ||| | j || }||k( rn|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 } nnH| dk rl|sn>t" j% || rnN |d| rK|dz |k( r| j d n*t0 j% || rn| 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| rtB j% || }|rY|jE dd }| jG | |jI } |d| d z s| d z } | j || }d||d v r,| j |||dz | j ||dz }n |d| rtJ 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 r9|ra||k r\| j r*| j r| j t ||| n| j ||| | j || }||d | _ y )Nr <&" z[\t\n\r\f ;]