HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: //usr/local/lib64/python3.8/site-packages/lxml/html/__pycache__/html5parser.cpython-38.pyc
U

O��i�!�@spdZddlZddlZddlmZddlmZddlm	Z	ddl
mZmZm
Z
zeZWnek
rpeefZYnXzddlmZWn ek
r�ddlmZYnXzddlmZWn ek
r�ddlmZYnXGd	d
�d
e�ZzddlmZWnek
�rYnXGdd
�d
e�Ze�Zdd�Zddd�Zddd�Zddd�Zd dd�Z d!dd�Z!dd�Z"e�Z#dS)"z?
An interface to html5lib that mimics the lxml.html interface.
�N)�
HTMLParser)�TreeBuilder)�etree)�Element�XHTML_NAMESPACE�_contains_block_level_tag)�urlopen)�urlparsec@seZdZdZddd�ZdS)rz*An html5lib HTML parser with lxml as tree.FcKstj|f|td�|��dS�N)�strict�tree)�_HTMLParser�__init__r��selfr�kwargs�r�7/tmp/pip-install-gdmoqxf6/lxml/lxml/html/html5parser.pyrszHTMLParser.__init__N)F��__name__�
__module__�__qualname__�__doc__rrrrrrsr)�XHTMLParserc@seZdZdZddd�ZdS)rz+An html5lib XHTML Parser with lxml as tree.FcKstj|f|td�|��dSr
)�_XHTMLParserrrrrrrr*szXHTMLParser.__init__N)Frrrrrr'srcCs(|�|�}|dk	r|S|�dt|f�S)Nz{%s}%s)�findr)r�tag�elemrrr�	_find_tag0s
rcCsZt|t�std��|dkrt}i}|dkr8t|t�r8d}|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_parser�bytes�parse�getroot)�html�
guess_charset�parser�optionsrrr�document_fromstring7s
r,FcCs�t|t�std��|dkrt}i}|dkr8t|t�r8d}|dk	rH||d<|j|df|�}|r�t|dt�r�|r�|d��r�t�d|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%�
parseFragment�stripr�ParserError)r(�no_leading_textr)r*r+�childrenrrr�fragments_fromstringOs$
�r3cCs�t|t�std��t|�}t||||d�}|rvt|t�s>d}t|�}|rrt|dt�rh|d|_|d=|�|�|S|s�t�	d��t
|�dkr�t�	d��|d}|jr�|j��r�t�	d|j��d	|_|S)
a�Parses 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*r1r-rzNo elements found�zMultiple elements foundzElement followed by text: %rN)
r!r"r#�boolr3r�text�extendrr0�len�tailr/)r(Z
create_parentr)r*Zaccept_leading_text�elements�new_root�resultrrr�fragment_fromstringqs8
�




r=cCs�t|t�std��t|||d�}|dd�}t|t�rB|�dd�}|����}|�d�sb|�d�rf|St	|d	�}t
|�r||St	|d
�}t
|�dkr�|jr�|j��s�|dj
r�|dj
��s�|d
St|�r�d|_nd|_|S)a�Parse 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)N�2�ascii�replacez<htmlz	<!doctype�head�bodyr4���rr-�span)r!r"r#r,r%�decode�lstrip�lower�
startswithrr8r6r/r9rr)r(r)r*�doc�startrArBrrr�
fromstring�s2
�


��rKcCsz|dkrt}t|t�s(|}|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).
    NFT�rbr )r$r!r"�_looks_like_urlr�openr&)Zfilename_url_or_filer)r*�fpr+rrrr&�s"

r&cCs@t|�d}|sdStjdkr8|tjkr8t|�dkr8dSdSdS)NrF�win32r4T)r	�sys�platform�string�
ascii_lettersr8)�str�schemerrrrM�s
�
�rM)NN)FNN)FNN)NN)NN)$rrQrS�html5librr
Z html5lib.treebuilders.etree_lxmlr�lxmlrZ	lxml.htmlrrr�
basestringr"�	NameErrorr%rU�urllib2r�ImportError�urllib.requestr	�urllib.parserrZxhtml_parserrr,r3r=rKr&rMr$rrrr�<module>sN
�
"�
,
6
$