
    RiO                       d Z ddlmZ ddl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 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jF                  e$      Z%	 	 	 	 	 	 	 	 d)dZ&d*dZ'dddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d+dZ(dddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d,dZ)	 d-	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d.dZ*	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d/dZ+d0dZ,	 	 	 	 	 	 	 	 d1dZ-d0d Z.	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d2d!Z/d3d"Z0 d#        Z1ddd$	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d4d%Z2	 	 	 	 	 	 d5d&Z3 G d' d(      Z4y)6z'Toctree adapter for sphinx.environment.    )annotationsN)TYPE_CHECKING)nodesElement)addnodes)RemovedInSphinx11Warning)__)loggingurl_re)Matcher)_only_node_keep_childrenclean_astext)IterableSet)Any)Node)Builder)BuildEnvironment)Tagsc                p   |d   r| j                   j                  |       |j                  d      r| j                  j                  |       |d   }|D ]5  }| j                  j                  |t                     j                  |       7 | j                  j                  |g       j                  |       y)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)envdocnametoctreenodeinclude_filesinclude_files        [/home/agent/.friday_env/lib/python3.12/site-packages/sphinx/environment/adapters/toctree.pynote_toctreer*       s     6g&z"!!'*/M% J 	''ce<@@IJ ##GR077F    c                $   | j                   |   j                  dd      }	 t        | j                  |   d|d|      }|j                  t
        j                        D ]  }|d   xs d|d<    |S # t        $ r t        j                         cY S w xY w)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%   tagsr-   tocnodes         r)   document_tocr<   2   s     ||G$((Q7H!CHHW-q(E4H EOO, 3l+2sX3J  !   !s   A/ /BB.FT)r9   collapseincludehiddenmaxdepthtitles_onlyc               h    du r(t        j                  dt        d       j                   fd j                  j                  t        j                        D        }|D 	cg c]  }	|	|		 }
}	|
sy|
d   }|
dd D ]  }	|j                  |	j                          |S c c}	w )	zxGet the global ToC tree at a given document.

    This gives the global ToC, with all ancestors and their siblings.
    .z['tags' will become a required keyword argument for global_toctree_for_doc() in Sphinx 11.0.r.   )
stacklevelc              3  Z   K   | ]"  }t        |d t              	
       $ yw)Tpruner?   r@   r=   r>   r9   N)_resolve_toctreeint)
.0toctree_nodebuilderr=   r%   r$   r>   r?   r9   r@   s
     r)   	<genexpr>z)global_toctree_for_doc.<locals>.<genexpr>^   sG        	]#'	
 	
s   (+Nr      )
warningswarnr	   r9   master_doctreer7   r   toctreer#   children)r$   r%   rJ   r9   r=   r>   r?   r@   resolvedrP   toctreesresults   ````````    r)   global_toctree_for_docrU   F   s     s{;$		
 ||   ..66x7G7GHH (0GG73FGHGa[FAB< (g&&'(M Hs   2B/:B/)rE   r?   r@   r=   r>   c                  |j                  dd      r|syt        | j                  |      }
t        | j                  j
                        }t        | j                  j                        }|xs |j                  dd      }|s|j                  dd      rd}|s|j                  dd      rd}t        | |||||	|
|||g       }|syt        j                  d	d	      }|j                  j                  d
      x}rt        j                  |d	gt        j                  |      g }|j                  |_        |j                  |_        |d   |_        t#        |d      r|j$                  |_        |`|j'                  |       |j)                  |       d|d<   t+        |d|       t-        |d|r|nd||	      }t/        |d   t        j0                        rt3        |d         dk(  ry|j5                  t        j6                        D ];  }t9        j:                  |d         |j=                  ||d         }||d   z   |d<   = |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.
    hiddenFNr?   
