
    -PhhL                       d 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mZ dd	lmZ dd
lmZmZ er&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   ej!        e"          Z#dRdZ$dSdZ%	 	 	 	 dTdUd)Z&dddddd*dVd-Z'	 dWdXd7Z(dYd;Z)dZd=Z*d[d@Z+dZdAZ,d\dDZ-d]dHZ. edIe	J          Z/d^dKZ0d_dNZ1 G dO dP          Z2dQS )`z'Toctree adapter for sphinx.environment.    )annotations)TYPE_CHECKINGTypeVar)nodes)Element)addnodes)__)loggingurl_re)Matcher)_only_node_keep_childrenclean_astext)IterableSet)Any)Node)Builder)BuildEnvironment)Tagsenvr   docnamestrtoctreenodeaddnodes.toctreereturnNonec                   |d         r| j                             |           |                    d          r| j                            |           |d         }|D ]<}| j                            |t                                                    |           =| j                            |g                               |           dS )zeNote a TOC tree directive in a document and gather information about
    file relations from it.
    globnumberedincludefilesN)	glob_toctreesaddgetnumbered_toctreesfiles_to_rebuild
setdefaultsettoctree_includesextend)r   r   r   include_filesinclude_files        c/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/sphinx/environment/adapters/toctree.pynote_toctreer-      s     6 'g&&&z"" +!!'***/M% J J 	''cee<<@@IIII##GR0077FFFFF    tagsr   r   c                ,   | j         |                             dd          }	 t          | j        |         d|d|          }n## t          $ r t          j                    cY S w xY w|                    t
          j                  D ]}|d         pd|d<   |S )zGet the (local) table of contents for a document.

    Note that this is only the sections within the document.
    For a ToC tree that shows the document's place in the
    ToC structure, use `get_toctree_for`.
    tocdepthr      F
anchorname#refuri)	metadatar#   _toctree_copytocsKeyErrorr   	paragraphfindall	reference)r   r   r/   r1   tocnodes         r,   document_tocr?   0   s     |G$((Q77H!CHW-q(E4HH ! ! !      !
 EO,, 3 3l+2sXJs   A A"!A"FTbuilderr   collapseboolincludehiddenmaxdepthinttitles_onlyElement | Nonec                      fd j                             t          j                  D             }d |D             }|sdS |d         }	|dd         D ]}
|	                    |
j                   |	S )zxGet the global ToC tree at a given document.

    This gives the global ToC, with all ancestors and their siblings.
    c              3  n   K   | ]/}t          |d t                    j        
  
        V  0dS )TprunerD   rF   rA   rC   r/   N)_resolve_toctreerE   r/   )	.0toctree_noder@   rA   r   r   rC   rD   rF   s	     r,   	<genexpr>z)global_toctree_for_doc.<locals>.<genexpr>Q   sn          	]]#'	
 	
 	
     r.   c                    g | ]}||S N )rM   toctrees     r,   
