509318396
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
3
Uñ*WÓG  ã               @   sp  d Z ddlmZ ddlZddlZddlZyddlmZ W n  e	k
rX   ddl
mZ Y nX ddddd	d
dgZyeZW n ek
r�   eefZY nX ejd dkZejdƒZejdƒZejdƒZejZdd„ Zdd„ Zejddd�Zdd„ ZejdƒZejdƒZG dd„ deƒZ G dd	„ d	e ƒZ!d#dd
„Z"d$dd„Z#G dd„ de$ƒZ%dd„ Z&d d!iZ'e(d"k�rlddlZej)ƒ  dS )%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é   c             C   s   | d krd S | j ƒ S d S )N)Ústrip)Úv© r   ú&/usr/lib64/python3.6/doctestcompare.pyr   ?   s    r   c             C   s   t jd| ƒS )Nú )Ú_norm_whitespace_reÚsub)r   r   r   r   Únorm_whitespaceE   s    r   FT)ZrecoverZremove_blank_textc             C   s   t j| tƒS )N)r   Z
fromstringÚ_html_parser)Úhtmlr   r   r   Úhtml_fromstringJ   s    r   z^<[^>]+ (at|object) z[ \t\n][ \t\n]+c            
   @   s    e Zd Zd0Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zd1dd„Zd2dd „Zd3d!d"„Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd4d-d.„Zd/S )5r   ÚparamÚimgÚareaÚbrÚbasefontÚinputÚbaseÚmetaÚlinkÚcolc             C   s   t jS )N)r   ÚXML)Úselfr   r   r   Úget_default_parserW   s    z$LXMLOutputChecker.get_default_parserc       	      C   sš   t | dd ƒ}|d k	r | j}|} ntj}| j|||ƒ}|sF|| |||ƒS y||ƒ}W n tjk
rh   dS X y||ƒ}W n tjk
rŒ   dS X | j||ƒS )NÚ_temp_override_selfF)ÚgetattrÚ_temp_call_super_check_outputÚOutputCheckerÚcheck_outputÚ
get_parserr   ÚXMLSyntaxErrorÚcompare_docs)	r"   ÚwantÚgotÚoptionflagsZalt_selfZsuper_methodÚparserÚwant_docÚgot_docr   r   r   r(   Z   s$    zLXMLOutputChecker.check_outputc             C   st   d }t |@ rd S t|@ rt}nRt|@ r.tj}nB|jƒ jƒ jdƒrT|jƒ jdƒrTt}n| j	|ƒrp| j	|ƒrp| j
ƒ }|S )Nz<html)r   r   r   r   r   r!   r   ÚlowerÚ
startswithÚ_looks_like_markupr#   )r"   r,   r-   r.   r/   r   r   r   r)   o   s    

zLXMLOutputChecker.get_parserc             C   s   |j ƒ }|jdƒotj|ƒ S )Nú<)r   r3   Ú_repr_reÚsearch)r"   Úsr   r   r   r4      s    
z$LXMLOutputChecker._looks_like_markupc       
      C   s  | j |j|jƒsdS | j|j|jdƒs*dS | j|j|jdƒs@dS d|jkržt|jjƒ ƒ}t|jjƒ ƒ}||krrdS x*|D ]"}| j|j| |j| dƒsxdS qxW |jdks²t|ƒ�rt	|ƒ}t	|ƒ}xV|sÎ|�r| sÚ| rÞdS |j
dƒ}|j
dƒ}	| j||	ƒ�sdS | rÄ|jdkrÄP qÄW dS )NFTÚanyz...r   )Útag_compareÚtagÚtext_compareÚtextÚtailÚattribÚsortedÚkeysÚlenÚlistÚpopr+   )
r"   r,   r-   Z	want_keysZgot_keysÚkeyÚwant_childrenÚgot_childrenZ
want_firstZ	got_firstr   r   r   r+   „   s6    



zLXMLOutputChecker.compare_docsc             C   s^   |pd}|pd}|r,t |ƒjƒ }t |ƒjƒ }dtj|ƒ }|jddƒ}tj||ƒrVdS dS d S )NÚ z^%s$z\.\.\.z.*TF)r   r   Úrer   Úreplacer7   )r"   r,   r-   r   r   r   r   r<   ¡   s    zLXMLOutputChecker.text_comparec             C   sn   |dkrdS t |tƒ s$t |tƒ r,||kS |p2d}|p:d}|jdƒrb|jdƒd |jdƒd kS ||kS d S )	Nr9   TrH   z{...}ú}é   éÿÿÿÿrM   )Ú
isinstanceÚ_basestringr3   Úsplit)r"   r,   r-   r   r   r   r:   ®   s    
zLXMLOutputChecker.tag_comparec             C   sF  |j }| j|||ƒ}g }|d k	rœy||ƒ}W n0 tjk
r\   tjƒ d }|jd| ƒ Y nX y||ƒ}	W n0 tjk
rš   tjƒ d }|jd| ƒ Y nX |d ks¨|rÔtj| |||ƒ}
|rÐ|j|
ƒ dj	|ƒS |
S |t
k}g }|jdƒ |j| j||dƒƒ |jdƒ |j| j|	|dƒƒ |jdƒ |j| j||	|dƒƒ dj	|ƒS )	NrL   zIn example: %szIn actual output: %sÚ
z	Expected:é   zGot:zDiff:)r,   r)   r   r*   ÚsysÚexc_infoÚappendr'   Úoutput_differenceÚjoinr   Ú
format_docÚcollect_diff)r"   Zexampler-   r.   r,   r/   Úerrorsr0   Úer1   Úvaluer   Z
diff_partsr   r   r   rV   ¼   s<    




