
    }c[                        d Z ddlZddlZddlmZmZmZmZmZm	Z	m
Z
mZmZmZmZ ddlmZ ddlmZmZ ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ erddl m!Z! ddl"m#Z# ddl$m%Z% ddl&m'Z'  ej(        e)          Z* ej+        dej,                  Z-e-Z. G d d          Z/dede0fdZ1ddede2de0fdZ3deddfdZ4ej5        ej6        ej7        ej8        fZ9dede:fdZ;dede:fdZ<ej6        ej7        ej=        ej>        fZ?ej@        fZAejB        fZCdedeeee0f                  fdZDdede	e0         fdZEdede	e2         fdZFdded edee         fd!ZGdede	e         fd"ZHdedeeeed#         f                  fd$ZId%ed&edede0fd'ZJdede0fd(ZKd)e0dee:e0e0f         fd*ZLg d+ZMd,e0d-e0deee0e0e0e0e	e0         f                  fd.ZNd/d0d1e
e0         d2e0d3ejO        d4ed5ee0         dejO        fd6ZPd7e0de0fd8ZQ ej+        d9          ZR ej+        d:          ZSi d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdHdJdKdLd>dMdNdOdPdQdDdRdSdTdUdVdFdWdFi dXdYdZd[d\d]d^d[d_dDd`dSdadFdbdcdddKdedfdgd[dhdidjdcdkdldmdndodYZTdpdqdrdsdtduZU	 ddwdxdyejO        dze0d{e0de0f
d|ZVdejW        d}e0de	e         fd~ZX	 dd/d0de0de0d-e0deeee         f         de0dejY        fdZZdededdfdZ[dede2deddfdZ\dededdfdZ]ej^        ej_        ej`        ej@        ej>        eja        ejb        fZcdede:fdZddyeddddfdZededefdZfefej        _g        dS )z3Docutils node-related utility functions for Sphinx.    N)TYPE_CHECKINGAnyCallableIterableListOptionalSetTupleTypeUnioncast)nodes)ElementNode)	Directive)Inliner)
StringList)addnodes)__)logging)Builder)
IndexEntry)BuildEnvironment)Tagsz^(.+?)\s*(?<!\x00)<([^<]*?)>$c                   R    e Zd ZdZdee         deddfdZdedefdZ	dedefd	Z
dS )
NodeMatchera"  A helper class for Node.findall().

    It checks that the given node is an instance of the specified node-classes and
    has the specified node-attributes.

    For example, following example searches ``reference`` node having ``refdomain``
    and ``reftype`` attributes::

        matcher = NodeMatcher(nodes.reference, refdomain='std', reftype='citation')
        doctree.findall(matcher)
        # => [<reference ...>, <reference ...>, ...]

    A special value ``typing.Any`` matches any kind of node-attributes.  For example,
    following example searches ``reference`` node having ``refdomain`` attributes::

        from typing import Any
        matcher = NodeMatcher(nodes.reference, refdomain=Any)
        doctree.findall(matcher)
        # => [<reference ...>, <reference ...>, ...]
    node_classesattrsreturnNc                 "    || _         || _        d S N)classesr   )selfr   r   s      1lib/python3.11/site-packages/sphinx/util/nodes.py__init__zNodeMatcher.__init__6   s    #


    nodec                 D   	 | j         rt          || j                   sdS | j        rht          |t          j                  sdS | j                                        D ]2\  }}||vr dS |t          u r|                    |          |k    r dS 3dS # t          $ r Y dS w xY w)NFT)	r"   