titlesonlyTr>    caption
rawcaptionuidrP   rL   r   r1   r/   )r   _get_toctree_ancestorsr"   r   configinclude_patternsexclude_patterns_entries_from_toctreer   compact_paragraph
attributesr   titleTextlinesource	rawsourcehasattrr]   appendr#   _toctree_add_classesr3   
isinstancer   lenr7   r8   r   matchget_relative_uri)r$   r%   rJ   rP   rE   r?   r@   r=   r>   r9   toctree_ancestorsincludedexcluded
tocentriesnewnoder[   caption_noderefnoderel_uris                      r)   rF   rF   w   s(   0 {{8U#M* /s/C/CWMszz223Hszz223H67;;z26H7;;|U;W[[%@&
J ((R0G$$((33w3{{7BG%**W2E1FG#LL%nn!(!67E"&{{L|$NN:GI !W-GQEq(DQG 	72;.3wr{3Cq3H ??5??3 @<<)*2..w8IJG '',*? ?GH@ Nr+   c                ,   g }|	d   D ]Z  \  }}	 t        ||| |||||||	|
      \  }}|j                  }|rZ|D ]U  }t        |      dkD  st	        |j                  t        j                              x}r	||d   dd E|j                  d       W t	        |j                  t        j                              D ]  }|j                  dd      r|st        t        | ||||||||||g|
d      |j                  j                  |      dz         D ]!  \  }}|j                  j                  ||       # |j                  j                  |        |j!                  |       ] |st#        j$                         }||z  }|gS |S # t        $ r Y w xY w)	z&Return TOC entries for a toctree node.entriesrL   NrW   FT)subtree)start)_toctree_entryLookupErrorrQ   rn   listr7   r   rP   popr   	enumeraterb   parentindexinsertremover#   r   bullet_list)r$   rE   r@   r=   r>   r9   rq   rr   rs   r&   parentsr{   rz   re   refr:   refdocrQ   	top_levelsubtreessub_toc_nodeientryrets                           r)   rb   rb      s     G!), <!
s	(!KC( -0LL  & )	y>A%#'	(9(9(:J:J(K#LLxL*2	!Q!a() !X-=-=!>? 	5L%0%%!% &g&  #))//=A 55" ##**1e4#5$ &&|4+	5. 	x y<!| !wuNi  		s   F	FFc           
     2   ddl m} 	 d}t        j                  |      rt	        | |      }n|dk(  rt        | |	d   |j                        }n||j                  v rt        | |      }n||
v r@t        j                  t        d      |dj                  |
      |dd	
       d}t        |      t        | ||j                  |   j!                  dd      |j"                  |   ||||      \  }}|j$                  s#t        j                  t        d      ||	dd
       ||fS # t&        $ rp t)        |j+                  |d            } ||      rt        d      }d}n# ||      st        d      }d}nt        d      }d}t        j                  |||	d|
        w xY w)Nr   StandardDomainrZ   selfr   z8circular toctree references detected, ignoring: %s <- %sz <- r:   circular)locationtypesubtypezcircular referencer-   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 %rrs   z6toctree contains reference to non-included document %rnot_includedz6toctree contains reference to non-existing document %rnot_readable)sphinx.domains.stdr   r   ro   _toctree_url_entry_toctree_self_entrytitles_virtual_doc_names_toctree_generated_entryloggerwarningr
   joinr~   _toctree_standard_entryr2   r   r4   rQ   r5   strdoc2path)re   r   r$   rE   r=   r9   rq   rr   rs   r&   r   r   r   r:   msgref_pathmessager   s                     r)   r}   r}   5  s    2:<<$UC0CF]%e[-BCJJOCN555*5#6Cg~QRKK( &   +!#&&1S!%%j!4!	KC ||NNF $"  	2 ;  s||C/0HMNG G(#QRG$GQRG$GwkwWs   DD A9Fc                    | |} t        j                  ddgt        j                  |       gd|dd}t        j                  dd|      }t        j
                  d|      }t        j                  d|      }|S )NrZ   Finternalr1   r/   )r   r8   rf   r   rc   	list_itemr   )re   r   r8   paraitemr:   s         r)   r   r     s|    }
B=BZZ=N<OsrI %%b"i8D??2t$D


B
%CJr+   c                   | st        ||         } t        j                  ddgt        j                  |       gd|dd}t	        j
                  dd|      }t        j                  d|      }t        j                  d|      }|S )NrZ   Tr   )r   r   r8   rf   r   rc   r   r   )re   r   r   r8   r   r   r:   s          r)   r   r     s     VC[)
