U e!@spdZddlZddlZddlmZddlmZddlm Z ddl m Z m Z m Z zeZWnek rpeefZYnXzddlmZWn ek rddlmZYnXzddlmZWn ek rddlmZYnXGd d d eZzdd lmZWnek r YnXGd d d eZeZddZdddZdddZdddZd ddZ d!ddZ!ddZ"eZ#dS)"z? An interface to html5lib that mimics the lxml.html interface. N) HTMLParser) TreeBuilder)etree)ElementXHTML_NAMESPACE_contains_block_level_tag)urlopen)urlparsec@seZdZdZdddZdS)rz*An html5lib HTML parser with lxml as tree.FcKstj|f|td|dSN)stricttree) _HTMLParser__init__rselfr kwargsrE/opt/hc_python/lib64/python3.8/site-packages/lxml/html/html5parser.pyrszHTMLParser.__init__N)F__name__ __module__ __qualname____doc__rrrrrrsr) XHTMLParserc@seZdZdZdddZdS)rz+An html5lib XHTML Parser with lxml as tree.FcKstj|f|td|dSr ) _XHTMLParserrrrrrrr*szXHTMLParser.__init__N)Frrrrrr'srcCs(||}|dk r|S|dt|fS)Nz{%s}%s)findr)r tagelemrrr _find_tag0s rcCsZt|tstd|dkrt}i}|dkr8t|tr8d}|dk rH||d<|j|f|S)z Parse a whole document into a string. If `guess_charset` is true, or if the input is not Unicode but a byte string, the `chardet` library will perform charset guessing on the string. string requiredNT useChardet) isinstance_strings TypeError html_parserbytesparseZgetroot)html guess_charsetparseroptionsrrrdocument_fromstring7s r+FcCst|tstd|dkrt}i}|dkr8t|tr8d}|dk rH||d<|j|df|}|rt|dtr|r|drtd|d|d=|S)a`Parses several HTML elements, returning a list of elements. The first item in the list may be a string. If no_leading_text is true, then it will be an error if there is leading text, and it will always be a list of only elements. If `guess_charset` is true, the `chardet` library will perform charset guessing on the string. rNFr divrzThere is leading text: %r) r!r"r#r$r%Z parseFragmentstripr ParserError)r'no_leading_textr(r)r*childrenrrrfragments_fromstringOs$  r1cCst|tstdt|}t|||| d}|rvt|ts>d}t|}|rrt|dtrh|d|_|d=|||S|st dt |dkrt d|d}|j r|j rt d|j d |_ |S) aParses a single HTML element; it is an error if there is more than one element, or if anything but whitespace precedes or follows the element. If 'create_parent' is true (or is a tag name) then a parent node will be created to encapsulate the HTML in a single element. In this case, leading or trailing text is allowed. If `guess_charset` is true, the `chardet` library will perform charset guessing on the string. r)r(r)r/r,rzNo elements foundzMultiple elements foundzElement followed by text: %rN) r!r"r#boolr1rtextextendrr.lentailr-)r'Z create_parentr(r)Zaccept_leading_textelementsnew_rootresultrrrfragment_fromstringqs8       r;cCst|tstdt|||d}|dd}t|trB|dd}|}|dsb|drf|St |d }t |r||St |d }t |d kr|j r|j s|d j r|d j s|d St|rd|_nd|_|S)aParse the html, returning a single element/document. This tries to minimally parse the chunk of text, without knowing if it is a fragment or a document. 'base_url' will set the document's base_url attribute (and the tree's docinfo.URL) If `guess_charset` is true, or if the input is not Unicode but a byte string, the `chardet` library will perform charset guessing on the string. r)r)r(N2asciireplacezsN     " , 6 $