isinstancer   r   r   itemsr   get	Exception)r#   r'   keyvalues       r$   matchzNodeMatcher.match:   s    	| JtT\$B$B uz 
%!$66 ! 5"&*"2"2"4"4 % %JC$ %$uu# % #%/ %$uu% 4 	 	 	55	s(   B !B #B ($B B 
BBc                 ,    |                      |          S r!   )r/   )r#   r'   s     r$   __call__zNodeMatcher.__call__P   s    zz$r&   )__name__
__module____qualname____doc__r   r   r   r%   boolr/   r1    r&   r$   r   r       s         *d4j 3 4    $ 4    , T  d            r&   r   r'   r   c                 L    d                     | j        | j        j                  S )z
    Return full module dotted path like: 'docutils.nodes.paragraph'

    :param nodes.Node node: target node
    :return: full module dotted path
    z{}.{})formatr3   	__class__r2   r'   s    r$   get_full_module_namer<   T   s     >>$/4>+BCCCr&   P   lengthc                     	 |                                                                  }n# t          $ r t          |           }Y nw xY w|r t	          |          |k    r|d|         dz   }|S )a  
    return DOM XML representation of the specified node like:
    '<paragraph translatable="False"><inline classes="versionmodified">New in version...'

    :param nodes.Node node: target node
    :param int length:
       length of return value to be striped. if false-value is specified, repr_domxml
       returns full of DOM XML representation.
    :return: DOM XML representation
    Nz...)asdomtoxmlr,   strlen)r'   r>   texts      r$   repr_domxmlrE   ^   s}    zz||!!##   4yy %#d))f$ %GVG}u$Ks   &) AAc                    t          | t          j                  ry| j        srt                              dt          |           t          |                      | j        }|j	        | _	        |j
        dz
  | _
        |                                 | _        n2t          | t          j                  r| j	        s| j        j	        | _	        t          | t          j                  r`| j	        Yt                              dt          |           t          |                      | j        j	        | j        j
        c| _	        | _
        t          | t          j                  r`| j	        Yt                              dt          |           t          |                      | j        j	        | j        j
        c| _	        | _
        t          | t          j                  rt                              dt          |           t          |                      t          t!          | j                            t          j                                      D ]I}t%          j        dt%          j        |                                          z  d| j                  | _        Jt          | t          j                  r`| j	        Yt                              dt          |           t          |                      | j        j	        | j        j
        c| _	        | _
        t          | t          j                  r| j	        t/          |           | _	        | j        s|                                 | _        | j	        r	| j        rd S t          | t          j        t          j
        t          j        t          j        f          rUt                              dt          |           t          |                      t/          |           pd| _	        d	| _
        d S d S )
Nz7[i18n] PATCH: %r to have source, line and rawsource: %s   z)[i18n] PATCH: %r to have source, line: %sz#[i18n] PATCH: %r to have source: %sz&[i18n] PATCH: %r to have rawsource: %sz	\s*:\s*%s z,[i18n] PATCH: %r to have source and line: %sr   )r)   r   
classifier	rawsourceloggerdebugr<   rE   parentsourcelineastextimagetitletermreversedlistfindallresubescapetopicliteral_blockget_node_sourcerubric
field_name)r'   definition_list_itemrI   s      r$   apply_source_workaroundr`   r   s    $()) 	)$. 	)N)$//T1B1B	D 	D 	D#{*1(-1		D%*	+	+ )DK )k($$$ F F@)$//T1B1B	D 	D 	D!%!3T[5ETY$$$ F F:)$//T1B1B	D 	D 	D!%!3T[5ETY$
## 8=)$//T1B1B	D 	D 	D #4(;(;E<L(M(M#N#NOO 	8 	8JVL29Z=N=N=P=P3Q3Q$Q$&8 8DNN$$$ F F@)$//T1B1B	D 	D 	D!%!3T[5ETY $+,, , ,%d++ > '{ t~  	4LJK	 	 	 
 	C)$//T1B1B	D 	D 	D%d++1r	
 
r&   c                     t          | t          j                  r<t          | j                            dd g          d         t
          j                  rdS dS )Nr   r   TF)r)   r   pendingdetailsr+   r   metar;   s    r$   is_pending_metare      sM    4'' $,""7TF33A6FFtur&   c                 T   t          | t          j                  rdS t          | t          j                  r,|                     d          s|                     d          rdS t          | t          j                  rd| vrdS t          | t          j                  rC| j        s8t          
                    dt          |           t          |                      dS t          | t                    r<d| vr8t          
                    dt          |           t          |                      dS |                     dd          s8t          
                    dt          |           t          |                      dS t          | t          j                  rI| j        d         d	k    r8t          
                    d
