
    -Phb                       d Z ddlmZ ddlZddlZddlZddl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 dd	lmZ dd
lmZ er6ddlmZmZmZ ddl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)  ej*        e+          Z, ej-        dej.                  Z/e/Z0 e
de          Z1 G d de	e1                   Z2ddZ3ddd Z4dd#Z5ej6        ej7        ej8        ej9        fZ:dd%Z;ej7        ej8        ej<        ej=        fZ>ej?        fZ@dd(ZAdd)ZBdd*ZCddd.ZDdd0ZEdd2ZF	 ddd8ZGdd9ZHdd<ZIg d=ZJddAZK	 dddOZLddQZM ej-        dR          ZN ej-        dS          ZOi dTdUdVdWdXdYdZd[d\d]d^d_d`dadbdadcdddedWdfdgdhdidjd]dkdldmdndod_dpd_i dqdrdsdtdudvdwdtdxd]dydldzd_d{d|d}ddd~dddtdddd|ddddddrZPddddddZQ	 	 dddZRddZS	 dddZTddZUddZVddZWejX        ejY        ejZ        ej?        ej=        ej[        ej\        fZ]ddZ^ddZ_ddZ`ddZaeaej        _b        ddZcecej        _d        dS )z3Docutils node-related utility functions for Sphinx.    )annotationsN)TYPE_CHECKINGAnyGenericTypeVarcast)nodes)Node)addnodes)__)logging)_fresh_title_style_context)CallableIterableIterator)Element)	Directive)InlinerRSTState)
StringList)Builder)BuildEnvironment)Tagsz^(.+?)\s*(?<!\x00)<([^<]*?)>$N)boundc                  2    e Zd ZdZddZddZddZd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')
        matcher.findall(doctree)
        # => [<reference ...>, <reference ...>, ...]

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

        matcher = NodeMatcher(nodes.reference, refdomain=Any)
        matcher.findall(doctree)
        # => [<reference ...>, <reference ...>, ...]
    node_classestype[N]attrsr   returnNonec                "    || _         || _        d S N)classesr    )selfr   r    s      Q/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/sphinx/util/nodes.py__init__zNodeMatcher.__init__>   s    #


    noder
   boolc                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.matchB   s    	| JtT\$B$B uz 
%!$66 ! 5"&*"2"2"4"4 % %JC$$uu# #%//$uu 0 4 	 	 	55	s(   B !B #B ($B B 
BBc                ,    |                      |          S r$   )r3   )r&   r*   s     r'   __call__zNodeMatcher.__call__X   s    zz$r)   Iterator[N]c              #  ^   K   |                     |           D ]}t          d|          V  dS )zAn alternative to `Node.findall` with improved type safety.

        While the `NodeMatcher` object can be used as an argument to `Node.findall`, doing so
        confounds type checkers' ability to determine the return type of the iterator.
        r   N)findallr   )r&   r*   founds      r'   r8   zNodeMatcher.findall[   sF       \\$'' 	# 	#EsE""""""	# 	#r)   N)r   r   r    r   r!   r"   r*   r
   r!   r+   )r*   r
   r!   r6   )__name__
__module____qualname____doc__r(   r3   r5   r8    r)   r'   r   r   )   sn         (      ,       # # # # # #r)   r   r*   r
   r!   strc                .    | j          d| j        j         S )zReturn full module dotted path like: 'docutils.nodes.paragraph'

    :param nodes.Node node: target node
    :return: full module dotted path
    .)r<   	__class__r;   r*   s    r'   get_full_module_namerE   e   s     o99 7999r)   P   lengthintc                    	 |                                                                  }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="versionadded">Added 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toxmlr0   r@   len)r*   rG   texts      r'   repr_domxmlrN   n   s{    zz||!!##   4yy %#d))f$$GVG}u$Ks   &) AAr   r"   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                  rL| j	        Et/          j        t2                    5  t5          |           | _	        d d d            n# 1 swxY w Y   | j        s|                                 | _        | j	        r	| j        rd S t          | t          j        t          j
        z  t          j        z  t          j        z            rlt                              dt          |           t          |                      	 t5          |           | _	        n# t2          $ r
 d| _	        Y nw xY w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debugrE   rN   parentsourcelineastextimagetitletermreversedlistr8   resubescapetopicliteral_block
contextlibsuppress
ValueErrorget_node_sourcerubric
field_name)r*   definition_list_itemrR   s      r'   apply_source_workaroundrk      s     $()) )$. )E &&	
 	
 	

  ${*1(-1		D%*	+	+ )DK )k($$$ F)<7 &&	
 	
 	

 "&!3T[5ETY$$$ F)<1 &&	
 	
 	

 "&!3T[5ETY$
