+
     hCE  c                   s   R t ^ RIHt ^ RIt^ RIt^ RIt ^ RIHt . ROt]P                  ! R4      t]P                  ! R4      t]P                  ! R4      t]P                   tR	 tR
 t]P&                  ! RRR7      tR t]P,                  ! R4      t]P,                  ! R4      t ! R R]4      t ! R R]4      tRR ltRR lt ! R R4      tR tRR/t] R8X  d   ^ RIt]PB                  ! 4        R# R#   ]	 d
    ^ RI
Ht  Li ; i)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LHTMLOutputCheckerc                 s.    V f   R # V P                  4       # N)stripZv   &:/usr/lib64/python3.14/site-packages/lxml/doctestcompare.pyr   r   8   s    ywwy    c                 s.    \         P                  R V 4      # ) )_norm_whitespace_reZsubr	   r
   r   norm_whitespacer   >   s    ""3**r   FT)ZrecoverZremove_blank_textc                 s8    \         P                  ! V \        4      # r   )r    Z
fromstring_html_parserhtmlr
   r   html_fromstringr   C   s    D,//r   z^<[^>]+ (at|object) z[ \t\n][ \t\n]+c                   s   a  ] tR t^Jt o RtR tR tR tR tR t	R t
R tR tRR	 ltRR
 ltRR ltR tR tR tR tR tRR ltRtV tR# )r   c                s"    \         P                  # r   )r    XMLselfr
   r   get_default_parserZ$LXMLOutputChecker.get_default_parserP   s    yyr   c                s^   \        V R R4      pVe   V P                  pTp M\        P                  pV P	                  WV4      pV'       g
   V! WW#4      #  V! V4      p T! T4      pT P                  Yx4      #   \
        P                   d     R# i ; i  \
        P                   d     R# i ; i)_temp_override_selfNF)Z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_docs	   &&&&     r   r   ZLXMLOutputChecker.check_outputS   s    4!6===LD(55LK8C. .	d|H	SkG   33 ## 		 ## 		s$   A7 B 7BBB,+B,c                s   R p\         V,          '       d   R # \        V,          '       d	   \        pV# \        V,          '       d   \        P
                  pV# VP                  4       P                  4       P                  R4      '       d.   VP                  4       P                  R4      '       d	   \        pV# V P                  V4      '       d(   V P                  V4      '       d   V P                  4       pV# )Nz<html)r   r   r   r   r    r   r   Zlower
startswith_looks_like_markupr   )r   r   r    r!   r"      &&&& r   r   ZLXMLOutputChecker.get_parserh   s    K''##$F  $$YYF  jjl  "--g66))+((11$F  %%d++))#..,,.Fr   c                s    VP                  4       pVP                  R 4      ;'       d    \        P                  V4      '       * # )<)r   r%   _repr_research)r   Zs   &&r   r&   Z$LXMLOutputChecker._looks_like_markupx   s7    GGIS! + + **	,r   c                s   V P                  VP                  VP                  4      '       g   R # V P                  VP                  VP                  R4      '       g   R # V P                  VP                  VP                  R4      '       g   R # RVP
                  9  d   \        VP
                  P                  4       4      p\        VP
                  P                  4       4      pW48w  d   R # V FA  pV P                  VP
                  V,          VP
                  V,          R 4      '       d   K@   R # 	  VP                  R8w  g   \        V4      '       d   \        V4      p\        V4      pV'       g	   V'       dn   V'       d	   V'       g   R # VP                  ^ 4      pVP                  ^ 4      p	V P                  W4      '       g   R # V'       d   Kg  VP                  R8X  g   Kz   R# R# )FTanyz...)tag_comparetagtext_comparetexttailattribsortedZkeyslenlistpopr   )
r   r   r    Z	want_keysZgot_keysZkeywant_childrengot_childrenZ
want_firstZ	got_firsts
   &&&       r   r   ZLXMLOutputChecker.compare_docs}   sS   #''22  CHHd;;  CHHd;;#t{{//12Icjjoo/0H$ ((S)93::c?ERR  ! 99T JM9L<$L *..q1