t          |           t          |                      dS dS t!          |           st          | t          j                  rdS t          | t          j                  rdS dS )NTtranslatablealtFz)[i18n] SKIP %r because no node.source: %szO[i18n] SKIP %r because node is in IGNORED_NODES and no node['translatable']: %sz3[i18n] SKIP %r because not node['translatable']: %sr   orphanz&[i18n] SKIP %r because orphan node: %s)r)   r   rg   r   rQ   r+   InlineTextElementrN   rK   rL   r<   rE   IGNORED_NODESr^   childrenre   rd   docutils_metar;   s    r$   is_translatablero      s%   $-.. t $$$ $((>*B*B dhhuoo t$%% .*D u$)** { 	LLD-d33[5F5FH H H5dM** 	~T/I 	LL ;-d33[5F5FH H H 5xx-- 	LLN-d33[5F5FH H H5 dE,-- 	$-2Bh2N 	LLA-d33[5F5FH H H5tt 
4 ? ? t	D(0	1	1 t5r&   doctreec              #   L  K   |                      t                    D ]}t          |t          j                  r|                                D ]}||fV  	;t          |t                    r|j        }|s|                                }nt          |t          j
                  rE|                    d          r||d         fV  |                    d          rd|d         z  }nd}nt          |t                    r|j        }nt          |t          j                  r(t          |          r|j        d         d         j        }nPt          |t          j                  r	|d         }n-|j                            d	d
                                          }|r||fV  dS )z3Extract translatable messages from a document tree.rh   rg   z.. image:: %surirH   r   r   content
 N)rV   ro   r)   r   rg   extract_original_messagesLITERAL_TYPE_NODESrJ   rP   r   rQ   r+   META_TYPE_NODES
