
    FeOI                    v   d Z ddlmZ ddl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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   ejB                  e"      Z#d$dZ$d%dZ%	 	 	 	 d&	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d'dZ&dddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d(dZ'	 d)	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d*dZ(	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d+dZ)d,dZ*	 	 	 	 	 	 	 	 d-dZ+d,dZ,	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d.dZ-d/dZ. ede
      Z/d0dZ0	 	 	 	 	 	 d1d Z1 G d! d"      Z2y#)2z'Toctree adapter for sphinx.environment.    )annotations)TYPE_CHECKINGAnyTypeVar)nodes)ElementNode)addnodes)__)loggingurl_re)Matcher)_only_node_keep_childrenclean_astext)IterableSet)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        E/usr/lib/python3/dist-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;   +   s     ||G$((Q7H!CHHW-q(E4H EOO, 3l+2sX3J  !   !s   A/ /BBFTc                "   g }| j                   j                  t        j                        D ]3  }t	        | |||dt        |      |||	      x}	s#|j                  |	       5 |sy|d   }
|dd D ]  }	|
j                  |	j                          |
S )zxGet the global ToC tree at a given document.

    This gives the global ToC, with all ancestors and their siblings.
    Tprunemaxdepthtitles_onlycollapseincludehiddenNr      )	master_doctreer6   r
   toctree_resolve_toctreeintappendr"   children)r#   r$   builderrA   rB   r?   r@   toctreestoctree_noderE   results              r(   global_toctree_for_docrN   @   s     !H**2283C3CD %&]#'

 

7 

 OOG$% a[FAB< (g&&'(Mr*   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        | |||||j                  |	|
||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||j                        }t1        |d   t        j2                        rt5        |d         dk(  ry|j7                  t        j8                        D ];  }t;        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?   
titlesonlyTrB    caption
rawcaptionuidrE   rC   r   r0   r.   ) r   _get_toctree_ancestorsr!   r   configinclude_patternsexclude_patterns_entries_from_toctreer8   r
   compact_paragraph
attributesr   titleTextlinesource	rawsourcehasattrrV   rH   r"   _toctree_add_classesr2   
isinstancer   lenr6   r7   r   matchget_relative_uri)r#   r$   rJ   rE   r>   r?   r@   rA   rB   toctree_ancestorsincludedexcluded
tocentriesnewnoderT   caption_noderefnoderel_uris                     r(   rF   rF   d   s.   " {{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(GLLYG'"+u}}-#gbk2Ba2G ??5??3 @<<)*2..w8IJG '',*? ?GH@ Nr*   c                .   g }|	d   D ][  \  }}	 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|
z   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.entriesrC   NrP   FT)subtree)start)_toctree_entryLookupErrorrI   rf   listr6   r
   rE   popr   	enumerater[   parentindexinsertremover"   r   bullet_list)r#   r>   r@   rA   rB   r8   ri   rj   rk   r%   parentsrs   rr   r^   refr9   refdocrI   	top_levelsubtreessub_toc_nodeientryrets                           r(   r[   r[      s     G#I. 3!	(sC$8I(KKC -0LL  & )	y>A%#'	(9(9(:J:J(K#LLxL*2	!Q!a() !X-=-=!>? 	5L%0%%!% Hw&  #))//=A 55" ##**1e4#5$ &&|4+	5. 	x g3!j !wuNi  		s   F	FFc           
        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      ||	       ||fS # t&        $ r_ |j)                  |d      } ||      rt        d      }n ||      st        d      }nt        d      }t        j                  |||	        w xY w)Nr   StandardDomainrS   selfrz   z8circular toctree references detected, ignoring: %s <- %sz <- r9   circular)locationtypesubtypezcircular referencer,   z^toctree contains reference to document %r that doesn't have a title: no link will be generated)r   Fz2toctree contains reference to excluded document %rz6toctree contains reference to non-included document %rz5toctree contains reference to nonexisting document %r)sphinx.domains.stdr   r   rg   _toctree_url_entry_toctree_self_entrytitles_virtual_doc_names_toctree_generated_entryloggerwarningr   joinrv   _toctree_standard_entryr1   r   r3   rI   r4   doc2path)r^   r   r#   r>   rA   r8   ri   rj   rk   r%   r   r   r   r9   msgref_pathmessages                    r(   ru   ru     s    2,<<$UC0CF]%e[-BCJJOCN555*5#6Cg~r #A  B"FKK$8(+%  M +!#&&1S!%%j!4!	KC ||NN2 P Q  6 ;  <<U+HMNG(#QRGPQGwk:s   DD A(Fc                    | |} t        j                  ddgt        j                  |       gd|dd}t        j                  dd|      }t        j
                  d|      }t        j                  d|      }|S )NrS   Finternalr0   r.   )r   r7   r_   r
   r\   	list_itemr~   )r^   r   r7   paraitemr9   s         r(   r   r   N  s{    }B 6"'**U"3!46'*r6I %%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 )NrS   Tr   )r   r   r7   r_   r
   r\   r   r~   )r^   r   r   r7   r   r   r9   s          r(   r   r   Z  s    
 VC[)B 6 #(**U"3!46'*+-6I %%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   rS   Tr   )	r   r   r   r   r7   r
   r\   r   r~   )	r^   r   r   r$   sectionnamer7   r   r   r9   s	            r(   r   r   l  sv    1)<<SAG[ED'.2?I%%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-   rC   r0   r.   )deepcopyr2   rI   rf   r6   r   r7   r_   )r^   r   r?   r9   ri   r>   rA   r8   r   childro   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-lrC   r0   r.   current	iscurrentNT)rI   re   r
   r\   r   r   rH   rd   r~   r7   rz   r   )r:   depthr$   subnode