## 
4 &&	
 	
 	
 #4(;(;E<L(M(M#N#NOO 	 	JVry):):)<)<===r4> DNN $$$ F)<7 &&	
 	
 	

 "&!3T[5ETY $+,, 01D ,, 	0 	0)$//DK	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 > '{ t~   Lj k	 	   	: &&	
 	
 	

	)$//DKK 	 	 	DKKK		/ s$   M''M+.M+P/ /QQr+   c                   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          | t          j                  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   rm   r	   rZ   r/   InlineTextElementrW   rT   rU   rE   rN   IGNORED_NODESri   childrenmetarD   s    r'   is_translatableru      s   $-.. t $$$ $((>*B*B dhhuoo t$%% .*D*Du$)** !{ 	LL;$T**D!!  
 5dM** 	~T/I/ILL2$T**D!!	   5xx-- 	LLE$T**D!!  
 5 dE,-- 	4=3Cx3O3OLL8$T**D!!  
 5tdEJ'''r)   doctreeIterable[tuple[Element, str]]c              #    K   |                      t                    D ];}t          |t          j                  r|                                D ]}||fV  	;t          |t                    r|j        }|s|                                }nt          |t          j
                  r[|                    d          r||d         fV  |                    d          r"|                    d|d                   }d| }nSd}nPt          |t          j                  r	|d         }n-|j                            dd	                                          }|r||fV  =d
S )z3Extract translatable messages from a document tree.rn   rm   original_uriuriz.. image:: rQ   content
 N)r8   ru   r-   r   rm   extract_original_messagesLITERAL_TYPE_NODESrS   rY   r	   rZ   r/   rt   replacestrip)rv   r*   msg	image_uris       r'   extract_messagesr   $  ss     00  dH122 	5577    Cid.// 	<.C $kkmmek** 	<xx (DK''''xx''  HH^T%[AA	/I//ej)) 	<y/CC.((s3399;;C  	)OOO1 r)   c                h    t          |           D ]}|j        r	|j        c S d}t          |          )Nznode source not found)traverse_parentrW   rf   r*   pnoder   s      r'   rg   rg   A  sG     &&    < 	 <	 
!C
S//r)   c                h    t          |           D ]}|j        r	|j        c S d}t          |          )Nznode line not found)r   rX   rf   r   s      r'   get_node_liner   I  sG     &&  : 	:	
C
S//r)   clsr   Iterable[Element]c              #  P   K   | r!|t          | |          r| V  | j        } | d S d S r$   )r-   rV   )r*   r   s     r'   r   r   Q  sO      
 ;*T3//;JJJ{      r)   Node | Nonec                f    | j                             |           }|dk    r| j         |dz
           S d S )Nr   rP   )rV   index)r*   poss     r'   get_prev_noder   X  s6    
+

D
!
!C
Qww{37##tr)   EIterable[tuple[Element, list[tuple[str, str, str, str, str | None]]]]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   r8   )rv   matcherr*   r   s       r'   traverse_translatable_indexr   `  st       (.777G((  D  =)GG9oGGm r)   stater   r{   r   content_offsetc                    t          |           5  |                     |||d          }ddd           n# 1 swxY w Y   |S )ax  Version 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.

    This function is retained for compatibility and will be deprecated in
    Sphinx 8. Prefer ``nested_parse_to_nodes()``.
    T)match_titlesN)r   nested_parse)r   r{   r*   r   rets        r'   nested_parse_with_titlesr   m  s     
$E	*	* S S  .$T RRS S S S S S S S S S S S S S SJs   6::c                2   |                                  } |                     t          j                  D ]}d|d<   t	          |                     t          j                            D ]}|j                            |           |                                 S )z&Like node.astext(), but ignore images.rQ   rn   )	deepcopyr8   r	   rZ   r^   rawrV   removerY   )r*   imgr   s      r'   clean_astextr   ~  s    ==??D||EK((  E

DLL++,,  
#;;==r)   rM   tuple[bool, str, str]c                    t                               |           }|r+d|                    d          |                    d          fS d| | fS )z3Split role content into title and target, if given.TrP      F)explicit_title_rer3   group)rM   r3   s     r'   split_explicit_titler     sK    ##D))E 4U[[^^U[[^^33$r)   )singlepairdoubletripleseeseealsoentrytargetid+list[tuple[str, str, str, str, str | None]]c                   ddl m} g }|                                 } | }d}|                     d          rd}| dd                                          } |D ]}|                     | d          r| t          |          dz   d                                          }||          d| }t                              t          d	          || |d
           |	                    d|||d f            nt          D ]j}|                     | d          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   )pairindextypesrQ   !mainrP   :z; zK%r is deprecated for index entries (from entry %r). Use 'pair: %s' instead.r   )typer   r   ,r   )sphinx.domains.pythonr   r   