<listcomp>z*global_toctree_for_doc.<locals>.<listcomp>`   s    GGGG73F3F3F3Fr.   Nr      )master_doctreer;   r   rS   r)   children)r   r   r@   rA   rC   rD   rF   resolvedtoctreesresultrS   s   ```````    r,   global_toctree_for_docr[   D   s               .66x7GHH  H HGxGGGH ta[FABB< ( (g&''''Mr.   )rK   rD   rF   rA   rC   rS   rK   c                  |                     dd          r|sdS t          | j        |          }
t          | j        j                  }t          | j        j                  }|p|                     dd          }|s|                     dd          rd}|s|                     dd          rd}t          | |||||	|
|||g           }|sdS t          j	        d	d	          }|j
                             d
          x}r~t          j        |d	gt          j        |          gR  }|j        |_        |j        |_        |d         |_        t#          |d          r|j        |_        |`|                    |           |                    |           d|d<   t+          |d|           t-          |d|r|nd||j                  }t1          |d         t          j                  rt5          |d                   dk    rdS |                    t          j                  D ]F}t;          j        |d                   *|                    ||d                   }||d         z   |d<   G|S )a  Resolve a *toctree* node into individual bullet lists with titles
    as items, returning None (if no containing titles are found) or
    a new node.

    If *prune* is True, the tree is pruned to *maxdepth*, or if that is 0,
    to the value of the *maxdepth* option on the *toctree* node.
    If *titles_only* is True, only toplevel document titles will be in the
    resulting tree.
    If *collapse* is True, all branches not containing docname will
    be collapsed.
    hiddenFNrD   
titlesonlyTrC    caption
rawcaptionuidrS   rU   r   r5   r3   ) r#   _get_toctree_ancestorsr(   r   configinclude_patternsexclude_patterns_entries_from_toctreer   compact_paragraph
attributesr   titleTextlinesource	rawsourcehasattrrc   appendr)   _toctree_add_classesr7   r/   
isinstancer   lenr;   r<   r   matchget_relative_uri)r   r   r@   rS   rK   rD   rF   rA   rC   r/   toctree_ancestorsincludedexcluded
tocentriesnewnodera   caption_noderefnoderel_uris                      r,   rL   rL   j   s   0 {{8U## M t* /s/CWMMsz233Hsz233H67;;z266H 7;;|U;;  W[[%@@ &
 J  t(R00G$((333w 	%{7BG%*W2E2E1FGGG#L%n!(!67E"" 	&{L|$$$NN:GI !W---,HH1h G
 	72;..36wr{3C3Cq3H3Ht ??5?33 @ @<)**2..w8IJJG '',*? ?GHNr.   rw   Set[str]rx   r   ry   parents	list[str]subtreelist[Element]c                d   g }|	d         D ]\  }}	 t          ||| |||||||	|
          \  }}n# t          $ r Y 0w xY w|j        }|ri|D ]f}t          |          dk    rQt	          |                    t          j                            x}r||d         dd<   Q|                    d           gt	          |                    t          j                            D ]}|	                    dd          r|st          t          | ||||||||||g|
d          |j                            |          dz             D ] \  }}|j                            ||           !|j                            |           |                    |           |st#          j                    }||z  }|gS |S )	z&Return TOC entries for a toctree node.entriesrU   Nr]   FT)r   )start)_toctree_entryLookupErrorrW   rt   listr;   r   rS   popr#   	enumeraterh   parentindexinsertremover)   r   bullet_list)r   rK   rF   rA   rC   r/   rw   rx   ry   r   r   r   r   rk   refr=   refdocrW   	top_levelsubtreessub_toc_nodeientryrets                           r,   rh   rh      s:     G!), <! <!
s	(! KC  	 	 	H	 -0L  		) & ) )	y>>A%%#'	(9(9(:J(K(K#L#LLx )*2	!QQQ!a((( X-=!>!>?? 	5 	5L%00  %%!% &g&    #)//==A   5 55" #**1e4444&&|4444x     !!wuNs   /
<<rk   r   tuple[Element, str]c           
        ddl m} 	 d}t          j        |          rt	          | |          }n|dk    rt          | |	d         |j                  }n||j        v rt          | |          }n||
v rQt          
                    t          d          |d                    |
          |dd	
           d}t          |          t          | ||j        |                             dd          |j        |         ||||          \  }}|j        s,t          
                    t          d          ||	dd
           n# t&          $ r t)          |                    |d                    } ||          rt          d          }d}n. ||          st          d          }d}nt          d          }d}t          
                    |||	d|
            w xY w||fS )Nr   StandardDomainr`   selfr   z8circular toctree references detected, ignoring: %s <- %sz <- r=   circular)locationtypesubtypezcircular referencer1   z^toctree contains reference to document %r that doesn't have a title: no link will be generatedno_titleFz2toctree contains reference to excluded document %rry   z6toctree contains reference to non-included document %rnot_includedz6toctree contains reference to non-existing document %rnot_readable)sphinx.domains.stdr   r   ru   _toctree_url_entry_toctree_self_entrytitles_virtual_doc_names_toctree_generated_entryloggerwarningr	   joinr   _toctree_standard_entryr6   r#   r8   rW   r9   r   doc2path)rk   r   r   rK   rA   r/   rw   rx   ry   r   r   r   r   r=   msgref_pathmessager   s                     r,   r   r   *  s:    211111:< 	$UC00CCF]]%e[-BCJOOCCN555*5#66CCg~~QRRKK(( &     +!#&&&1S!%%j!44!	 	KC | 	NNF  $"  	 	 	    s||C//008H 	%MNNG GG(## 	%QRRG$GGQRRG$GwkwWWW ;s   D/D8 8BGnodes.bullet_listc                    | |} t          j        ddgt          j        |           gR d|dd}t          j        dd|          }t          j        d|          }t          j        d|          }|S )Nr`   Finternalr5   r3   )r   r<   rl   r   ri   	list_itemr   )rk   r   r<   paraitemr=   s         r,   r   r   w  s    }
B=BZ=N=N<O sr  I %b"i88D?2t$$D

B
%
%CJr.   r   dict[str, nodes.title]c                
   | st          ||                   } t          j        ddgt          j        |           gR d|dd}t	          j        dd|          }t          j        d|          }t          j        d|          }|S )Nr`   Tr   )r   r   r<   rl   r   ri   r   r   )rk   r   r   r<   r   r   r=   s          r,   r   r     s      *VC[))
B<AJu<M<M;N cb  I %b"i88D?2t$$D

B
%
%CJr.   c                    ddl m} |j        |         \  }}| s|} t          j        d| d|d          }t          j        dd|          }t          j        d|          }t          j        d|          }|S )Nr   r   r`   Tr   )	r   r   r   r   r<   r   ri   r   r   )	rk   r   r   r   sectionnamer<   r   r   r=   s	            r,   r   r     s    111111)<SAG[ EDUWXXXI%b"i88D?2t$$D

B
%
%CJr.   r=   tuple[nodes.bullet_list, str]c                |   |}||v r|r|dk    r|                                 }nt          |d|||          }| r|j        rzt          |j                  dk    rb|j        d         }	|	                    t
          j                  D ]5}
|
d         |k    r'|
d         st          j        |           g|
j        d d <   6||fS )Nr   r2   rU   r5   r3   )deepcopyr7   rW   rt   r;   r   r<   rl   )rk   r   rD   r=   rw   rK   rA   r/   r   childr}   s              r,   r   r     s     F
(a--llnnCHh== : :#cl"3"3q"8"8Q}}U_55 	: 	:Gx C''0E'',z%'8'8&9 #;r.   r>   r   depthc                @   | j         D ]}t          |t          j        t          j        z            r3|d                             d|dz
              t          |||           ]t          |t          j                  rt          ||dz   |           t          |t          j	                  rn|d         |k    rb|d         s(|}|r$|d                             d           |j
        }|$|j
        j
                            d          r dS |rd	|d<   |j
        }|dS )
z7Add 'toctree-l%d' and 'current' classes to the toctree.classesz	toctree-lrU   r5   r3   current	iscurrentNT)rW   rs   r   ri   r   r   rq   rr   r   r<   r   r#   )r>   r   r   subnode
branchnodes        r,   rr   rr     sW   = - -gx9EOKLL 	-I%%&=%!)&=&=>>> %9999!233 	- %!)W====11 	- x G++|, 7 +2J$ 7"9-44Y???%/%6
 % 7 >(,,[99 FF -+/GK(%nG  -/- -r.   ET)boundc                   |dk    p||k    s|dk    o| pd| v }|                                  }| j        D ]}t          |t          j        t
          j        z            r'|                    t          |||||                     Qt          |t
          j	                  r,|r)|                    t          ||dz   |||                     t          |t          j
                  r(|                    |                                            t          |t          j                  rBt          ||          r0|j        D ](}|                    t          |||||                     )5t          |t
          j        t
          j        z            rR|                                 }	d |j        D             |	_        |	j        D ]	}|	|_        
|                    |	           d|j        j        d}
t%          |
          |S )z6Utility: Cut and deep-copy a TOC at a specified depth.rU   r   r   c                6    g | ]}|                                 S rR   )r   )rM   r   s     r,   rT   z!_toctree_copy.<locals>.<listcomp>  s"    %U%U%U5enn&6&6%U%U%Ur.   zUnexpected node type !)copyrW   rs   r   ri   r   r   rq   r7   r   rS   onlyr   r<   rk   r   	__class____name__
ValueError)r>   r   rD   rA   r/   keep_bullet_list_sub_nodesr   r   r   sub_node_copyr   s              r,   r7   r7     s    "'! "	(		+h!mVh,2U+QUBU  99;;D= $" $"gx9EOKLL #	"KKguh$OOPPPP!233  	"
 * YM'519hRVWWXXX!122 	"KK''''// 	"'66 
$- 	 	EKK%!!$$      5;!>?? 		"#LLNNM%U%UGDT%U%U%UM"&/ - -,KK&&&&I'*;*DIIICS//!Kr.   r(   dict[str, list[str]]c                0   i }|                                  D ]#\  }}|t                              ||          z  }$g }|}||v r)||vr%|                    |           ||         }||v r||v%t                              |                                          S rQ   )itemsdictfromkeysrq   keys)r(   r   r   prW   	ancestorsds          r,   rd   rd     s      F'--// - -8$--!,,,IA
v++!9,,1I v++!9,, ==##((***r.   c                  J    e Zd Zd"dZd#d
Z	 	 	 	 	 d$d%dZd&dZd'dZd(d Zd!S ))TocTreer   r   r   r   c                    || _         d S rQ   )r   )r   r   s     r,   __init__zTocTree.__init__  s    r.   r   r   r   r   c                2    t          | j        ||           d S rQ   )r-   r   )r   r   r   s      r,   notezTocTree.note"  s    TXw44444r.   Tr   Fr@   r   rS   rK   rB   rD   rE   rF   rA   rC   rG   c	                H    t          | j        |||||||||j        
  
        S )NrJ   )rL   r   r/   )	r   r   r@   rS   rK   rD   rF   rA   rC   s	            r,   resolvezTocTree.resolve%  s=      H#'
 
 
 	
r.   r   c                :    g t          | j        j        |          S rQ   )rd   r   r(   )r   r   s     r,   get_toctree_ancestorszTocTree.get_toctree_ancestors=  s    L'(A7KKLLr.   r   c                B    t          | j        || j        j                  S rQ   )r?   r   _tags)r   r   r@   s      r,   get_toc_forzTocTree.get_toc_for@  s    DHgtx~>>>r.   kwargsr   c                .    t          | j        ||fd|i|S )NrA   )r[   r   )r   r   r@   rA   r   s        r,   get_toctree_forzTocTree.get_toctree_forC  s4     &Hgw
 