branchnodes        r(   rd   rd     s   == -g : :EOOLMI%%	%!)&=> %9!2!23 %!)W=1 x G+|, +2J$"9-44Y?%/%6%6
 % >>((,,[9+/GK(%nnG /-r*   ET)boundc                0   |dk  xs ||k  xs |dk  xr	 | xs d| v }| j                         }| j                  D ]  }t        |t        j                  t
        j                  f      r|j                  t        |||||             Mt        |t
        j                        r%|sj|j                  t        ||dz   |||             t        |t        j                        r |j                  |j                                t        |t        j                        r>t        ||      s|j                  D ]   }|j                  t        |||||             " t        |t
        j                  t
        j                  f      rh|j                         }	|j                  D cg c]  }|j                          c}|	_        |	j                  D ]	  }|	|_         |j                  |	       d|j"                  j$                  d}
t'        |
       |S c c}w )z6Utility: Cut and deep-copy a TOC at a specified depth.rC   r   r   zUnexpected node type !)copyrI   re   r
   r\   r   r   rH   r2   r~   rE   onlyr   r7   r^   r   rz   	__class____name__
ValueError)r:   r   r?   rA   r8   keep_bullet_list_sub_nodesr   r   r   sub_node_copyr   s              r(   r2   r2     s   "'1* #Q','8'IHM 'P/7<+N;$;N  99;D== "g : :EOOLMKKguh$OP!2!23
 *M'519hRVWX!1!12KK'/'6$-- EKKuh$!  %//5;;!?@#LLNMDKDTDT%U5enn&6%UM"&// -,-KK&)'*;*;*D*D)GqICS/!="> K &Vs   !Hc                   i }| j                         D ]  \  }}|t        j                  ||      z  }  g }|}||v r#||vr|j                  |       ||   }||v r||vrt        j                  |      j	                         S N)itemsdictfromkeysrH   keys)r!   r$   rz   prI   	ancestorsds          r(   rW   rW     s      F'--/ -8$--!,,-IA
v+!9,1I v+!9, ==#((**r*   c                  l    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__  s	    r*   c                2    t        | j                  ||       y r   )r)   r#   )r   r$   r%   s      r(   notezTocTree.note  s    TXXw4r*   c	                >    t        | j                  ||||||||	      S )Nr=   )rF   r#   )	r   r$   rJ   rE   r>   r?   r@   rA   rB   s	            r(   resolvezTocTree.resolve  s-      HHgw#'
 	
r*   c                F    g t        | j                  j                  |      S r   )rW   r#   r!   )r   r$   s     r(   get_toctree_ancestorszTocTree.get_toctree_ancestors  s    L'(A(A7KLLr*   c                    t        | j                  || j                  j                  j                  j                        S r   )r;   r#   apprJ   r8   )r   r$   rJ   s      r(   get_toc_forzTocTree.get_toc_for  s)    DHHgtxx||/C/C/H/HIIr*   c                6    t        | j                  ||fd|i|S )NrA   )rN   r#   )r   r$   rJ   rA   kwargss        r(   get_toctree_forzTocTree.get_toctree_for  s"     &dhh^8^W]^^r*   N)r#   r   returnNone)r$   strr%   addnodes.toctreer   r   )Tr   FFF)r$   r   rJ   r   rE   r   r>   boolr?   rG   r@   r   rA   r   rB   r   r   Element | None)r$   r   r   	list[str])r$   r   rJ   r   r   r	   )
r$   r   rJ   r   rA   r   r   r   r   r   )	r   
__module____qualname__r   r   r   r   r   r    r*   r(   r   r     s    5 LQ>C



.1

DH



7;

HV

MJ__%,_8<_HK_	_r*   r   N)r#   r   r$   r   r%   r   r   r   )r#   r   r$   r   r8   r   r   r	   )FTr   F)r#   r   r$   r   rJ   r   rA   r   rB   r   r?   rG   r@   r   r   r   )r#   r   r$   r   rJ   r   rE   r   r>   r   r?   rG   r@   r   rA   r   rB   r   r   r   )F)r#   r   r>   r   r@   r   rA   r   rB   r   r8   r   ri   Set[str]rj   r   rk   r   r%   r   r   r   rs   r   r   zlist[Element])r^   r   r   r   r#   r   r>   r   rA   r   r8   r   ri   r   rj   r   rk   r   r%   r   r   r   r   ztuple[Element, str])r^   r   r   r   r   nodes.bullet_list)r^   r   r   r   r   zdict[str, nodes.title]r   r   )r^   r   r   r   r?   rG   r9   r   ri   r   r>   r   rA   r   r8   r   r   ztuple[nodes.bullet_list, str])r:   r   r   rG   r$   r   r   r   )r:   r   r   rG   r?   rG   rA   r   r8   r   r   r   )r!   zdict[str, list[str]]r$   r   r   r   )3__doc__
__future__r   typingr   r   r   docutilsr   docutils.nodesr   r	   sphinxr
   sphinx.localer   sphinx.utilr   r   sphinx.util.matchingr   sphinx.util.nodesr   r   collections.abcr   r   sphinx.buildersr   sphinx.environmentr   sphinx.util.tagsr   	getLoggerr   r   r)   r;   rN   rF   r[   ru   r   r   r   r   rd   r   r2   rW   r   r   r*   r(   <module>r      s   - " . .  (   ' ( D-'3% 
		8	$G 2 !	!! ! 	!
 ! ! ! !L u%[	[$'[29[DT[["%[8<[ [ ,0[ 	[T J	JJ J 	J
 J J  J J J "J J J JZ<<	< 
< 	<
 < <  < < < "< < <~	"8$	  
	
      #0-< T!&R+*+58++_ _r*   