AlkantarClanX12

Your IP : 18.191.189.124


Current Path : /opt/alt/python37/lib64/python3.7/site-packages/lxml/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/site-packages/lxml/__pycache__/doctestcompare.cpython-37.pyc

B

�|/\�G�@spdZddlmZddlZddlZddlZyddlmZWn e	k
rXddl
mZYnXddddd	d
dgZyeZ
Wnek
r�eefZ
YnXejddkZe�d�Ze�d�Ze�d�ZejZd
d�Zdd�Zejddd�Zdd�Ze�d�Ze�d�ZGdd�de�Z Gdd	�d	e �Z!d#dd
�Z"d$dd�Z#Gdd�de$�Z%dd�Z&d d!iZ'e(d"k�rlddlZe�)�dS)%a�
lxml-based doctest output comparison.

Note: normally, you should just import the `lxml.usedoctest` and
`lxml.html.usedoctest` modules from within a doctest, instead of this
one::

    >>> import lxml.usedoctest # for XML output

    >>> import lxml.html.usedoctest # for HTML output

To use this module directly, you must call ``lxmldoctest.install()``,
which will cause doctest to use this in all subsequent calls.

This changes the way output is checked and comparisons are made for
XML or HTML-like content.

XML or HTML content is noticed because the example starts with ``<``
(it's HTML if it starts with ``<html``).  You can also use the
``PARSE_HTML`` and ``PARSE_XML`` flags to force parsing.

Some rough wildcard-like things are allowed.  Whitespace is generally
ignored (except in attributes).  In text (attributes and text in the
body) you can use ``...`` as a wildcard.  In an example it also
matches any trailing tags in the element, though it does not match
leading tags.  You may create a tag ``<any>`` or include an ``any``
attribute in the tag.  An ``any`` tag matches any tag, while the
attribute matches any and all attributes.

When a match fails, the reformatted example and gotten text is
displayed (indented), and a rough diff-like output is given.  Anything
marked with ``+`` is in the output but wasn't supposed to be, and
similarly ``-`` means its in the example but wasn't in the output.

You can disable parsing on one line with ``# doctest:+NOPARSE_MARKUP``
�)�etreeN)�escape�
PARSE_HTML�	PARSE_XML�NOPARSE_MARKUP�LXMLOutputChecker�LHTMLOutputChecker�install�temp_install�cCs|dkrdS|��SdS)N)�strip)�v�r�F/opt/alt/python37/lib64/python3.7/site-packages/lxml/doctestcompare.pyr?srcCst�d|�S)N� )�_norm_whitespace_re�sub)r
rrr�norm_whitespaceEsrFT)ZrecoverZremove_blank_textcCst�|t�S)N)rZ
fromstring�_html_parser)�htmlrrr�html_fromstringJsrz^<[^>]+ (at|object) z[ \t\n][ \t\n]+c@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zd'dd�Zd(dd�Z
d)dd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd*d$d%�Zd&S)+r)
�paramZimgZarea�brZbasefont�input�base�meta�link�colcCstjS)N)r�XML)�selfrrr�get_default_parserWsz$LXMLOutputChecker.get_default_parserc	Cs�t|dd�}|dk	r |j}|}ntj}|�|||�}|sF|||||�Sy||�}Wntjk
rhdSXy||�}Wntjk
r�dSX|�||�S)N�_temp_override_selfF)�getattr�_temp_call_super_check_output�
OutputChecker�check_output�
get_parserr�XMLSyntaxError�compare_docs)	r�want�got�optionflagsZalt_selfZsuper_method�parser�want_doc�got_docrrrr%Zs$zLXMLOutputChecker.check_outputcCstd}t|@rdSt|@rt}nRt|@r.tj}nB|�����d�rT|���d�rTt}n|�	|�rp|�	|�rp|�
�}|S)Nz<html)rrrrrrr�lower�
startswith�_looks_like_markupr )rr)r*r+r,rrrr&os

