
    }c!                        d Z ddlZddlZddlZddlZddlZddlmZ ddlm	Z	m
Z
mZmZmZmZ ddlmZ ddlmZ ddlmZ ddlmZmZ dd	lmZmZ dd
lmZ ddlmZ ddlm Z  g dZ!d+dede"de#ddfdZ$d+dede"de#ddfdZ%de"de"ddfdZ&d,dede
de"de
ddf
dZ'de"de
fdZ( G d d           Z) G d! d"ej*                  Z+ G d# d$          Z, ej-        d%          Z.d-d&e"d'e/dee"ddf         fd(Z0de"de"fd)Z1d* Z2dS ).zSphinx test suite utilities    N)StringIO)IOAnyDict	GeneratorListPattern)ElementTree)nodes)Node)
directivesroles)applicationlocale)ModuleAnalyzerpath)relpath)StructSphinxTestApp#SphinxTestAppWrapperForSkipBuildingregextextflagsreturnc                 P    t          j        | ||          sJ | d|            d S )NFz did not match researchr   r   r   s      3lib/python3.11/site-packages/sphinx/testing/util.pyassert_re_searchr"      s;    9UD%(( <;uuudd;;;;< <    c                 P    t          j        | ||          rJ | d|            d S )NFz did match r   r    s      r!   assert_not_re_searchr%      s;    	ye$$ 87555$$77778 8r#   thingprefixc                 N    |                      |          sJ | d|            d S )NFz does not start with 
startswith)r&   r'   s     r!   assert_startswithr+   #   s>    F## DCUUUFFCCCCD Dr#    nodeclsxpathkwargsc                    |rt          |t                    rt          | |d         fd|i| |dd          rt          |d         t                    rt          | |d         fd|i| nt          | t          j                  sJ d|z              t          |           dk    sJ d|t          |           fz              t          | d         |dd          fd|dz   i| nt          |t                    rt          | t          t          j        f          sJ d|z              t          |           t          |          k    s*J d|t          |           t          |          fz              t          |          D ]#\  }}|d	|z  z   }t          | |         |fd|i| $nRt          |t                    r| |k    sJ d
|d|d|             n#t          | |          sJ d|d|d|             |rt          | t          j                  sJ d|z              |	                                D ]F\  }}|| v sJ d|d|d|             | |         |k    sJ d|d|d|d| |                     Ed S d S )Nr   r/      z%The node%s does not have any childrenz&The node%s has %d child nodes, not onez[0]z"The node%s does not have any itemsz%The node%s has %d child nodes, not %rz[%d]z	The node z is not z: zThe nodez is not subclass of z'The node%s does not have any attributesz does not have z attribute: [z	] is not )

isinstancelistassert_nodetupler   Elementlen	enumeratestritems)	r-   r.   r/   r0   inodeclsr   keyvalues	            r!   r6   r6   (   s   
 Lc4   	Lc!f<<E<V<<<122w Qc!fe,, Qc!fDDEDVDDDD%dEM:: H H?%GH H Ht99> V V@E3t99CUUV V VQQRRPPPPPPU## 	LdT5=$9:: = =4u<= = =t99C( W W75#d))SQTXX:VVW W W'nn D D
7vz)DGWCCDCFCCCCD S!! 	L3;PPPuuuccc44 PPPPPdC(( L L L:?%%ddKL L L  P$.. 	> 	>5=	> 	> 	> !,,.. 	P 	PJC$; Q Q Q?Duuccc44PQ Q Q9% P P P27%%eeeT#YYOP P P PP P	P 	Pr#   r   c                     t          j        d          5  t          j        dt                     t	          j        |           cd d d            S # 1 swxY w Y   d S )NF)recordignore)category)warningscatch_warningsfilterwarningsDeprecationWarningr
   parser   s    r!   etree_parserJ   N   s    		 	.	.	. ' '3EFFFF &&' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' 's   /AAAc                       e Zd ZdeddfdZdS )r   r0   r   Nc                 :    | j                             |           d S N)__dict__update)selfr0   s     r!   __init__zStruct.__init__U   s    V$$$$$r#   )__name__
__module____qualname__r   rQ    r#   r!   r   r   T   s6        % % % % % % % %r#   r   c                        e Zd ZU dZdZeed<   dZeed<   	 	 	 	 dded	e	d
e	de
dedededee         dededdf fdZdde
ddfdZdefdZ xZS )r   z
    A subclass of :class:`Sphinx` that runs on the test root, with some
    better default values for the initialization parameters.
    N_status_warninghtmlFr   buildernamesrcdirbuilddirfreshenvconfoverridesstatuswarningtagsdocutilsconfparallelr   c                    |	|dz                       |	           ||dz  }|}|                    |          }|                    d           |                    d          }|                    d           |i }d}t          j        d d          | _        t          j                                        | _	        t          j                                        | _        d t          t          j                  D             | _        	 t#                                          ||||||||||||
           d S # t&          $ r |                                   w xY w)	Nzdocutils.conf_buildT)exist_okdoctreesFc                 <    h | ]}|                     d           |S )visit_r)   ).0vs     r!   	<setcomp>z)SphinxTestApp.__init__.<locals>.<setcomp>y   s8     #> #> #>&'ll8&<&<#>1 #> #> #>r#   )rc   )
