• File: html5parser.cpython-37.pyc
  • Full Path: /home3/farmfre2/public_html/ALFA_DATA/alfasymlink/root/opt/alt/python37/lib64/python3.7/site-packages/lxml/html/__pycache__/html5parser.cpython-37.pyc
  • Date Modified: 04/24/2023 6:38 PM
  • File size: 6.32 KB
  • MIME-type: text/x-bytecode.python
  • Charset: 8 bit
B

'Y!@spdZddlZddlZddlmZddlmZddlm	Z	ddl
mZmZm
Z
yeZWnek
rpeefZYnXyddlmZWn ek
rddlmZYnXyddlmZWn ek
rddlmZYnXGd	d
d
eZyddlmZWnek
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|dS)N)stricttree)_HTMLParser__init__r)selfr
kwargsrH/opt/alt/python37/lib64/python3.7/site-packages/lxml/html/html5parser.pyr
szHTMLParser.__init__N)F)__name__
__module____qualname____doc__r
rrrrrsr)XHTMLParserc@seZdZdZdddZdS)rz+An html5lib XHTML Parser with lxml as tree.FcKstj|f|td|dS)N)r
r)_XHTMLParserr
r)rr
rrrrr
*szXHTMLParser.__init__N)F)rrrrr
rrrrr'srcCs(||}|dk	r|S|dt|fS)Nz{%s}%s)findr)rtagelemrrr	_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.
    zstring requiredNT
useChardet)
isinstance_strings	TypeErrorhtml_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.
    zstring requiredNFrdivrzThere is leading text: %r)	rrrr r!Z
parseFragmentstriprParserError)r#no_leading_textr$r%r&Zchildrenrrrfragments_fromstringOs"
r,cCst|tstdt|}t||||d}|rvt|ts>d}t|}|rrt|dtrh|d|_|d=|||S|st	dt
|dkrt	d|d}|jr|jrt	d|jd	|_|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.
    zstring required)r$r%r+r(rzNo elements foundzMultiple elements foundzElement followed by text: %rN)
rrrboolr,rtextextendrr*lentailr))r#Z
create_parentr$r%Zaccept_leading_textelementsZnew_rootresultrrrfragment_fromstringqs2






r5cCst|tstdt|||d}|dd}t|trB|dd}|}|dsb|drf|St	|d	}t
|r||St	|d
}t
|dkr|jr|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.
    zstring required)r%r$N2asciireplacez<htmlz	<!doctypeheadbodyr-rr(span)rrrr'r!decodelstriplower
startswithrr1r/r)r2rr)r#r$r%docstartr9r:rrr
fromstrings*



rCcCsz|dkrt}t|ts(|}|dkr\d}n4t|rFt|}|dkr\d}nt|d}|dkr\d}i}|rl||d<|j|f|S)a*Parse a filename, URL, or file-like object into an HTML document
    tree.  Note: this returns a tree, not an element.  Use
    ``parse(...).getroot()`` to get the document root.

    If ``guess_charset`` is true, the ``useChardet`` option is passed into
    html5lib to enable character detection.  This option is on by default
    when parsing from URLs, off by default when parsing from file(-like)
    objects (which tend to return Unicode more often than not), and on by
    default when parsing from a file path (which is read in binary mode).
    NFTrbr)r rr_looks_like_urlropenr")Zfilename_url_or_filer$r%fpr&rrrr"s"

r"cCs@t|d}|sdStjdkr8|tjkr8t|dkr8dSdSdS)NrFZwin32r-T)r	sysplatformstringZ
ascii_lettersr1)strZschemerrrrEs

rE)NN)FNN)FNN)NN)NN)$rrHrJZhtml5librrZ html5lib.treebuilders.etree_lxmlrZlxmlrZ	lxml.htmlrrrZ
basestringr	NameErrorr!rKZurllib2rImportErrorZurllib.requestr	Zurllib.parserrZxhtml_parserrr'r,r5rCr"rEr rrrr<module>sF

!
+
6
$