HEX
Server: LiteSpeed
System: Linux php-prod-1.spaceapp.ru 5.15.0-157-generic #167-Ubuntu SMP Wed Sep 17 21:35:53 UTC 2025 x86_64
User: xnsbb3110 (1041)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //usr/local/CyberPanel/lib64/python3.10/site-packages/bs4/__pycache__/diagnose.cpython-310.pyc
o

��h�@sdZdZddlZddlmZddlmZddlZddlmZm	Z	ddl
mZddlZddl
Z
ddlZddlZddlZddlZddlZddlZdd	�Zd#dd�ZGd
d�de�Zdd�ZdZdZd$dd�Zd%dd�Zd&dd�Zd'dd�Zd(d d!�Zed"kr�eej� ��dSdS))z=Diagnostic functions, mainly for use when doing tech support.�MIT�N)�BytesIO)�
HTMLParser)�
BeautifulSoup�__version__)�builder_registryc
Cs�tdt�tdtj�gd�}|D]}tjD]	}||jvr!nq|�|�td|�qd|vrc|�d�zddl	m
}td	d
�tt
|j���Wntyb}z
td�WYd}~nd}~wwd
|vr�z
ddl}td|j�Wnty�}z
td�WYd}~nd}~wwt|d�r�|��}|D]C}td|�d}z
t||d�}	d}Wnty�}ztd|�t��WYd}~nd}~ww|r�td|�t|	���td�q�dS)z�Diagnostic suite for isolating common problems.

    :param data: A string containing markup that needs to be explained.
    :return: None; diagnostics are printed to standard output.
    z'Diagnostic running on Beautiful Soup %szPython version %s)�html.parser�html5lib�lxmlz;I noticed that %s is not installed. Installing it may help.r
zlxml-xmlr��etreezFound lxml version %s�.z.lxml is not installed or couldn't be imported.Nr	zFound html5lib version %sz2html5lib is not installed or couldn't be imported.�readz#Trying to parse your markup with %sF)�featuresT�%s could not parse the markup.z#Here's what %s did with the markup:zP--------------------------------------------------------------------------------)�printr�sys�versionr�buildersr�remove�appendr
r�join�map�str�LXML_VERSION�ImportErrorr	�hasattrrr�	Exception�	traceback�	print_exc�prettify)
�data�
basic_parsers�name�builderr�er	�parser�success�soup�r)�B/usr/local/CyberPanel/lib/python3.10/site-packages/bs4/diagnose.py�diagnosesl

�
���
������
��
�r+TcKspddlm}|�dd�}t|t�r|�d�}t|�}|j|f||d�|��D]\}}td||j	|j
f�q&dS)	a�Print out the lxml events that occur during parsing.

    This lets you see how lxml parses a document when no Beautiful
    Soup code is running. You can use this to determine whether
    an lxml-specific problem is in Beautiful Soup's lxml tree builders
    or in lxml itself.

    :param data: Some markup.
    :param html: If True, markup will be parsed with lxml's HTML parser.
       if False, lxml's XML parser will be used.
    rr�recoverT�utf8)�htmlr,z%s, %4s, %sN)r
r�pop�
isinstancer�encoder�	iterparser�tag�text)r!r.�kwargsrr,�reader�event�elementr)r)r*�
lxml_traceNs