write_textjoinpathmakedirssysr   _saved_pathr   _directivescopy_saved_directivesr   _roles_saved_rolesdirr   GenericNodeVisitor_saved_nodeclassessuperrQ   	Exceptioncleanup)rP   rZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   confdiroutdir
doctreedirwarningiserror	__class__s                  r!   rQ   zSphinxTestApp.__init__a   s   
  	@o%11,??? 	)(H"";//&&&&&z22
T*** 	M8AAA;!+!7!<!<!>!>!L--//#> #>c%2J.K.K #> #> #>	GGVWfj(-%~th  P P P P P  	 	 	LLNNN	s   	-D8 8 Erg   c                 6   t           j                                         t          j                                         | j        t          j        d d <   t          j        	                    dd            | j
        t          _        | j        t          _        t!          t"          j                  D ]j}|                    d          rS|| j        vrJt+          t"          j        d|dd          z              t+          t"          j        d|dd          z              kd S )Nautodoc_fodderri      depart_)r   cacheclearr   translatorsrq   rp   r   modulespoprt   r   rr   rv   r   ru   rw   r   rx   r*   ry   delattr)rP   rg   methods      r!   r|   zSphinxTestApp.cleanup   s    ""$$$  """&($///!%!7
(%233 	J 	JF  ** JT44J0(VABBZ2GHHH0)fQRRj2HIII		J 	Jr#   c                 <    d| j         j        d| j        j        dS )N<z buildername=>)r   rR   buildername)rP   s    r!   __repr__zSphinxTestApp.__repr__   s%     (,(?(?(?ARARARSSr#   )
rY   NNFNNNNNr   )F)rR   rS   rT   __doc__rW   r   __annotations__rX   r;   r   boolr   r   r   intrQ   r|   r   __classcell__)r   s   @r!   r   r   Y   s-          GXHhX\RVQU!"! !C !$ !QU !!8<!MO!!+/9!KN! ! (,! ! ! ! ! !FJ J J J J J JT# T T T T T T T Tr#   r   c                   F    e Zd ZdZdeddfdZdedefdZded	eddfd
Z	dS )r   z
    This class is a wrapper for SphinxTestApp to speed up the test by skipping
    `app.build` process if it is already built and there is even one output
    file.
    app_r   Nc                     || _         d S rM   )app)rP   r   s     r!   rQ   z,SphinxTestAppWrapperForSkipBuilding.__init__   s    r#   r   c                 ,    t          | j        |          S rM   )getattrr   )rP   r   s     r!   __getattr__z/SphinxTestAppWrapperForSkipBuilding.__getattr__   s    tx&&&r#   argsr0   c                 j    | j         j                                        s | j         j        |i | d S d S rM   )r   r~   listdirbuild)rP   r   r0   s      r!   r   z)SphinxTestAppWrapperForSkipBuilding.build   sC    x&&(( 	,DHND+F+++++	, 	,r#   )
rR   rS   rT   r   r   rQ   r;   r   r   r   rU   r#   r!   r   r      s         ] t    ' ' ' ' ' ',3 ,# ,$ , , , , , ,r#   r   zu(".*?")|u(\'.*?\')rootsuffixc              #      K   t          j        | d          D ]=\  }}}t          |          }fd|D             D ]}||z  }t          ||           V  >d S )NT)followlinksc                 B    g | ]}r|                               |S rU   )endswith)rj   fr   s     r!   
<listcomp>zfind_files.<locals>.<listcomp>   s/    GGG&GAJJv4F4FG!GGGr#   )oswalkr   r   )r   r   dirpath_dirsfilesr   fpaths    `     r!   
find_filesr      s      !#4!@!@!@ ' 'w--GGGGUGGG 	' 	'AaKE%&&&&&&	'' 'r#   c                 .    t          j        dd|           S )Nz.*?mr,   )r   sub)r   s    r!   strip_escseqr      s    6*b$'''r#   c                 F     t          j                    fd            }|S )zA
    A simple decorator that does nothing, for tests to use.
    c                       | i |S rM   rU   )r   r0   r   s     r!   wrapperz!simple_decorator.<locals>.wrapper   s    q$!&!!!r#   )	functoolswraps)r   r   s   ` r!   simple_decoratorr      s8     _Q" " " " "Nr#   )r   )Nr,   rM   )3r   r   r   r   rp   rE   ior   typingr   r   r   r   r   r	   	xml.etreer
   docutilsr   docutils.nodesr   docutils.parsers.rstr   r   sphinxr   r   sphinx.pycoder   sphinx.testing.pathr   sphinx.util.osutilr   __all__r;   r   r"   r%   r+   r6   rJ   r   Sphinxr   r   compile_unicode_literals_rer   r   r   r   rU   r#   r!   <module>r      s=   ! !     				 				 



        : : : : : : : : : : : : : : : : ! ! ! ! ! !             2 2 2 2 2 2 2 2 & & & & & & & & ( ( ( ( ( ( $ $ $ $ $ $ & & & & & &  
< <G <3 <s <4 < < < <
8 8 8s 83 8t 8 8 8 8
DS D# D$ D D D D
#P #Pd #P #PC #P #PPT #P #P #P #PL'c 'c ' ' ' '% % % % % % % %
9T 9T 9T 9T 9TK& 9T 9T 9Tx, , , , , , , ,( "rz"899 ' 'S '$ ')CtO2L ' ' ' '(s (s ( ( ( (    r#   