ó
öÀ„\c           @   sð   d  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 m Z d d
 l m Z d d l m Z n  e j e ƒ Z d e f d „  ƒ  YZ d S(   sð   
    sphinx.environment.adapters.toctree
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Toctree adapter for sphinx.environment.

    :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
    :license: BSD, see LICENSE for details.
iÿÿÿÿ(   t   nodes(   t	   iteritems(   t   addnodes(   t   __(   t   url_ret   logging(   t   Matcher(   t   clean_astextt   process_only_nodes(   t   Anyt   Dictt   List(   t   Builder(   t   BuildEnvironmentt   TocTreec           B   sY   e  Z d  „  Z d „  Z e d e e e d „ Z d „  Z e d „ Z d „  Z	 d „  Z
 RS(   c         C   s   | |  _  d  S(   N(   t   env(   t   selfR   (    (    sB   lib/python2.7/site-packages/sphinx/environment/adapters/toctree.pyt   __init__   s    c         C   s¥   | d r  |  j  j j | ƒ n  | j d ƒ rE |  j  j j | ƒ n  | d } x0 | D]( } |  j  j j | t ƒ  ƒ j | ƒ qV W|  j  j j | g  ƒ j	 | ƒ d S(   sm   Note a TOC tree directive in a document and gather information about
        file relations from it.
        t   globt   numberedt   includefilesN(
   R   t   glob_toctreest   addt   gett   numbered_toctreest   files_to_rebuildt
   setdefaultt   sett   toctree_includest   extend(   R   t   docnamet   toctreenodeR   t   includefile(    (    sB   lib/python2.7/site-packages/sphinx/environment/adapters/toctree.pyt   note#   s    

&i    c	            sU  | j  d t ƒ r ˆ r d Sˆ j ˆ ƒ ‰
 t ˆ j j j ƒ ‰ ‡ ‡ f d †  ‰ t t ‡  ‡ ‡ ‡ ‡ ‡ ‡ ‡	 ‡
 f	 d † ‰  | p• | j  d d ƒ } ˆ	 rº | j  d t ƒ rº t ‰	 n  ˆ rÜ | j  d t ƒ rÜ t ‰ n  ˆ  | g  d t ƒ}	 |	 sû d St	 j
 d	 d	 ƒ }
 | j j  d
 ƒ } | rœt j | d	 t j | ƒ g Œ } | j | _ | j | _ | d | _ t | d ƒ r| j | _ | ` n  |
 | 7}
 n  |
 j |	 ƒ t |
 d <ˆ |
 d ƒ ˆ j |
 d ˆ rØ| pÛd ˆ ƒ t |
 d ƒ d k rüd SxR |
 j t j ƒ D]> } t j | d ƒ sˆ j ˆ | d ƒ | d | d <qqW|
 S(   s   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.
        t   hiddenc            s  x|  j  D]} t | t j t j f ƒ rT | d j d | d ƒ ˆ  | | ƒ q
 t | t j ƒ rz ˆ  | | d ƒ q
 t | t j ƒ r
 | d ˆ k r| d sÖ | } x' | rÒ | d j d ƒ | j	 } q¯ Wn  | j	 j	 j
 d ƒ rï d Sx  | rt | d <| j	 } qò Wqq
 q
 Wd S(	   s7   Add 'toctree-l%d' and 'current' classes to the toctree.t   classess   toctree-l%di   t   refurit
   anchornamet   currentt	   iscurrentN(   t   childrent
   isinstanceR   t   compact_paragraphR    t	   list_itemt   appendt   bullet_listt	   referencet   parentR   t   True(   t   nodet   deptht   subnodet
   branchnode(   t   _toctree_add_classesR   (    sB   lib/python2.7/site-packages/sphinx/environment/adapters/toctree.pyR5   Y   s&    
		
c            s¨  g  |  d D] } | d | d f ^ q } g  } xE| D]=\ } } y¦d }	 t j | ƒ rà | d k rq | } n  t j d d d t d | d d t j | ƒ g Œ}
 t j d d |
 ƒ } t j	 d | ƒ } t j
 d | ƒ } ná| d k r„|  d	 } | st ˆ j j | ƒ } n  t j d d d t d | d d t j | ƒ g Œ}
 t j d d |
 ƒ } t j	 d | ƒ } t j
 d | ƒ } n=| | k r¾t j t d
 ƒ | d j | ƒ d | ƒw8 n  | }	 ˆ j j | j ƒ  } ˆ j j | j d d ƒ } | ˆ k sˆ r-| d k r-ˆ j | d | ˆ ƒ n  t | ˆ j ƒ | rÁ| j rÁt | j ƒ d k rÁ| j d } xP | j t j ƒ D]9 } | d | k r| d rt j | ƒ g | _ qqWn  | j sét j t d ƒ | d |  ƒn  Wn] t k
 rIˆ ˆ j j | d ƒ ƒ r$t d ƒ } n t d ƒ } t j | | d |  ƒq8 Xˆ r¬xY | D]N } t | ƒ d k rW| j t j ƒ } | r•| | d (q¥| j  d ƒ qWqWWn  x  | j t j ƒ D]Œ } | j d t ƒ oÛˆ s¿| j! j" | ƒ d } xA ˆ  | |	 g | d t ƒD]# } | j! j# | | ƒ | d 7} qW| j! j$ | ƒ q¿q¿W| re| j% | ƒ q8 | j& | j ƒ q8 W| r¤| r¤t j
 ƒ  } | | 7} | g S| S(   s&   Return TOC entries for a toctree node.t   entriesi    i   t    t   internalR$   R%   R   R/   s8   circular toctree references detected, ignoring: %s <- %ss    <- t   locationt   tocdepthi   s^   toctree contains reference to document %r that doesn't have a title: no link will be generateds2   toctree contains reference to excluded document %rs5   toctree contains reference to nonexisting document %rR"   t   subtreeN('   t   NoneR   t   matchR    R.   t   Falset   TextR   R*   R+   R-   R   R   t   titlesR0   t   loggert   warningR   t   joint   tocst   deepcopyt   metadataR   t   _toctree_pruneR   t   tagsR(   t   lent   traverset   KeyErrort   doc2patht   toctreet   popR/   t   indext   insertt   removeR,   R   (   R   t   parentst   separateR;   t   et   refsR6   t   titlet   reft   refdocR.   t   parat   itemt   toct   maxdeptht   childt   refnodet   messaget   toplevelt   subtreest
   subtocnodet   it   ret(	   t   _entries_from_toctreet   buildert   collapset   excludedt   includehiddent   pruneR   t   titles_onlyt   toctree_ancestors(    sB   lib/python2.7/site-packages/sphinx/environment/adapters/toctree.pyRe   x   s–    +		
$	
R\   iÿÿÿÿt
   titlesonlyRi   RS   R7   t   captiont
   rawcaptiont   uidRM   i   i    R$   R%   N(   R   R>   R<   t   get_toctree_ancestorsR   R   t   configt   exclude_patternsR0   R   R*   t
   attributesR    Rn   R?   t   linet   sourcet	   rawsourcet   hasattrRp   R   RG   RI   RJ   R.   R   R=   t   get_relative_uri(   R   R   Rf   RM   Rj   R\   Rk   Rg   Ri   t
   tocentriest   newnodeRn   t   caption_nodeR^   (    (   Re   R5   Rf   Rg   R   Rh   Ri   Rj   R   Rk   Rl   sB   lib/python2.7/site-packages/sphinx/environment/adapters/toctree.pyt   resolve3   sH    -b		!	
"#c         C   sŠ   i  } x; t  |  j j ƒ D]' \ } } x | D] } | | | <q, Wq Wg  } | } x3 | | k r… | | k r… | j | ƒ | | } qS W| S(   N(   R   R   R   R,   (   R   R   R/   t   pR(   R]   t	   ancestorst   d(    (    sB   lib/python2.7/site-packages/sphinx/environment/adapters/toctree.pyRq     s    c         C   sÞ   x× | j  D]Ë } t | t j t j f ƒ rE |  j | | | | ƒ q t | t j ƒ r | d k r… | | k r… | j j	 | g  ƒ qÖ | r¹ | d k r¹ d | j k r¹ | j j
 | ƒ qÖ |  j | | d | | ƒ q q Wd S(   s(   Utility: Cut a TOC at a specified depth.i    i   R'   N(   R(   R)   R   R*   R    R+   RG   R-   R/   t   replaceRQ   (   R   R1   R2   R\   Rg   R3   (    (    sB   lib/python2.7/site-packages/sphinx/environment/adapters/toctree.pyRG     s    c         C   s©   |  j  j | j d d ƒ } y- |  j  j | j ƒ  } |  j | d | ƒ Wn t k
 rc t j ƒ  SXt	 | | j
 ƒ x. | j t j ƒ D] } | d pš d | d <q‡ W| S(   s7   Return a TOC nodetree -- for use on the same page only!R:   i    i   R%   t   #R$   (   R   RF   R   RD   RE   RG   RK   R    t	   paragraphR   RH   RJ   R.   (   R   R   Rf   R:   R[   R1   (    (    sB   lib/python2.7/site-packages/sphinx/environment/adapters/toctree.pyt   get_toc_for(  s    c   
      K   së   |  j  j |  j  j j ƒ } g  } d | k r: t | d <n  d | k rS d | d <n  | | d <xN | j t j ƒ D]: } |  j | | | d t | } | rp | j	 | ƒ qp qp W| s¸ d S| d }	 x" | d D] } |	 j | j ƒ qÍ W|	 S(   s   Return the global TOC nodetree.Ri   R\   i    Rg   Rj   i   N(   R   t   get_doctreeRr   t
   master_docR0   RJ   R   RM   R}   R,   R<   R   R(   (
   R   R   Rf   Rg   t   kwdst   doctreet   toctreesR   RM   t   result(    (    sB   lib/python2.7/site-packages/sphinx/environment/adapters/toctree.pyt   get_toctree_for8  s"    

(   t   __name__t
   __module__R   R!   R0   R>   R}   Rq   RG   R„   R‹   (    (    (    sB   lib/python2.7/site-packages/sphinx/environment/adapters/toctree.pyR      s   		Ñ		N(   t   __doc__t   docutilsR    t   sixR   t   sphinxR   t   sphinx.localeR   t   sphinx.utilR   R   t   sphinx.util.matchingR   t   sphinx.util.nodesR   R   R>   t   typingR	   R
   R   t   sphinx.buildersR   t   sphinx.environmentR   t	   getLoggerRŒ   RA   t   objectR   (    (    (    sB   lib/python2.7/site-packages/sphinx/environment/adapters/toctree.pyt   <module>
   s   