U õ üeCEã@s:dZddlmZddlZddlZddlZzddlmZWn e k rXddl mZYnXddddd d d gZ e  d¡Z e  d¡Ze  d¡ZejZd d „Zdd„ZejdddZdd„Ze d¡Ze d¡ZGdd„deƒZGdd „d eƒZd"dd „Zd#dd „ZGdd„dƒZdd„Zdd iZe d!kr6ddlZe !¡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 ```` 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_installcCs|dkr dS| ¡SdS©N)Ústrip©Úv©rúC/opt/hc_python/lib64/python3.8/site-packages/lxml/doctestcompare.pyr 8sr cCs t d|¡S)Nú )Ú_norm_whitespace_reÚsubr rrrÚnorm_whitespace>srFT)ZrecoverZremove_blank_textcCs t |t¡Sr )rÚ fromstringÚ _html_parser©ÚhtmlrrrÚhtml_fromstringCsrz^<[^>]+ (at|object) z[ \t\n][ \t\n]+c@s eZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z d'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ÚcolcCstjSr )rÚXML©ÚselfrrrÚget_default_parserPsz$LXMLOutputChecker.get_default_parserc Csžt|ddƒ}|dk r |j}|}ntj}| |||¡}|sF|||||ƒSz ||ƒ}Wntjk rjYdSXz ||ƒ}Wntjk rYdSX| ||¡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)Ss, ÿ  zLXMLOutputChecker.check_outputcCstd}t|@rdSt|@rt}nRt|@r.tj}nB| ¡ ¡ d¡rT| ¡ d¡rTt}n|  |¡rp|  |¡rp|  ¡}|S)Nzd}| d¡rf| d¡d| d¡dkS||kSdS)Nr:TrIz{...}Ú}éÿÿÿÿ)Ú isinstanceÚstrÚbytesr4Úsplit)r#r-r.rrrr;§s ÿ zLXMLOutputChecker.tag_comparec Cs|j}| |||¡}g}|dk rœz ||ƒ}Wn0tjk r\t ¡d}| d|¡YnXz ||ƒ} 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) r#Zexampler.r/r-r0Úerrorsr1Úer2ÚvaluerZ diff_partsrrrrXµsD     ÿ    ûz#LXMLOutputChecker.output_differenceTcCs.|sdS|j|jkrdS|js&t|ƒr*dSdS)NFT)r<Ú empty_tagsr>rC)r#ÚelrrrrÚhtml_empty_tagÕs z LXMLOutputChecker.html_empty_tagrIc Csžg}t|ƒsœ| d|¡| |¡| | |¡¡| ||¡slt|jƒr\| | |j¡¡| | |¡¡t|jƒrˆ| | |j¡¡| d¡d  |¡S| d|¡| |¡| | |¡¡| ||¡s^| d¡t|jƒr| d|¡| | |j¡¡| d¡|D]}| |  |||d¡¡q| d|¡| | |¡¡| d¡t|jƒr”| d|¡| | |j¡¡| d¡d  |¡S)NrrSrIrT) rCrWÚ format_tagrar r>Ú format_textÚformat_end_tagr?rYrZ)r#ÚdocrÚindentÚprefixÚpartsr`rrrrZßs@             zLXMLOutputChecker.format_doccCs"|dkr dS|r| ¡}t|dƒS)NrIrR)r Ú html_escape)r#r>r rrrrcs zLXMLOutputChecker.format_textc Cshg}t|tjƒrdSt|j ¡ƒD]"\}}| d|| |d¡f¡q"|sTd|jSd|jd  |¡fS)Nzú)rNrrmr<)r#r`rrrrds 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 |ƒ}|s|r˜|sD| |  |  d¡||dd¡¡q|sn| |  |  d¡||dd¡¡q| |  |  d¡|  d¡||d¡¡q| d|¡| | ||¡¡| d¡t |jƒsÚt |jƒr| d|¡| | |j|j¡¡| d¡d |¡S)NrrSrIrrTú+ú-)rCrWÚcollect_diff_tagraÚcollect_diff_textr>Úcollect_diff_end_tagr?rYr rDrZrEr[)r#r-r.rrfrhrGrHrrrr[sP        ÿ   zLXMLOutputChecker.collect_diffc Cs*| |j|j¡s"d|j|jf}n|j}g}|jdkp>d|jk}t|j ¡ƒD]p\}}||jkr€|s€| d|| |d¡f¡qN||jkr | |j||d¡}n | |d¡}| d||f¡qN|st|j ¡ƒD].\}}||jkrèqÔ| d|| |d¡f¡qÔ|rd|d |¡f}nd |}|S) Nú %s (got: %s)r:z+%s="%s"Frjz-%s="%s"rlrrk) r;r<r@rArnrWrcrurY) r#r-r.r<ror:rpr^r>rrrrt@s*   z"LXMLOutputChecker.collect_diff_tagcCs,|j|jkrd|j|jf}n|j}d|S)Nrwrq)r<)r#r-r.r<rrrrv[s z&LXMLOutputChecker.collect_diff_end_tagcCs:| |||¡r"|sdS| ||¡Sd||f}| ||¡S)NrIrw)r=rc)r#r-r.r r>rrrrubs   z#LXMLOutputChecker.collect_diff_textN)T)rI)T)T)Ú__name__Ú __module__Ú __qualname__r_r$r)r*r5r,r=r;rXrarZrcrbrdr[rtrvrurrrrrJs$  #  &c@seZdZdd„ZdS)rcCstSr )rr"rrrr$ksz%LHTMLOutputChecker.get_default_parserN)rxryrzr$rrrrrjscCs|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(rrrrrr nsc Cs`|r t}nt}tƒ}|jd}|ƒ}|j}||_|jdj}|jj}tt_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Ú__func__r)rr{Ú_RestoreChecker) rÚ del_moduleZCheckerÚframeÚdt_selfÚcheckerÚ old_checkerÚ check_funcZchecker_check_funcrrrr zs   þc@sLeZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dS)r€cCsD||_||_|j|j_||j_||_||_||_| ¡|  ¡dSr ) rƒr„Ú call_superr'r%r†Ú clone_funcrÚ install_cloneÚinstall_dt_self)r#rƒr…Z new_checkerr†rˆrrrrÚ__init__žs z_RestoreChecker.__init__cCs$|jj|_|jj|_|jj|j_dSr )r†Ú__code__Ú func_codeÚ __globals__Z func_globalsrˆr"rrrr‰©s  z_RestoreChecker.install_clonecCs|j|j_dSr )rr†rŒr"rrrÚuninstall_clone­sz_RestoreChecker.uninstall_clonecCs|jj|_||j_dSr )rƒÚ_DocTestRunner__record_outcomeÚ prev_funcr"rrrrŠ¯s z_RestoreChecker.install_dt_selfcCs|j|j_dSr )r‘rƒrr"rrrÚuninstall_dt_self²sz!_RestoreChecker.uninstall_dt_selfcCsL|jrHddl}|j|j=d|jkrH|j dd¡\}}|j|}t||ƒdS)NrÚ.rR)rrUÚmodulesÚrsplitÚdelattr)r#rUÚpackageÚmoduleZ package_modrrrÚuninstall_module´s   z _RestoreChecker.uninstall_modulecOs4| ¡| ¡|j`|j`|j||Ž}| ¡|Sr )rr’r„r%r'r‘r™)r#ÚargsÚkwÚresultrrrÚ__call__¼s z_RestoreChecker.__call__cOs(| ¡z|j||ŽW¢S| ¡XdSr )rr‰r†)r#ršr›rrrr‡Äsz_RestoreChecker.call_superN) rxryrzr‹r‰rrŠr’r™rr‡rrrrr€s r€cCs<ddl}| d¡}|r0|j}d|kr(|S|j}qtdƒ‚dS)NrrRZBOOMzBCould not find doctest (only use this function *inside* a doctest))rUÚ _getframer~Úf_backÚ LookupError)rUr‚Úlrrrr}Ës ÿr}Úbasicai >>> temp_install() >>> print """stuff""" ... >>> print """""" >>> print """blahblahblah""" # doctest: +NOPARSE_MARKUP, +ELLIPSIS ...foo /> Ú__main__)F)FN)"Ú__doc__ZlxmlrrUrJr{rrriÚ ImportErrorÚcgiÚ__all__Zregister_optionflagrrrr(r rÚ HTMLParserrrÚcompiler7rrrr r r€r}Z__test__rxÚtestmodrrrrÚsJ% ÿ     " #. ÿ