����r9c@s`eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�AnnouncingParserz�Subclass of HTMLParser that announces parse events, without doing
    anything else.

    You can use this to get a picture of how html.parser sees a given
    document. The easiest way to do this is to call `htmlparser_trace`.
    cCst|�dS)N)r)�self�sr)r)r*�_plszAnnouncingParser._pcC�|�d|�dS)Nz%s START�r=)r;r#�attrsr)r)r*�handle_starttago�z AnnouncingParser.handle_starttagcCr>)Nz%s ENDr?�r;r#r)r)r*�
handle_endtagrrBzAnnouncingParser.handle_endtagcCr>)Nz%s DATAr?�r;r!r)r)r*�handle_dataurBzAnnouncingParser.handle_datacCr>)Nz
%s CHARREFr?rCr)r)r*�handle_charrefxrBzAnnouncingParser.handle_charrefcCr>)Nz%s ENTITYREFr?rCr)r)r*�handle_entityref{rBz!AnnouncingParser.handle_entityrefcCr>)Nz
%s COMMENTr?rEr)r)r*�handle_comment~rBzAnnouncingParser.handle_commentcCr>)Nz%s DECLr?rEr)r)r*�handle_decl�rBzAnnouncingParser.handle_declcCr>)Nz%s UNKNOWN-DECLr?rEr)r)r*�unknown_decl�rBzAnnouncingParser.unknown_declcCr>)Nz%s PIr?rEr)r)r*�	handle_pi�rBzAnnouncingParser.handle_piN)�__name__�
__module__�__qualname__�__doc__r=rArDrFrGrHrIrJrKrLr)r)r)r*r:dsr:cCst�}|�|�dS)z�Print out the HTMLParser events that occur during parsing.

    This lets you see how HTMLParser parses a document when no
    Beautiful Soup code is running.

    :param data: Some markup.
    N)r:�feed)r!r&r)r)r*�htmlparser_trace�srR�aeiou�bcdfghjklmnpqrstvwxyz�cCs:d}t|�D]}|ddkrt}nt}|t�|�7}q|S)z#Generate a random word-like string.��r)�range�_consonants�_vowels�random�choice)�lengthr<�i�tr)r)r*�rword�sr`�cCsd�dd�t|�D��S)z'Generate a random sentence-like string.� css �|]}tt�dd��VqdS)ra�	N)r`r[�randint)�.0r^r)r)r*�	<genexpr>�s�zrsentence.<locals>.<genexpr>)rrX)r]r)r)r*�	rsentence�srg��cCs�gd�}g}t|�D]9}t�dd�}|dkr#t�|�}|�d|�q
|dkr3|�tt�dd���q
|dkrCt�|�}|�d|�q
d	d
�|�dS)z+Randomly generate an invalid HTML document.)�p�div�spanr^�b�script�tabler�z<%s>�rarWz</%s>z<html>�
z</html>)rXr[rdr\rrgr)�num_elements�	tag_names�elementsr^r\�tag_namer)r)r*�rdoc�s

�rv順c
Cs&tdt�t|�}tdt|��dddgddfD]>}d}zt��}t||�}t��}d}WntyK}ztd	|�t��WYd
}~nd
}~ww|rXtd|||f�qdd
l	m
}t��}|�|�t��}td||�dd
l}	|	�
�}t��}|�|�t��}td||�d
S)z.Very basic head-to-head performance benchmark.z1Comparative parser benchmark on Beautiful Soup %sz3Generated a large invalid HTML document (%d bytes).r
r.r	rFTrNz"BS4+%s parsed the markup in %.2fs.rrz$Raw lxml parsed the markup in %.2fs.z(Raw html5lib parsed the markup in %.2fs.)rrrv�len�timerrrrr
r�HTMLr	r�parse)
rrr!r&r'�ar(rlr%rr	r)r)r*�benchmark_parsers�s:
���

r}r
cCsXt��}|j}t|�}tt||d�}t�d|||�t�	|�}|�
d�|�dd�dS)z7Use Python's profiler on a randomly generated document.)�bs4r!r&zbs4.BeautifulSoup(data, parser)�
cumulativez
_html5lib|bs4�2N)�tempfile�NamedTemporaryFiler#rv�dictr~�cProfile�runctx�pstats�Stats�
sort_stats�print_stats)rrr&�
filehandle�filenamer!�vars�statsr)r)r*�profile�s

r��__main__)T)rU)ra)rh)rw)rwr
)!rP�__license__r��ior�html.parserrr~rr�bs4.builderr�osr�r[r�ryrrr+r9r:rRrZrYr`rgrvr}r�rM�stdinrr)r)r)r*�<module>s<
8&




 