19
=C
 
 	
r.   N)r   r   r   r   )r   r   r   r   r   r   )Tr   FFF)r   r   r@   r   rS   r   rK   rB   rD   rE   rF   rB   rA   rB   rC   rB   r   rG   )r   r   r   r   )r   r   r@   r   r   r   )
r   r   r@   r   rA   rB   r   r   r   rG   )	r   
__module____qualname__r   r   r   r   r   r   rR   r.   r,   r   r     s           5 5 5 5 !#
 
 
 
 
0M M M M? ? ? ?	
 	
 	
 	
 	
 	
r.   r   N)r   r   r   r   r   r   r   r   )r   r   r   r   r/   r   r   r   )FTr   F)r   r   r   r   r@   r   rA   rB   rC   rB   rD   rE   rF   rB   r   rG   )r   r   r   r   r@   r   rS   r   rK   rB   rD   rE   rF   rB   rA   rB   rC   rB   r/   r   r   rG   )F)r   r   rK   rB   rF   rB   rA   rB   rC   rB   r/   r   rw   r   rx   r   ry   r   r   r   r   r   r   rB   r   r   )rk   r   r   r   r   r   rK   rB   rA   rB   r/   r   rw   r   rx   r   ry   r   r   r   r   r   r   r   )rk   r   r   r   r   r   )rk   r   r   r   r   r   r   r   )rk   r   r   r   rD   rE   r=   r   rw   r   rK   rB   rA   rB   r/   r   r   r   )r>   r   r   rE   r   r   r   r   )r>   r   r   rE   rD   rE   rA   rB   r/   r   r   r   )r(   r   r   r   r   r   )3__doc__
__future__r   typingr   r   docutilsr   docutils.nodesr   sphinxr   sphinx.localer	   sphinx.utilr
   r   sphinx.util.matchingr   sphinx.util.nodesr   r   collections.abcr   r   r   r   sphinx.buildersr   sphinx.environmentr   sphinx.util.tagsr   	getLoggerr   r   r-   r?   r[   rL   rh   r   r   r   r   r   rr   r   r7   rd   r   rR   r.   r,   <module>r      s   - - " " " " " " ) ) ) ) ) ) ) )       " " " " " "             ' ' ' ' ' ' ' ' ( ( ( ( ( ( D D D D D D D D &--------######''''''333333%%%%%% 
	8	$	$G G G G$   0 # # # # #X g g g g g gl S S S S SlJ J J JZ	 	 	 	   &      0- - - -< WT!!!. . . .b+ + + + .
 .
 .
 .
 .
 .
 .
 .
 .
 .
r.   