rawcontentrb   re   rc   rn   replacestrip)rp   r'   msgs      r$   extract_messagesr}      s     00  dH122 	5577    Cid.// 	<.C $kkmmek** 	<xx (DK''''xx'' %U3o.. 
	</CCem,, 	<1F1F 	<,w'*5CCh455 	<y/CC.((s3399;;C  	)OOO= r&   c                 J    t          |           D ]}|j        r	|j        c S d S r!   )traverse_parentrN   r'   pnodes     r$   r\   r\     s;     &&    < 	 <	 4r&   c                 J    t          |           D ]}|j        r	|j        c S d S r!   )r   rO   r   s     r$   get_node_liner   &  s;     &&  : 	:	4r&   clsc              #   P   K   | r!|t          | |          r| V  | j        } | d S d S r!   )r)   rM   )r'   r   s     r$   r   r   -  sU      
  	*T3// 	JJJ{      r&   c                 f    | j                             |           }|dk    r| j         |dz
           S d S )Nr   rG   )rM   index)r'   poss     r$   get_prev_noder   4  s9    
+

D
!
!C
Qw {37##tr&   r   c              #      K   t          t          j        d          }|                     |          D ]}d|v r	|d         }n|d         }||fV  dS )z6Traverse translatable index node from a document tree.F)inlineraw_entriesentriesN)r   r   r   rV   )rp   matcherr'   r   s       r$   traverse_translatable_indexr   <  st      (.777G((  D  	&=)GG9oGGm r&   staters   c                     | j         j        }| j         j        }g | j         _        d| j         _        	 |                     |d|d          || j         _        || j         _        S # || j         _        || j         _        w xY w)zVersion of state.nested_parse() that allows titles and does not require
    titles to have the same decoration as the calling document.

    This is useful when the parsed content comes from a completely different
    context, such as docstrings.
    r   rG   )match_titles)memotitle_stylessection_levelnested_parse)r   rs   r'   surrounding_title_stylessurrounding_section_levels        r$   nested_parse_with_titlesr   G  s      %z6 %
 8 EJ EJ=!!'1d!CC":
#<
   #;
#<
 <<<<s   A# #A=c                 2   |                                  } |                     t          j                  D ]}d|d<   t	          |                     t          j                            D ]}|j                            |           |                                 S )z&Like node.astext(), but ignore images.rH   rh   )	deepcopyrV   r   rQ   rU   rawrM   removerP   )r'   imgr   s      r$   clean_astextr   Z  s    ==??D||EK((  E

DLL++,,  
#;;==r&   rD   c                     t                               |           }|r+d|                    d          |                    d          fS d| | fS )z3Split role content into title and target, if given.TrG      F)explicit_title_rer/   group)rD   r/   s     r$   split_explicit_titler   d  sK    ##D))E 4U[[^^U[[^^33$r&   )singlepairdoubletripleseeseealsoentrytargetidc                 r   ddl m} g }|                                 } | }d}|                     d          rd}| dd                                          } |D ]p}|                     |dz             rV| t          |          dz   d                                          }||         dz   |z   }|                    d	|||d f            nqt          D ]j}|                     |dz             rP| t          |          dz   d                                          }|d
k    rd	}|                    ||||d f            nk|                    d          D ]h}|                                }d}|                    d          rd}|dd                                          }|sN|                    d|||d f           i|S )Nr   )pairindextypesrH   !mainrG   :z; r   r   ,r   )	sphinx.domains.pythonr   r{   
startswithlstriprC   append
indextypessplit)r   r   r   indexentriesoentryr   typer.   s           r$   process_index_entryr   q  s   444444CELKKMMEFD #abb	  "" M MD3J'' 	#d))a-..)//11E"4(4/%7E$ EFFFE		  	M 	MDs
++ c$ii!mnn-33558# "!D##T5(D$$GHHH  c** M M##C(( /!D!!""I,,..E ##Xuhd$KLLLLr&   builderr   
docnamesetdocnametree	colorfunc	traversedc           
         t          t          j        |                                          }t	          |                    t          j                            D ]c}g }t          t          |d                   }|D ]$}	|	|vr	 |
                    |	           t                               ||	          dz   d           t          | ||	| j                            |	          ||          }
|                    |	           t          j        |	          }|
j        |_        |                    t          j                  D ]}d|vr|	|d<   |
                    |           # t(          $ r. t                              t-          d          |	|           Y  w xY w&|j                            ||           e|S )	zwInline all toctrees in the *tree*.

    Record all docnames in *docnameset*, and output docnames with *colorfunc*.
    includefilesru   T)nonl)r   r   z+toctree contains ref to nonexisting file %rlocation)r   r   documentr   rU   rV   r   toctreemaprB   r   rK   infoinline_all_toctreesenvget_doctreeaddstart_of_filerm   sectionr,   warningr   rM   rz   )r   r   r   r   r   r   toctreenodenewnodesr   includefilesubtreesofsectionnodes                r$   r   r     s    00DDLL)9::;; : :3N ;<<' 	) 	)K)+ ))$$[111KK		+ 6 6 <4KHHH1':{29+2I2I+2V2V2;YH HG NN;///
 #0EEEC#*#3CL'*{{5='A'A A A$K7 A5@K	2OOC(((( ! B B BNN2&S#T#T#. # B B B B BB)$ 	"";9999Ks   A>E$$4FFstringc                    |                      t                    }|                     t                    }t          j        d|                              dd                              d          }t                              dd	                    |
                                                    }t                              d|          }t          |          S )a  Convert `string` into an identifier and return it.

    This function is a modified version of ``docutils.nodes.make_id()`` of
    docutils-0.16.

    Changes:

    * Allow to use capital alphabet characters
    * Allow to use dots (".") and underscores ("_") for an identifier
      without a leading character.

    # Author: David Goodger <goodger@python.org>
    # Maintainer: docutils-develop@lists.sourceforge.net
    # Copyright: This module has been placed in the public domain.
    NFKDasciiignore-ru   rH   )	translate_non_id_translate_digraphs_non_id_translateunicodedata	normalizeencodedecode_non_id_charsrX   joinr   _non_id_at_endsrB   )r   ids     r$   _make_idr     s      
		4	5	5B	'	(	(B 
	vr	*	*	1	1'8	D	D	K	KG	T	TB			3 4 4	5	5B			R	$	$Br77Nr&   z[^a-zA-Z0-9._]+z^[-0-9._]+|-+$   oi  di'  hi1  iiB  lig  ti  bi  i  ci  i  fi  ki  i  ni  pi  i  i  yi  zi  gi%  i4  i5  i6  i7  ji<  i?  si@  iG  eiI  iK  qiM  riO  szaeoedbqp)      iS  i8  i9  rH   r   r   r   prefixrS   c                    d}|r|dz   }n|j         j        pddz   }|r|rt          ||z            }||k    rd}n|rt          |          }|dk    rd}|	||j        v r#||                     |          z  }|||j        v #|S )z>Generate an appropriate node_id for given *prefix* and *term*.Nz-%sr   z%srH   )settings	id_prefixr   idsnew_serialno)r   r   r  rS   node_ididformats         r$   make_idr    s     G @E>%/744?  $ 8d?++f 	G	 4..b= 	G
 6W4 6S--f555  6W4 6 Nr&   	conditionc                 ~    | D ]9}t          |t          j                  r|                    d          |k    r|c S :dS )zBPick matched pending_xref_condition node up from the pending_xref.r  N)r)   r   pending_xref_conditionr+   )r'   r  subnodes      r$   find_pending_xref_conditionr    sP       w ?@@ 	K((I5	NNNtr&   fromdocname	todocnamechildrR   c                     t          j        ddd          }||k    r|r||d<   n;|r |                     ||          dz   |z   |d<   n|                     ||          |d<   |r||d<   ||z  }|S )z$Shortcut to create a reference node.rH   T)internalrefid#refurireftitle)r   	referenceget_relative_uri)r   r  r  r   r  rR   r'   s          r$   make_refnoder   (  s     ?2rD111Di NH N W 	N%66{INN!"$,-DNN %55k9MMDN ! ZEMDKr&   	directivec                 ^    | j                             | j                  \  |_        |_        d S r!   )state_machineget_source_and_linelinenorN   rO   )r!  r'   s     r$   set_source_infor&  :  s*    33I4DEE DKr&   inlinerr%  c                 T    | j                             |          \  |_        |_        d S r!   )reporterr$  rN   rO   )r'  r%  r'   s      r$   set_role_source_infor*  ?  s%    $-AA&IIDKr&   srcdstc                 V    t          |           |_        t          |           |_        d S r!   )r\   rN   r   rO   )r+  r,  s     r$   copy_source_infor.  C  s$     %%CJS!!CHHHr&   c                     t          | j                  D ]5}t          |t                    r dS |                    dd          du r dS 6t          | dd          du rdS dS )z0Check whether the node is smart-quotable or not.Fsupport_smartquotesNT)r   rM   r)   NON_SMARTQUOTABLE_PARENT_NODESr+   getattrr   s     r$   is_smartquotabler3  S  s     --  e;<< 	55YY,d33u< 	55	 t*D11U: u4r&   tagsr   c                 
   |                      t          j                  D ]}	 |                    |d                   }|r.|                    |j        pt          j                               N|                    t          j                               u# t          $ ra}t          
                    t          d          ||           |                    |j        pt          j                               Y d}~d}~ww xY wdS )z0Filter ``only`` nodes which do not match *tags*.exprz8exception while evaluating only directive expression: %sr   N)rV   r   onlyeval_conditionreplace_selfrm   r   commentr,   rK   r   r   )r   r4  r'   reterrs        r$   process_only_nodesr=  a  s     // 3 3	3%%d6l33C  3!!$-"B5=??CCCC !!%-//2222  	@ 	@ 	@NN2XYY[^$(  * * *dm>u}????????	@3 3s   B
D AC;;D r#   c                      | j         | j        fi | j        }t          | t          j                  r| j        |_        | j        |_        |S )zmonkey-patch Element.copy to copy the rawsource and line
    for docutils-0.16 or older versions.

    refs: https://sourceforge.net/p/docutils/patches/165/
    )r:   rJ   
attributesr)   r   r   rN   rO   )r#   newnodes     r$   	_new_copyrA  u  sL     dnT^??t??G$&& !yNr&   )r=   r!   )rH   N)hr5   rW   r   typingr   r   r   r   r   r   r	   r
   r   r   r   docutilsr   docutils.nodesr   r   docutils.parsers.rstr   docutils.parsers.rst.statesr   docutils.statemachiner   sphinxr   sphinx.localer   sphinx.utilr   sphinx.buildersr   sphinx.domainr   sphinx.environmentr   sphinx.util.tagsr   	getLoggerr2   rK   compileDOTALLr   caption_ref_rer   rB   r<   intrE   r`   	Invisibler[   doctest_blockversionmodifiedrl   r6   re   ro   
math_blockr   rw   rQ   IMAGE_TYPE_NODESrd   rx   r}   r\   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  pending_xrefr  r  r   r&  r*  r.  FixedTextElementliteralmathproblematicnot_smartquotabler1  r3  r=  rA  copyr7   r&   r$   <module>r`     sY	   9 9 				    ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !       ( ( ( ( ( ( ( ( * * * * * * / / / / / / , , , , , ,                   &''''''((((((333333%%%%%%		8	$	$ BJ?KK "1  1  1  1  1  1  1  1 hDt D D D D D d C     (;' ;d ; ; ; ;~ 
O			$ 4    *$ *4 * * * *\ 
			I	  
K  M
 g  (5#3F*G        F' hsm     HSM     '  x7H     $     XeGTR^M_D_>`5a    =C =* =D =S = = = =&w 3    s uT3^'<      

$s $c $!%S#sHSM(I"JK$ $ $ $N C 3 #n9ANRSVi"^   DS S    6 
,--"*-.."
C"
C" C" C	"
 C" C" C" C" C" C" C" C" C" C" C"  C!"" C#" "$ C%"& C'"( C)"* C+", C-". C/"0 C1"2 C3"4 C5"6 C7"8 C9": C;"< C="> C?"@ CA"B CC" " H    +/ # u~ $'36   4h&;  %-g%6    ?C ) # # QT dDJ./8;GL   $Fy F F F F F F
J' J3 Jd Jt J J J J"' " "D " " " " 
	M	J	K	I	" 4 D    3 3V 3 3 3 3 3(
G 
 
 
 
 
    r&   