(,,Q/	((?? #|
5(@r   c                sD   T;'       g    R pT;'       g    R pV'       d3   \        V4      P                  4       p\        V4      P                  4       pR\        P                  ! V4      ,          pVP	                  RR4      p\        P
                  ! W4      '       d   R# R# ) z^%s$z\.\.\.z.*TF)r   r   rer   Zreplacer*   )r   r   r    r   s   &&&&r   r/   ZLXMLOutputChecker.text_compare   sx    zzriiR"4(..0D!#&,,.C		$'||It,99Tr   c                sT   VR 8X  d   R# \        V\        \        34      '       d   \        V\        \        34      '       g   W8H  # T;'       g    RpT;'       g    RpVP                  R4      '       d2   VP	                  R4      R,          VP	                  R4      R,          8H  # W8H  # )r,   Tr9   z{...}Z}i)
isinstanceZstrZbytesr%   Zsplit)r   r   r       &&&r   r-   ZLXMLOutputChecker.tag_compare   s    5=4#u..!#U|44;zzriiR??7##::c?2&#))C.*<<<;r   c                s   VP                   pV P                  WBV4      p. pVe    V! V4      p V! V4      p	Ve	   V'       dC   \        P                  WW#4      p
V'       d#   VP                  V
4       RP                  V4      # V
# V\        J pRV P                  XV^4      RV P                  X	V^4      RV P                  WyV^4      .pRP                  V4      #   \        P                   d8    \        P
                  ! 4       ^,          pTP                  RT,          4        Li ; i  \        P                   d9    \        P
                  ! 4       ^,          pTP                  RT,          4        EL=i ; i)NzIn example: %szIn actual output: %s
z	Expected:zGot:zDiff:)r   r   r    r   sysZexc_infoappendr   output_differencejoinr   
format_doccollect_diff)r   Zexampler    r!   r   r"   Zerrorsr#   Zer$   valuer   Z
diff_partss   &&&&         r   r@   Z#LXMLOutputChecker.output_difference   sR   ||K84!$<: + >V!33s1Ee$yy(((!ooha8oogtQ7''4CE
 yy$$/ '' 4LLN1%.234
 '' :LLN1%4q89:s$   C D( A	D%$D%(A	E54E5c                s    V'       g   R # VP                   V P                  9  d   R # VP                  '       g   \        V4      '       d   R # R# )FT)r.   
empty_tagsr0   r4   )r   elr   r<   r   html_empty_tagZ LXMLOutputChecker.html_empty_tag   s2    66(777c"ggr   c           	     s2   . p\        V4      '       Eg-   VP                  R V,          4       VP                  V4       VP                  V P                  V4      4       V P                  W4      '       gf   \	        VP
                  4      '       d+   VP                  V P                  VP
                  4      4       VP                  V P                  V4      4       \	        VP                  4      '       d+   VP                  V P                  VP                  4      4       VP                  R4       RP                  V4      # VP                  R V,          4       VP                  V4       VP                  V P                  V4      4       V P                  W4      '       g   VP                  R4       \	        VP
                  4      '       dT   VP                  R V,          4       VP                  V P                  VP
                  4      4       VP                  R4       V F+  pVP                  V P                  WbV^,           4      4       K-  	  VP                  R V,          4       VP                  V P                  V4      4       VP                  R4       \	        VP                  4      '       dT   VP                  R V,          4       VP                  V P                  VP                  4      4       VP                  R4       RP                  V4      # )r   r=   r9   )r4   r?   
format_tagrG   r   r0   format_textformat_end_tagr1   rA   rB   )r   Zdocr   indentZprefixpartsrF   s   &&&&&  r   rB   ZLXMLOutputChecker.format_doc   s   3xxLLV$LL LL-.&&s11??LL!1!1#((!;<T0056SXXT--chh78LL775>!SZ VT__S)*""3--LLSXXSZ(T--chh78T"T__Rvax@A LLV$LL,,S12LL??LLV$LL))#((34LLwwu~r   c                sV    Vf   R# V'       d   VP                  4       p\        V^4      # )Nr9   )r   html_escape)r   r0   r   r<   r   rI   ZLXMLOutputChecker.format_text  s%    <::<D4##r   c           	     sr   . p\        V\        P                  4      '       d   R # \        VP                  P                  4       4       F.  w  r4VP                  V: RV P                  VR4      : R24       K0  	  V'       g   RVP                  ,          # RVP                  : RRP                  V4      : R2# )z<!--="F"<%s>r(   r   >)
r;   r    CommentBaser3   r2   itemsr?   rI   r.   rA   )r   rF   attrsnamerD   s   &&   r   rH   ZLXMLOutputChecker.format_tag	  s    b%++,,!"))//"34KDLLdD,<,<UE,JKL 5BFF?" FFCHHUO44r   c                sl    \        V\        P                  4      '       d   R # RVP                  ,          # )z--></%s>)r;   r    rR   r.   )r   rF   r+   r   rJ   Z LXMLOutputChecker.format_end_tag  s'    b%++,,r   c           	     s   . p\        V4      '       Eg   \        V4      '       g   VP                  R V,          4       VP                  V P                  W4      4       V P                  W#4      '       gV   VP                  V P	                  VP
                  VP
                  4      4       VP                  V P                  W4      4       VP                  V P	                  VP                  VP                  4      4       VP                  R4       RP                  V4      # VP                  R V,          4       VP                  V P                  W4      4       VP                  R4       \        VP
                  4      '       g   \        VP
                  4      '       d_   VP                  R V,          4       VP                  V P	                  VP
                  VP
                  4      4       VP                  R4       \        V4      p\        V4      pV'       g	   V'       d   V'       g;   VP                  V P                  VP                  ^ 4      W4^,           R4      4       KR  V'       g;   VP                  V P                  VP                  ^ 4      W4^,           R4      4       K  VP                  V P                  VP                  ^ 4      VP                  ^ 4      W4^,           4      4       K  VP                  R V,          4       VP                  V P                  W4      4       VP                  R4       \        VP                  4      '       g   \        VP                  4      '       d_   VP                  R V,          4       VP                  V P	                  VP                  VP                  4      4       VP                  R4       RP                  V4      # )r   r=   r9   +-)r4   r?   collect_diff_tagrG   collect_diff_textr0   collect_diff_end_tagr1   rA   r   r5   rB   r6   rC   )r   r   r    r   rK   rL   r7   r8   s   &&&&&   r   rC   ZLXMLOutputChecker.collect_diff  s   4yySLLV$LL..t9:&&s11T33DIIsxxHIT66tABLL//		388DELL775>!SZ T**456TuSXXLLV$LL//		388DELLT