B<AJJu<M;NcbI %%b"i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   rZ   Tr   )	r   r   r   r   r8   r   rc   r   r   )	re   r   r   r%   sectionnamer8   r   r   r:   s	            r)   r   r     st    1)<<SAG[EDUWXI%%b"i8D??2t$D


B
%CJr+   c                z   |}||v r|r|dk  r|j                         }nt        |d|||      }| r|j                  r}t        |j                        dk(  re|j                  d   }	|	j	                  t
        j                        D ]4  }
|
d   |k(  s|
d   rt        j                  |       g|
j                  d d  6 ||fS )Nr   r.   rL   r1   r/   )deepcopyr3   rQ   rn   r7   r   r8   rf   )re   r   r?   r:   rq   rE   r=   r9   r   childrw   s              r)   r   r     s     F
(a-llnCHh=#cll"3q"8Q}}U__5 	:Gx C'0E',zz%'8&9  #	: ;r+   c                @   | j                   D ]  }t        |t        j                  t        j
                  f      r(|d   j                  d|dz
          t        |||       Vt        |t        j                        rt        ||dz   |       t        |t        j                        s|d   |k(  s|d   s'|}|r#|d   j                  d       |j                  }|r#|j                  j                  j                  d      r y|sd	|d<   |j                  }|r y)
z7Add 'toctree-l%d' and 'current' classes to the toctree.classesz	toctree-lrL   r1   r/   current	iscurrentNT)rQ   rm   r   rc   r   r   rk   rl   r   r8   r   r   )r;   depthr%   subnode
branchnodes        r)   rl   rl     s   == -g : :EOOLMI%%	%!)&=> %9!2!23 %!)W=1 x G+|, +2J$"9-44Y?%/%6%6
 % >>((,,[9+/GK(%nnG /-r+   c                 2    d d x}f	 	 	 	 	 	 	 	 	 	 	 ddcS )ETc                     t         S Nr    r+   r)   r   r     s    g+r+   c                    t        | t        j                        rJ t        |dz
  d      }t	        | ||||d      }t        |      dk(  sJ |d   S )z6Utility: Cut and deep-copy a TOC at a specified depth.rL   T)initial_callr   )rm   r   onlymax_toctree_copy_seqrn   )r;   r   r?   r=   r9   copieds         r)   r3   r3     sY     $...	1EtUHhSWXFv;!!9r+   )r;   r   r   rG   r?   rG   r=   boolr9   r   returnr   r   )	.defaultsr   s     r)   %<generic parameters of _toctree_copy>r     s4    +
$'37?Cr+   )r   
is_currentc                   t        | t        j                  t        j                  f      r:| j                         }| j                  D ]  }|t        |||||d| v       z  } |gS t        | t        j                        rg|dk  xs ||k  xs |dk  xr | xs |xs d| v }	|	s|sg S |dz  }| j                         }| j                  D ]  }|t        |||||d| v       z  } |gS t        | t        j                        r| j                         gS t        | t        j                        r9t        | |      sg S g }
| j                  D ]  }|
t        |||||d| v       z  }
 |
S t        | t        j                  t        j                  f      rX| j                         }| j                  D cg c]  }|j                          c}|_        |j                  D ]	  }||_         |gS d| j                   j"                  d}t%        |      c c}w )Nr   )r   rL   r   zUnexpected node type !)rm   r   rc   r   r   copyrQ   r   r   rP   r   r   r8   re   r   r   	__class____name__
ValueError)r;   r   r?   r=   r9   r   r   r   r   keep_bullet_list_sub_nodesr   sub_node_copyr   r   s                 r)   r   r     s$    $33U__EFyy{}} 	G%(D[TXEX D	 v$))*
 &+aZ &
