File: D:/Python311/Lib/site-packages/bs4/__pycache__/diagnose.cpython-311.pyc
�
��nc� � �F � d Z dZddlZddlmZ ddlmZ ddlZddlmZm Z ddl
mZ ddlZddl
Z
ddlZddlZddlZddlZddlZddlZd� Zdd
�Z G d� de� � Zd
� ZdZdZdd�Zdd�Zdd�Zdd�Zd d�Zedk r$ eej � � � � � dS dS )!z=Diagnostic functions, mainly for use when doing tech support.�MIT� N)�BytesIO)�
HTMLParser)�
BeautifulSoup�__version__)�builder_registryc �� � t dt z � � t dt j z � � g d�}|D ]C}t j D ]
}||j v r n(�|� |� � t d|z � � �Dd|v r�|� d� � ddl m
} t d d
� t t |j � � � � z � � n&# t $ r}t d� � Y d}~nd}~ww xY wd
|v rC ddl}t d|j z � � n&# t $ r}t d� � Y d}~nd}~ww xY wt# | d� � r| � � � } n�| � d� � s| � d� � r#t d| z � � t d� � dS t( j � | � � rMt d| z � � t/ | � � 5 }|� � � } ddd� � n# 1 swxY w Y n# t0 $ r Y nw xY wt d� � |D ]�}t d|z � � d} t3 | |�� � }
d} n<# t4 $ r/}t d|z � � t7 j � � Y d}~nd}~ww xY w| r3t d|z � � t |
� � � � � t d� � ��dS )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.�readzhttp:zhttps:z<"%s" looks like a URL. Beautiful Soup is not an HTTP client.zpYou need to use some other library to get the document behind the URL, and feed that document to Beautiful Soup.z7"%s" looks like a filename. Reading data from the file.� z#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 �hasattrr �
startswith�os�path�exists�open�
ValueErrorr � Exception� traceback� print_exc�prettify)�data�
basic_parsers�name�builderr �er �fp�parser�success�soups �.D:\Python311\Lib\site-packages\bs4/diagnose.py�diagnoser4 s/ � �
�4�{�B�D�D�D� ����,�.�.�.�7�7�7�M�� � ��'�0� � �G��w�'�'�
���
�
� � ��&�&�&��M���
�
�
�� ��� B����Z�(�(�(� B�"�"�"�"�"�"��*�S�X�X�c�#�e�>P�6Q�6Q�-R�-R�R�T�T�T�T��� B� B� B��@�
B�
B�
B�
B�
B�
B�
B�
B����� B����
�]�"� F� F��O�O�O��.��1E�E�G�G�G�G��� F� F� F��D�
F�
F�
F�
F�
F�
F�
F�
F����� F���� �t�V��� ��y�y�{�{���
���� !� !� �T�_�_�X�%>�%>� �
�M�PT�T�V�V�V�
� A� B� B� B��� ��w�~�~�d�#�#�
%��P�SW�W�Y�Y�Y��$�Z�Z� %�2��7�7�9�9�D�%� %� %� %� %� %� %� %� %� %� %���� %� %� %� %���� � � �
�D� ���� �b� � � ��
�
��
�4�v�=�?�?�?��� "� ���7�7�7�D��G�G��� "� "� "��3�f�<�>�>�>���!�!�!�!�!�!�!�!����� "���� � %��8�6�A�C�C�C��4�=�=�?�?�$�$�$�
�x�����
�
s� �AC �
C?�&C:�:C?�D# �#
E�-E�E�<A H) �<H�H) �H!�!H) �$H!�%H) �)
H6�5H6�!I5�5
J.�?%J)�)J.Tc �" � ddl m} |� dd� � }t | t � � r| � d� � } t
| � � } |j |f||d�|��D ]'\ }}t |�d|j d�d|j
��� � �(d S )
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.
r r
�recoverT�utf8)�htmlr6 z, z>4N)r r �pop�
isinstancer �encoder � iterparser �tag�text)r* r8 �kwargsr r6 �reader�event�elements r3 �
lxml_tracerC ] s� � � �������j�j��D�)�)�G��$���� #��{�{�6�"�"��
�T�]�]�F�)�%�/����7�� �.4�� � D� D���w� ����w�{�{�{�{�G�L�L�A�C�C�C�C�D� D� c �N � e Zd ZdZd� Zd� Zd� Zd� Zd� Zd� Z d� Z
d � Zd
� Zd� 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`.
c �$ � t |� � d S )N)r )�self�ss r3 �_pzAnnouncingParser._p{ s � �
�a�����rD c �6 � | � d|z � � d S )Nz%s START�rJ )rH r, �attrss r3 �handle_starttagz AnnouncingParser.handle_starttag~ s � ����
�T�!�"�"�"�"�"rD c �6 � | � d|z � � d S )Nz%s ENDrL �rH r, s r3 �
handle_endtagzAnnouncingParser.handle_endtag� s � �����4�� � � � � rD c �6 � | � d|z � � d S )Nz%s DATArL �rH r* s r3 �handle_datazAnnouncingParser.handle_data� � � ���� �D� �!�!�!�!�!rD c �6 � | � d|z � � d S )Nz
%s CHARREFrL rP s r3 �handle_charrefzAnnouncingParser.handle_charref� � � �����t�#�$�$�$�$�$rD c �6 � | � d|z � � d S )Nz%s ENTITYREFrL rP s r3 �handle_entityrefz!AnnouncingParser.handle_entityref� s � ������%�&�&�&�&�&rD c �6 � | � d|z � � d S )Nz
%s COMMENTrL rS s r3 �handle_commentzAnnouncingParser.handle_comment� rX rD c �6 � | � d|z � � d S )Nz%s DECLrL rS s r3 �handle_declzAnnouncingParser.handle_decl� rU rD c �6 � | � d|z � � d S )Nz%s UNKNOWN-DECLrL rS s r3 �unknown_declzAnnouncingParser.unknown_decl� s � ����!�D�(�)�)�)�)�)rD c �6 � | � d|z � � d S )Nz%s PIrL rS s r3 � handle_pizAnnouncingParser.handle_pi� s � �����$������rD N)�__name__�
__module__�__qualname__�__doc__rJ rN rQ rT rW rZ r\ r^ r` rb � rD r3 rF rF s s� � � � � � �� �� � �#� #� #�!� !� !�"� "� "�%� %� %�'� '� '�%� %� %�"� "� "�*� *� *� � � � � rD rF c �L � t � � }|� | � � 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)rF �feed)r* r0 s r3 �htmlparser_tracerj � s'