z#LXMLOutputChecker.output_differenceTc             C   s.   |sdS |j | jkrdS |js&t|ƒr*dS dS )NFT)r;   Ú
empty_tagsr=   rB   )r"   Úelr   r   r   r   Úhtml_empty_tagÝ   s    z LXMLOutputChecker.html_empty_tagrH   c             C   s¢  g }t |ƒsœ|jd| ƒ |j|ƒ |j| j|ƒƒ | j||ƒslt|jƒr\|j| j|jƒƒ |j| j|ƒƒ t|jƒrˆ|j| j|jƒƒ |jdƒ dj	|ƒS |jd| ƒ |j|ƒ |j| j|ƒƒ | j||ƒ�sb|jdƒ t|jƒ�r|jd| ƒ |j| j|jƒƒ |jdƒ x&|D ]}|j| j
|||d ƒƒ �qW |jd| ƒ |j| j|ƒƒ |jdƒ t|jƒ�r˜|jd| ƒ |j| j|jƒƒ |jdƒ dj	|ƒS )Nr   rQ   rH   rR   )rB   rU   Ú
format_tagr_   r   r=   Úformat_textÚformat_end_tagr>   rW   rX   )r"   Údocr   ÚindentÚprefixÚpartsr^   r   r   r   rX   ç   s@    










zLXMLOutputChecker.format_docc             C   s"   |d krdS |r|j ƒ }t|dƒS )NrH   rL   )r   Úhtml_escape)r"   r=   r   r   r   r   ra   
  s
    zLXMLOutputChecker.format_textc             C   sl   g }t |tjƒrdS x4t|jjƒ ƒD ]"\}}|jd|| j|dƒf ƒ q$W |sXd|j S d|jdj	|ƒf S )Nz<!--z%s="%s"Fz<%s>z<%s %s>r   )
rN   r   ÚCommentBaser@   r?   ÚitemsrU   ra   r;   rW   )r"   r^   ÚattrsÚnamer\   r   r   r   r`     s    
zLXMLOutputChecker.format_tagc             C   s   t |tjƒrdS d|j S )Nz-->z</%s>)rN   r   rh   r;   )r"   r^   r   r   r   rb     s    z LXMLOutputChecker.format_end_tagc             C   s  g }t |ƒ r–t |ƒ r–|jd| ƒ |j| j||ƒƒ | j||ƒsl|j| j|j|jƒƒ |j| j||ƒƒ |j| j|j|jƒƒ |jdƒ dj|ƒS |jd| ƒ |j| j||ƒƒ |jdƒ t	|jƒsÖt	|jƒ�r|jd| ƒ |j| j|j|jƒƒ |jdƒ t
|ƒ}t
|ƒ}xŒ|�s"|�r |�sL|j| j|jdƒ||d dƒƒ �q|�sv|j| j|jdƒ||d dƒƒ �q|j| j|jdƒ|jdƒ||d ƒƒ �qW |jd| ƒ |j| j||ƒƒ |jdƒ t	|jƒ�sät	|jƒ�r|jd| ƒ |j| j|j|jƒƒ |jdƒ dj|ƒS )Nr   rQ   rH   r   rR   ú+ú-)rB   rU   Úcollect_diff_tagr_   Úcollect_diff_textr=   Úcollect_diff_end_tagr>   rW   r   rC   rX   rD   rY   )r"   r,   r-   r   rd   rf   rF   rG   r   r   r   rY   "  sH    



  $

zLXMLOutputChecker.collect_diffc       	      C   s4  | j |j|jƒs"d|j|jf }n|j}g }|jdkp>d|jk}x„t|jjƒ ƒD ]r\}}||jkr„| r„|jd|| j|dƒf ƒ qP||jkr¤| j|j| |dƒ}n| j|dƒ}|jd||f ƒ qPW |�sx@t|jjƒ ƒD ].\}}||jkrðqÜ|jd|| j|dƒf ƒ qÜW |�r(d|dj|ƒf }nd	| }|S )
Nz%s (got: %s)r9   z+%s="%s"Fz%s="%s"z-%s="%s"z<%s %s>r   z<%s>)	r:   r;   r?   r@   ri   rU   ra   ro   rW   )	r"   r,   r-   r;   rj   r9   rk   r\   r=   r   r   r   rn   H  s*    

