File: //lib/python3/dist-packages/bs4/__pycache__/diagnose.cpython-38.pyc
U
t�^) � @ s d Z dZddlZddlmZ ddlmZ ddlZddlmZm Z ddl
mZ ddlZddl
Z
ddlZddlZddlZddlZddlZddlZdd � Zd#dd�ZG d
d� de�Zdd� ZdZdZd$dd�Zd%dd�Zd&dd�Zd'dd�Zd(d d!�Zed"k�reej� � � dS ))z=Diagnostic functions, mainly for use when doing tech support.ZMIT� N)�StringIO)�
HTMLParser)�
BeautifulSoup�__version__)�builder_registryc C sJ t dt � t dtj � dddg}|D ]4}tjD ]}||jkr2 q(q2|�|� t d| � q(d|kr�|�d� z*dd l m
} t d
d�tt
|j�� � W n* tk
r� } zt d� W 5 d
}~X Y nX d|k�rzdd
l}t d|j � W n, tk
�r } zt d� W 5 d
}~X Y nX t| d��r.| �� } n�| �d��sF| �d��r^t d| � t d� d
S z:tj�| ��r�t d| � t| ��}|�� } W 5 Q R X W n tk
�r� Y nX t � |D ]�}t d| � d} zt| |d�}
d} W n8 tk
�r } zt d| � t�� W 5 d
}~X Y nX | �r:t d| � t |
�� � t d� �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.zlxml-xmlr ��etreezFound lxml version %s�.z.lxml is not installed or couldn't be imported.NzFound 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 Zbuildersr �remove�appendr r �join�map�strZLXML_VERSION�ImportErrorr �hasattrr
�
startswith�os�path�exists�open�
ValueErrorr � Exception� traceback� print_excZprettify)�dataZ
basic_parsers�nameZbuilderr �er �fp�parser�success�soup� r* �./usr/lib/python3/dist-packages/bs4/diagnose.py�diagnose sr
��
�
�
r, Tc K sJ ddl m} |jt| �fd|i|��D ]\}}td||j|jf � 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.
r r
�htmlz%s, %4s, %sN)r r Z iterparser r �tag�text)r# r- �kwargsr Zevent�elementr* r* r+ �
lxml_trace] s "r2 c @ s` e Zd ZdZdd� Zdd� Zdd� Zdd � Zd
d� Zdd
� Z dd� Z
dd� Zdd� Zdd� 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 C s t |� d S )N)r )�self�sr* r* r+ �_pu s zAnnouncingParser._pc C s | � d| � d S )Nz%s START�r6 )r4 r$ Zattrsr* r* r+ �handle_starttagx s z AnnouncingParser.handle_starttagc C s | � d| � d S )Nz%s ENDr7 �r4 r$ r* r* r+ �
handle_endtag{ s zAnnouncingParser.handle_endtagc C s | � d| � d S )Nz%s DATAr7 �r4 r# r* r* r+ �handle_data~ s zAnnouncingParser.handle_datac C s | � d| � d S )Nz
%s CHARREFr7 r9 r* r* r+ �handle_charref� s zAnnouncingParser.handle_charrefc C s | � d| � d S )Nz%s ENTITYREFr7 r9 r* r* r+ �handle_entityref� s z!AnnouncingParser.handle_entityrefc C s | � d| � d S )Nz
%s COMMENTr7 r; r* r* r+ �handle_comment� s zAnnouncingParser.handle_commentc C s | � d| � d S )Nz%s DECLr7 r; r* r* r+ �handle_decl� s zAnnouncingParser.handle_declc C s | � d| � d S )Nz%s UNKNOWN-DECLr7 r; r* r* r+ �unknown_decl� s zAnnouncingParser.unknown_declc C s | � d| � d S )Nz%s PIr7 r; r* r* r+ � handle_pi� s zAnnouncingParser.handle_piN)�__name__�
__module__�__qualname__�__doc__r6 r8 r: r<