startswithlstriprL   rT   warningr   append
indextypessplit)r   r   r   indexentriesoentryr   
index_typer2   s           r'   process_index_entryr     se    544444@BLKKMMEFD #abb	  ""$ #M #M
z,,,-- 	#j//A-//06688E%j1<<U<<ENN.    	 	 	 $ EFFFE	" % 	M 	MJ: 0 0 011 c*oo1334::<<))!'J##Z$$MNNN  c** M M##C(( /!D!!""I,,..E ##Xuhd$KLLLLr)   rQ   builderr   
docnamesetset[str]docnametreenodes.document	colorfuncCallable[[str], str]	traversed	list[str]indentc                \   |                                 }t          |                    t          j                            D ]i}g }t          t          |d                   }	|dz  }|	D ]%}
|
|vr	 |                    |
           t          	                    | ||
          z              t          | ||
| j                            |
          |||          }|                    |
           t          j        |
          }|j        |_        |                    t           j                  D ]}d|vr|
|d<   |                    |           # t$          $ r0 t                              t)          d          |
|dd           Y !w xY w'|j                            ||           k|S )	zwInline all toctrees in the *tree*.

    Record all docnames in *docnameset*, and output docnames with *colorfunc*.
    includefilesr}   )r   r   z+toctree contains ref to nonexisting file %rtocnot_readable)locationr   subtype)r   r^   r8   r   toctreemapr@   r   rT   infoinline_all_toctreesenvget_doctreeaddstart_of_filers   r	   sectionr0   r   r   rV   r   )r   r   r   r   r   r   r   toctreenodenewnodesr   includefilesubtreesofsectionnodes                 r'   r   r     s    ==??DDLL)9::;; ": ":3N ;<<#' 	) 	)K)++)$$[111KK;)?)? ?@@@1"#//<<!! G NN;/// #0EEEC#*#3CL'*{{5='A'A A A$K775@K	2OOC(((( !   NNHII#!(" . #      ,: 	"";9999Ks   1A=E6F
	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-r}   rQ   )	translate_non_id_translate_digraphs_non_id_translateunicodedata	normalizeencodedecode_non_id_charsr`   joinr   _non_id_at_endsr@   )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  r   r   documentprefixr\   
str | Nonec                    d}|r|dz   }n|j         j        pddz   }|r|rt          ||z            }||k    rd}n|rt          |          }|sd}|	||j        v r#||                     |          z  }|||j        v #|S )z>Generate an appropriate node_id for given *prefix* and *term*.Nz-%sr   z%s)settings	id_prefixr   idsnew_serialno)r   r  r  r\   node_ididformats         r'   make_idr   D  s     G @E>%/744?  $ 8d?++fG	 4.. 	G
/W44S--f555 /W44 Nr)   addnodes.pending_xref	conditionElement | Nonec                ~    | 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'  b  sN       w ?@@	K((I55NNN4r)   fromdocname	todocnamechildNode | list[Node]r[   nodes.referencec                    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.rQ   T)internalrefid#refurireftitle)r	   	referenceget_relative_uri)r   r(  r)  r   r*  r[   r*   s          r'   make_refnoder5  o  s     ?2rD111DiH W 	N((i@@3FQ NN %55k9MMDN ! ZEMDKr)   	directiver   c                ^    | j                             | j                  \  |_        |_        d S r$   )state_machineget_source_and_linelinenorW   rX   )r6  r*   s     r'   set_source_infor;    s-    &4HH DKr)   inlinerr   r:  c                N    | j         j        } ||          \  |_        |_        d S r$   )reporterr9  rW   rX   )r<  r:  r*   gsals       r'   set_role_source_infor@    s'    /D!T&\\DKr)   srcdstc                    t          j        t                    5  t          |           |_        t          |           |_        d d d            d S # 1 swxY w Y   d S r$   )rd   re   rf   rg   rW   r   rX   )rA  rB  s     r'   copy_source_inforD    s    		Z	(	( & &$S))
 %%& & & & & & & & & & & & & & & & & &s   )AAAc                    t          | j                  D ]5}t          |t                    r dS |                    dd          du r dS 6t          | dd          duS )z0Check whether the node is smart-quotable or not.Fsupport_smartquotesN)r   rV   r-   NON_SMARTQUOTABLE_PARENT_NODESr/   getattr)r*   r   s     r'   is_smartquotablerI    su     --  e;<< 	5599*D11U::55 ; 4.55UBBr)   tagsr   c                   |                      t          j                  D ]f}t          ||          r.|                    |j        pt          j                               @|                    t          j                               gdS )z0Filter ``only`` nodes which do not match *tags*.N)r8   r   only_only_node_keep_childrenreplace_selfrs   r	   comment)r  rJ  r*   s      r'   process_only_nodesrP    s      // / /#D$// 	/dm>u}???? emoo..../ /r)   addnodes.onlyc                    	 |                     | d                   S # t          $ r5}t                              t	          d          ||            Y d}~dS d}~ww xY w)z%Keep children if tags match or error.exprz8exception while evaluating only directive expression: %s)r   NT)eval_conditionr0   rT   r   r   )r*   rJ  errs      r'   rM  rM    sz    ""4<000   IJJ 	 	
 	
 	

 ttttts    
A*AAelc                   t                               | j                  }g |_        | j        |_        | j        |_        d | j                                        D             |_        | j        |_        | j	        |_	        |S )zMonkey-patch ```nodes.Element.copy``` to not copy the ``_document``
    attribute.

    See: https://github.com/sphinx-doc/sphinx/issues/11116#issuecomment-1376767086
    c                6    i | ]\  }}||d vr|n	|dd         S )>   r  namesr%   backrefsdupnamesNr?   ).0r  vs      r'   
<dictcomp>z*_copy_except__document.<locals>.<dictcomp>  sJ       Aq 	
MMMAASTUVUVUVSW  r)   )
object__new__rC   rs   rS   tagname
attributesr.   rX   rW   )rV  newnodes     r'   _copy_except__documentrd    sz     nnR\**GGGjGO M''))  G 7GLYGNNr)   c                   |                                  }d | j        D             |_        |j        D ]L}||_        | j        r<| j        |_        |j        | j        j        |_        |j        | j        j        |_        M|S )z4Monkey-patch ```nodes.Element.deepcopy``` for speed.c                6    g | ]}|                                 S r?   )r   )r\  r*  s     r'   
<listcomp>z_deepcopy.<locals>.<listcomp>  s"    BBBU((BBBr)   )copyrs   rV   r  rW   current_sourcerX   current_line)rV  rc  r*  s      r'   	_deepcopyrk    s    ggiiGBBbkBBBG! 6 6; 	6[EN|#!{9z![5
Nr)   )r*   r
   r!   r@   )rF   )r*   r
   rG   rH   r!   r@   )r*   r   r!   r"   r:   )rv   r   r!   rw   )r*   r   r!   r@   )r*   r   r!   rH   r$   )r*   r   r   r   r!   r   )r*   r
   r!   r   )rv   r   r!   r   )r   )
r   r   r{   r   r*   r
   r   rH   r!   r@   )rM   r@   r!   r   )r   r@   r   r@   r!   r   )rQ   )r   r   r   r   r   r@   r   r   r   r   r   r   r   r@   r!   r   )r   r@   r!   r@   )rQ   N)
r   r   r  r   r  r@   r\   r  r!   r@   )r*   r!  r"  r@   r!   r#  )r   r   r(  r@   r)  r@   r   r  r*  r+  r[   r  r!   r,  )r6  r   r*   r
   r!   r"   )r<  r   r:  rH   r*   r
   r!   r"   )rA  r   rB  r   r!   r"   )r  r
   rJ  r   r!   r"   )r*   rQ  rJ  r   r!   r+   )rV  r   r!   r   )er>   
__future__r   rd   r_   r   typingr   r   r   r   r   docutilsr	   docutils.nodesr
   sphinxr   sphinx.localer   sphinx.utilr   sphinx.util.parsingr   collections.abcr   r   r   r   docutils.parsers.rstr   docutils.parsers.rst.statesr   r   docutils.statemachiner   sphinx.buildersr   sphinx.environmentr   sphinx.util.tagsr   	getLoggerr;   rT   compileDOTALLr   caption_ref_rer   r   rE   rN   rk   	Invisiblerc   doctest_blockversionmodifiedrr   ru   
math_blockr   r   rZ   IMAGE_TYPE_NODESr   rg   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r'  r5  r;  r@  rD  FixedTextElementliteralmathproblematicnot_smartquotablerG  rI  rP  rM  rd  rh  rk  r   r?   r)   r'   <module>r     s   9 9 " " " " " "     				     = = = = = = = = = = = = = =                               : : : : : : 
&<<<<<<<<<<&&&&&&......========000000''''''333333%%%%%%		8	$	$ BJ?KK " GCt9# 9# 9# 9# 9#'!* 9# 9# 9#x: : : :    &Z Z Z Z| 
O			/( /( /( /(f 
			I	  
K 
   :             
 
 
 
 MN    "       FEE
1 1 1 1v 1 1 1 1 1h   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    	    <
 
 
 
&     2   * * * *
& & & & 
	M	J	K	I	" C C C C
/ 
/ 
/ 
/
 
 
 
   * ,     #   r)   