Cy| T__\-=-=a-@$qRUVWT__]->->q-A4PQSVWXLL**!!!$l&6&6q&94K LSZ T..t9:TuSXXLLV$LL//		388DELLwwu~r   c           
     s   V P                  VP                  VP                  4      '       g    VP                  : R VP                  : R2pMVP                  p. pVP                  R8H  ;'       g    RVP                  9   p\        VP                  P	                  4       4       F  w  rgWaP                  9  d5   V'       g-   VP                  RV: RV P                  VR4      : R24       KI  WaP                  9   d&   V P                  VP                  V,          VR4      pMV P                  VR4      pVP                  V: RV: R24       K  	  V'       gi   \        VP                  P	                  4       4       FA  w  rgWbP                  9   d   K  VP                  RV: RV P                  VR4      : R24       KC  	  V'       d   RV: R	R	P                  V4      : R
2pV# RV,          pV# ) (got: )r,   rW   rN   FrO   rX   r(   r   rQ   rP   )	r-   r.   r2   r3   rS   r?   rI   rZ   rA   )	r   r   r    r.   rT   r,   rU   rD   r0   s	   &&&      r   rY   Z"LXMLOutputChecker.collect_diff_tag@  sl   #''22$(HHcgg6C''Chh%775DKK#7!#**"2"2"45KD;;&s41A1A%1OPQ;;&11$++d2CUERD++E59D$56 6 %dkk&7&7&9:::%41A1A%1OPQ  ; 5"CHHUO4C 
 3,C