zLXMLOutputChecker.get_parsercCs|��}|�d�ot�|�S)N�<)rr0�_repr_re�search)r�srrrr1s
z$LXMLOutputChecker._looks_like_markupc
Cs|�|j|j�sdS|�|j|jd�s*dS|�|j|jd�s@dSd|jkr�t|j���}t|j���}||krrdSx*|D]"}|�|j||j|d�sxdSqxW|jdks�t|��rt	|�}t	|�}xN|s�|�r|r�|s�dS|�
d�}|�
d�}	|�||	�s�dS|s�|jdkr�Pq�WdS)NFT�anyz...r)�tag_compare�tag�text_compare�text�tail�attrib�sorted�keys�len�list�popr()
rr)r*Z	want_keysZgot_keys�key�
want_children�got_childrenZ
want_firstZ	got_firstrrrr(�s6



zLXMLOutputChecker.compare_docscCs^|pd}|pd}|r,t|���}t|���}dt�|�}|�dd�}t�||�rVdSdSdS)N�z^%s$z\.\.\.z.*TF)rr�rer�replacer4)rr)r*rrrrr9�szLXMLOutputChecker.text_comparecCsj|dkrdSt|t�r t|t�s(||kS|p.d}|p6d}|�d�r^|�d�d|�d�dkS||kSdS)Nr6TrEz{...}�}���)�
isinstance�_basestringr0�split)rr)r*rrrr7�s


zLXMLOutputChecker.tag_comparec
Cs|j}|�|||�}g}|dk	r�y||�}Wn0tjk
r\t��d}|�d|�YnXy||�}	Wn0tjk
r�t��d}|�d|�YnX|dks�|r�t�||||�}
|r�|�|
�d�	|�S|
S|t
k}d|�||d�d|�|	|d�d|�||	|d�g}d�	|�S)	N�zIn example: %szIn actual output: %s�
z	Expected:�zGot:zDiff:)
r)r&rr'�sys�exc_info�appendr$�output_difference�joinr�
format_doc�collect_diff)
rZexampler*r+r)r,�errorsr-�er.�valuerZ
diff_partsrrrrS�s:

z#LXMLOutputChecker.output_differenceTcCs.|sdS|j|jkrdS|js&t|�r*dSdS)NFT)r8�
empty_tagsr:r?)r�elrrrr�html_empty_tag�sz LXMLOutputChecker.html_empty_tagrEc	Cs�g}t|�s�|�d|�|�|�|�|�|��|�||�slt|j�r\|�|�|j��|�|�|��t|j�r�|�|�|j��|�d�d�	|�S|�d|�|�|�|�|�|��|�||��sb|�d�t|j��r|�d|�|�|�|j��|�d�x&|D]}|�|�
|||d���qW|�d|�|�|�|��|�d�t|j��r�|�d|�|�|�|j��|�d�d�	|�S)NrrNrErO)r?rR�
format_tagr\rr:�format_text�format_end_tagr;rTrU)r�docr�indent�prefix�partsr[rrrrU�s@










zLXMLOutputChecker.format_doccCs"|dkrdS|r|��}t|d�S)NrErM)r�html_escape)rr:rrrrr^	s
zLXMLOutputChecker.format_textc	Cslg}t|tj�rdSx4t|j���D]"\}}|�d||�|d�f�q$W|sXd|jSd|jd�	|�fS)Nz<!--z%s="%s"Fz<%s>z<%s %s>r)
rJr�CommentBaser=r<�itemsrRr^r8rT)rr[�attrs�namerYrrrr]s
zLXMLOutputChecker.format_tagcCst|tj�rdSd|jS)Nz-->z</%s>)rJrrer8)rr[rrrr_sz LXMLOutputChecker.format_end_tagc	Csg}t|�s�t|�s�|�d|�|�|�||��|�||�sh|�|�|j|j��|�|�||��|�|�|j|j��|�d�d�|�S|�d|�|�|�||��|�d�t	|j�s�t	|j�r�|�d|�|�|�|j|j��|�d�t
|�}t
|�}x�|�s|�r�|�sF|�|�|�d�||dd���q|�sp|�|�|�d�||dd���q|�|�
|�d�|�d�||d���qW|�d|�|�|�||��|�d�t	|j��s�t	|j��r|�d|�|�|�|j|j��|�d�d�|�S)NrrNrErrO�+�-)r?rR�collect_diff_tagr\�collect_diff_textr:�collect_diff_end_tagr;rTrr@rUrArV)rr)r*rrarcrCrDrrrrV!sH



  $

zLXMLOutputChecker.collect_diffc		Cs2|�|j|j�s"d|j|jf}n|j}g}|jdkp>d|jk}x�t|j���D]p\}}||jkr�|s�|�d||�|d�f�qP||jkr�|�|j||d�}n|�|d�}|�d||f�qPW|�sx@t|j���D].\}}||jkr�q�|�d||�|d�f�q�W|�r&d|d�|�f}nd	|}|S)
Nz%s (got: %s)r6z+%s="%s"Fz%s="%s"z-%s="%s"z<%s %s>rz<%s>)	r7r8r<r=rfrRr^rlrT)	rr)r*r8rgr6rhrYr:rrrrkGs*