z"LXMLOutputChecker.collect_diff_tagc             C   s,   |j |j krd|j |j f }n|j }d| S )Nz%s (got: %s)z</%s>)r;   )r"   r,   r-   r;   r   r   r   rp   c  s    z&LXMLOutputChecker.collect_diff_end_tagc             C   s:   | j |||ƒr"|sdS | j||ƒS d||f }| j||ƒS )NrH   z%s (got: %s))r<   ra   )r"   r,   r-   r   r=   r   r   r   ro   j  s    z#LXMLOutputChecker.collect_diff_textN)
r   r   r   r   r   r   r   r   r   r    )T)rH   )T)T)Ú__name__Ú
__module__Ú__qualname__r]   r#   r(   r)   r4   r+   r<   r:   rV   r_   rX   ra   r`   rb   rY   rn   rp   ro   r   r   r   r   r   Q   s&    !


#
&c               @   s   e Zd Zdd„ ZdS )r   c             C   s   t S )N)r   )r"   r   r   r   r#   s  s    z%LHTMLOutputChecker.get_default_parserN)rq   rr   rs   r#   r   r   r   r   r   r  s   c             C   s   | rt t_ntt_dS )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   )r   r   r   r   r	   v  s    c       	      C   sz   | r
t }nt}tƒ }|jd }|ƒ }|j}||_trJ|jd j}|jj}n|jd j}|jj}t	t
_	t||||||ƒ dS )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"   ZcheckN)r   r   Ú_find_doctest_frameÚf_localsZ_checkerÚ_IS_PYTHON_3Ú__func__r(   Zim_funcr   rt   Ú_RestoreChecker)	r   Ú
del_moduleZCheckerÚframeÚdt_selfÚcheckerÚold_checkerÚ
check_funcZchecker_check_funcr   r   r   r
   ‚  s"    


c               @   sL   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dS )ry   c             C   sD   || _ || _| j| j_|| j_|| _|| _|| _| jƒ  | j	ƒ  d S )N)
r|   r}   Ú
call_superr&   r$   r   Ú
clone_funcrz   Úinstall_cloneÚinstall_dt_self)r"   r|   r~   Znew_checkerr   r�   rz   r   r   r   Ú__init__ª  s    
z_RestoreChecker.__init__c             C   sJ   t r&| jj| _| jj| _| jj| j_n | jj| _| jj| _| jj| j_d S )N)rw   r   Ú__code__Ú	func_codeÚ__globals__Zfunc_globalsr�   )r"   r   r   r   r‚   µ  s    



z_RestoreChecker.install_clonec             C   s   t r| j| j_n
| j| j_d S )N)rw   r†   r   r…   )r"   r   r   r   Úuninstall_clone¾  s    z_RestoreChecker.uninstall_clonec             C   s   | j j| _| | j _d S )N)r|   Ú_DocTestRunner__record_outcomeÚ	prev_func)r"   r   r   r   rƒ   Ã  s    
z_RestoreChecker.install_dt_selfc             C   s   | j | j_d S )N)rŠ   r|   r‰   )r"   r   r   r   Úuninstall_dt_selfÆ  s    z!_RestoreChecker.uninstall_dt_selfc             C   sL   | j rHdd l}|j| j = d| j krH| j jddƒ\}}|j| }t||ƒ d S )Nr   Ú.rL   )rz   rS   ÚmodulesÚrsplitÚdelattr)r"   rS   ÚpackageÚmoduleZpackage_modr   r   r   Úuninstall_moduleÈ  s    


z _RestoreChecker.uninstall_modulec             O   s4   | j ƒ  | jƒ  | j`| j`| j||Ž}| jƒ  |S )N)rˆ   r‹   r}   r$   r&   rŠ   r’   )r"   ÚargsÚkwÚresultr   r   r   Ú__call__Ð  s    z_RestoreChecker.__call__c          
   O   s$   | j ƒ  z| j||ŽS | jƒ  X d S )N)rˆ   r   r‚   )r"   r“   r”   r   r   r   r€   Ø  s    z_RestoreChecker.call_superN)rq   rr   rs   r„   r‚   rˆ   rƒ   r‹   r’   r–   r€   r   r   r   r   ry   ©  s   	ry   c              C   s@   dd l } | jdƒ}x |r2|j}d|kr*|S |j}qW tdƒ‚d S )Nr   rL   ZBOOMzBCould not find doctest (only use this function *inside* a doctest))rS   Ú	_getframerv   Úf_backÚLookupError)rS   r{   Úlr   r   r   ru   ß  s    

ru   Zbasicai  
    >>> 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__Zlxmlr   rS   rI   rt   r   r   rg   ÚImportErrorZcgiÚ__all__Z
basestringrO   Ú	NameErrorÚstrÚbytesÚversion_inforw   Zregister_optionflagr   r   r   r'   r   r   Z
HTMLParserr   r   Úcompiler6   r   r   r   r	   r
   Úobjectry   ru   Z__test__rq   Ztestmodr   r   r   r   Ú<module>$   sL   





  #

'6