r   c                s    VP                   VP                   8w  d(   VP                   : R VP                   : R2pRV,          # VP                   pRV,          # )r\   r]   rV   )r.   )r   r   r    r.   s   &&& r   r[   Z&LXMLOutputChecker.collect_diff_end_tag[  sE    88sww$(HHcgg6C } ''C}r   c                s    V P                  WV4      '       d   V'       g   R # V P                  W#4      # V: RV: R2pV P                  WC4      # )r9   r\   r]   )r/   rI   )r   r   r    r   r0   r'   r   rZ   Z#LXMLOutputChecker.collect_diff_textb  sG    T..##C//!%s+,,r    N)
ZparamZimgZareaZbrZbasefontZinputZbaseZmetaZlinkZcol)T)r9   )__name__
__module____qualname____firstlineno__rE   r   r   r   r&   r   r/   r-   r@   rG   rB   rI   rH   rJ   rC   rY   r[   rZ   __static_attributes____classdictcell__Z__classdict__   @r   r   r   J   si     'J4* ,
:%@!F$	5 $L6- -r   c                   s&   a  ] tR tRt o R tRtV tR# )r   ij  c                s    \         # r   )r   r   r
   r   r   Z%LHTMLOutputChecker.get_default_parserk  s    r   r^   N)r_   r`   ra   rb   r   rc   rd   re   rf   r   r   r   j  s      r   c                sV    V '       d   \         \        n        R# \        \        n        R# )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   installrh   n  s      2 1r   c                s<   V '       d   \         pM\        p\        4       pVP                  R,          pV! 4       pVP                  pWTn        VP                  R,          P
                  pVP                  P
                  p\        \        n        \        WFVWxV4       R# )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_checkerZ__func__r   r    rg   _RestoreChecker)	r   
del_moduleZCheckerframedt_selfcheckerold_checker
check_funcZchecker_check_funcs	   &&       r   temp_installrr   z  s     $#!EnnV$GiG""K (11J --66 GMG' r   c                   sP   a  ] tR tRt o R tR tR tR tR tR t	R t
R	 tR
tV tR# )rk   i  c                s    Wn         W n        V P                  V P                  n        W0P                  n        W@n        WPn        W`n        V P                  4        V P                  4        R # r   )
rn   ro   
call_superr   r   rq   
clone_funcrl   install_cloneinstall_dt_self)r   rn   rp   Znew_checkerrq   rt   rl   s   &&&&&&&r   __init__Z_RestoreChecker.__init__  sM    "59__2+6($$$r   c                s    V P                   P                  V n        V P                   P                  V n        V P
                  P                  V P                   n        R # r   )rq   __code__	func_codeZ__globals__func_globalsrt   r   r
   r   ru   Z_RestoreChecker.install_clone  s;    11 OO77#'??#;#; r   c                <    V P                   V P                  n        R # r   )ry   rq   rx   r   r
   r   uninstall_cloneZ_RestoreChecker.uninstall_clone  s    #'>> r   c                s\    V P                   P                  V n        W P                   n        R # r   )rn   _DocTestRunner__record_outcome	prev_funcr   r
   r   rv   Z_RestoreChecker.install_dt_self  s    DD6:3r   c                r{   r   )r~   rn   r}   r   r
   r   uninstall_dt_selfZ!_RestoreChecker.uninstall_dt_self  s    6:nn3r   c                s   V P                   '       dm   ^ RIpVP                  V P                    RV P                   9   d?   V P                   P                  R^4      w  r#VP                  V,          p\	        WC4       R# R# R# )    NZ.)rl   r>   ZmodulesZrsplitZdelattr)r   r>   ZpackageZmoduleZpackage_mods   &    r   uninstall_moduleZ _RestoreChecker.uninstall_module  sb    ???DOO,doo%"&//"8"8a"@!kk'2, & r   c                s    V P                  4        V P                  4        V P                  =V P                  =V P
                  ! V/ VB pV P                  4        V# r   )r|   r   ro   r   r   r~   r   )r   argskwZresults   &*, r   __call__Z_RestoreChecker.__call__  sR     LL,LL6,,r   c                s    V P                  4         V P                  ! V/ VB V P                  4        #   T P                  4        i ; ir   )r|   rq   ru   )r   r   r   s   &*,r   rs   Z_RestoreChecker.call_super  s=    	!??D/B/ D s	   4 A)rq   ro   rt   rl   rn   ry   rz   r~   N)r_   r`   ra   rb   rw   ru   r|   rv   r   r   r   rs   rc   rd   re   rf   r   rk   rk     s3     
<2;E-! !r   rk   c                  s    ^ RI p V P                  ! ^4      pV'       d$   VP                  pRV9   d   V# VP                  pK+  \	        R4      h)r   NZBOOMzBCould not find doctest (only use this function *inside* a doctest))r>   Z	_getframerj   Zf_backZLookupError)r>   rm   Zls      r   ri   ri     sF    MM!E
NNQ;L
LN Nr   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>
    Z__main__)r   r   r   r   r   rh   rr   )F)FN)"Z__doc__Zlxmlr    r>   r:   rg   r   r   rM   ZImportErrorZcgiZ__all__Zregister_optionflagr   r   r   r   r   r   Z
HTMLParserr   r   Zcompiler)   r   r   r   rh   rr   rk   ri   Z__test__r_   Ztestmodr^   r   r   <module>r      s$  #J  
 	 **< ((6
''4	,,-=>%%+ F0 ::-.jj!34 ^- ^-@	* 
2! F,! ,!\
N  
	 zOO q  *)*s   C4 4DD