z"LXMLOutputChecker.collect_diff_tagcCs,|j|jkrd|j|jf}n|j}d|S)Nz%s (got: %s)z</%s>)r8)rr)r*r8rrrrmbsz&LXMLOutputChecker.collect_diff_end_tagcCs:|�|||�r"|sdS|�||�Sd||f}|�||�S)NrEz%s (got: %s))r9r^)rr)r*rr:rrrrlisz#LXMLOutputChecker.collect_diff_textN)T)rE)T)T)�__name__�
__module__�__qualname__rZr r%r&r1r(r9r7rSr\rUr^r]r_rVrkrmrlrrrrrQs$
 


#
&c@seZdZdd�ZdS)rcCstS)N)r)rrrrr rsz%LHTMLOutputChecker.get_default_parserN)rnrorpr rrrrrqscCs|rtt_ntt_dS)z�
    Install doctestcompare for all future doctests.

    If html is true, then by default the HTML parser will be used;
    otherwise the XML parser is used.
    N)r�doctestr$r)rrrrr	usc	Csz|r
t}nt}t�}|jd}|�}|j}||_trJ|jdj}|jj}n|jdj}|jj}t	t
_	t||||||�dS)z�
    Use this *inside* a doctest to enable this checker for this
    doctest only.

    If html is true, then by default the HTML parser will be used;
    otherwise the XML parser is used.
    r�checkN)rr�_find_doctest_frame�f_localsZ_checker�_IS_PYTHON_3�__func__r%Zim_funcrrq�_RestoreChecker)	r�
del_moduleZChecker�frame�dt_self�checker�old_checker�
check_funcZchecker_check_funcrrrr
�s"


c@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dS)rwcCsD||_||_|j|j_||j_||_||_||_|��|�	�dS)N)
rzr{�
call_superr#r!r}�
clone_funcrx�
install_clone�install_dt_self)rrzr|Znew_checkerr}rrxrrr�__init__�s
z_RestoreChecker.__init__cCsJtr&|jj|_|jj|_|jj|j_n |jj|_|jj|_|jj|j_dS)N)rur}�__code__�	func_code�__globals__Zfunc_globalsr)rrrrr��s



z_RestoreChecker.install_clonecCstr|j|j_n
|j|j_dS)N)rur�r}r�)rrrr�uninstall_clone�sz_RestoreChecker.uninstall_clonecCs|jj|_||j_dS)N)rz�_DocTestRunner__record_outcome�	prev_func)rrrrr��s
z_RestoreChecker.install_dt_selfcCs|j|j_dS)N)r�rzr�)rrrr�uninstall_dt_self�sz!_RestoreChecker.uninstall_dt_selfcCsL|jrHddl}|j|j=d|jkrH|j�dd�\}}|j|}t||�dS)Nr�.rM)rxrP�modules�rsplit�delattr)rrP�package�moduleZpackage_modrrr�uninstall_module�s


z _RestoreChecker.uninstall_modulecOs4|��|��|j`|j`|j||�}|��|S)N)r�r�r{r!r#r�r�)r�args�kw�resultrrr�__call__�sz_RestoreChecker.__call__cOs$|��z|j||�S|��XdS)N)r�r}r�)rr�r�rrrr~�sz_RestoreChecker.call_superN)rnrorpr�r�r�r�r�r�r�r~rrrrrw�s	rwcCs@ddl}|�d�}x |r2|j}d|kr*|S|j}qWtd��dS)NrrMZBOOMzBCould not find doctest (only use this function *inside* a doctest))rP�	_getframert�f_back�LookupError)rPry�lrrrrs�s

rsZbasicai
    >>> temp_install()
    >>> print """<xml a="1" b="2">stuff</xml>"""
    <xml b="2" a="1">...</xml>
    >>> print """<xml xmlns="http://example.com"><tag   attr="bar"   /></xml>"""
    <xml xmlns="...">
      <tag attr="..." />
    </xml>
    >>> print """<xml>blahblahblah<foo /></xml>""" # doctest: +NOPARSE_MARKUP, +ELLIPSIS
    <xml>...foo /></xml>
    �__main__)F)FN)*�__doc__�lxmlrrPrFrqrrrd�ImportError�cgi�__all__�
basestringrK�	NameError�str�bytes�version_inforuZregister_optionflagrrrr$rrZ
HTMLParserrr�compiler3rrrr	r
�objectrwrsZ__test__rnZtestmodrrrr�<module>$sL





"

'6