h/(a- DBB{d/B 	# *,I
yy{}} 	G%(D[TXEX D	 v$(()		}$&'d3I "}} 	G'(D[TXEX F	 $%++67		@D!Nu%.."2!N"++ 	)E(EL	)!$.."9"9!<A
>C
S/ "Os   ,Hc                   i }| j                         D ]  \  }}|t        j                  ||      z  }  g }|}||v r#||vr|j                  |       ||   }||v r||vrt        j                  |      j	                         S r   )itemsdictfromkeysrk   keys)r"   r%   r   prQ   	ancestorsds          r)   r^   r^   2  s      F'--/ -8$--!,,-IA
v+!9,1I v+!9, ==#((**r+   c                  ~    e Zd ZddZd	dZ	 	 	 	 	 d
	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZddZddZ	 	 	 	 	 	 	 	 	 	 ddZy)TocTreec                    || _         y r   )r$   )r   r$   s     r)   __init__zTocTree.__init__C  s	    r+   c                2    t        | j                  ||       y r   )r*   r$   )r   r%   r&   s      r)   notezTocTree.noteF  s    TXXw4r+   c	                T    t        | j                  |||||||||j                  
      S )NrD   )rF   r$   r9   )	r   r%   rJ   rP   rE   r?   r@   r=   r>   s	            r)   resolvezTocTree.resolveI  s7      HH#'
 	
r+   c                F    g t        | j                  j                  |      S r   )r^   r$   r"   )r   r%   s     r)   get_toctree_ancestorszTocTree.get_toctree_ancestorsa  s    L'(A(A7KLLr+   c                X    t        | j                  || j                  j                        S r   )r<   r$   _tags)r   r%   rJ   s      r)   get_toc_forzTocTree.get_toc_ford  s    DHHgtxx~~>>r+   c                L    t        | j                  ||f|j                  |d|S )N)r9   r=   )rU   r$   r9   )r   r%   rJ   r=   kwargss        r)   get_toctree_forzTocTree.get_toctree_forg  s2     &HHgw
-4\\H
PV
 	
r+   N)r$   r   r   None)r%   r   r&   addnodes.toctreer   r   )Tr   FFF)r%   r   rJ   r   rP   r   rE   r   r?   rG   r@   r   r=   r   r>   r   r   Element | None)r%   r   r   	list[str])r%   r   rJ   r   r   r   )
r%   r   rJ   r   r=   r   r   r   r   r   )	r   
__module____qualname__r   r   r   r   r   r   r   r+   r)   r   r   B  s    5 !#

 
 "	

 
 
 
 
 
 

0M?	
	
 	
 		

 	
 
	
r+   r   )r$   r   r%   r   r&   r   r   r   )r$   r   r%   r   r9   r   r   r   )r$   r   r%   r   rJ   r   r9   r   r=   r   r>   r   r?   rG   r@   r   r   r   )r$   r   r%   r   rJ   r   rP   r   rE   r   r?   rG   r@   r   r=   r   r>   r   r9   r   r   r   )F)r$   r   rE   r   r@   r   r=   r   r>   r   r9   r   rq   Set[str]rr   r   rs   r   r&   r   r   r   r{   r   r   list[Element])re   r   r   r   r$   r   rE   r   r=   r   r9   r   rq   r   rr   r   rs   r   r&   r   r   r   r   ztuple[Element, str])re   r   r   r   r   nodes.bullet_list)re   r   r   r   r   zdict[str, nodes.title]r   r   )re   r   r   r   r?   rG   r:   r   rq   r   rE   r   r=   r   r9   r   r   ztuple[nodes.bullet_list, str])r;   r   r   rG   r%   r   r   r   )r;   r   r   rG   r?   rG   r=   r   r9   r   r   r   r   r   r   r   )r"   zdict[str, list[str]]r%   r   r   r   )5__doc__
__future__r   rM   typingr   docutilsr   docutils.nodesr   sphinxr   sphinx.deprecationr	   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<   rU   rF   rb   r}   r   r   r   r   rl   r3   r   r^   r   r   r+   r)   <module>r     s   - "     "  7  ' ( D-#'3% 
		8	$G	G$'G6FG	G$2 .	.. .
 . . . . . .n e	ee e 	e e e e e e e eh S	SS S 	S
 S S  S S S "S S S SlJJ	J 
J 	J
 J J  J J J "J J JZ		 # 	&	  
	
      #0-<$ ?
?? ? 	?
 ? ? ? ?D+*++ + .
 .
r+   