ó
¶ÊzJc           @   s™   d  Z  d Z d d l Z d d l Z d d l m Z m Z d d l m Z m	 Z	 d e	 f d „  ƒ  YZ
 d e	 f d	 „  ƒ  YZ d
 e j f d „  ƒ  YZ d S(   s'   
Transforms related to document parts.
t   reStructuredTextiÿÿÿÿN(   t   nodest   utils(   t   TransformErrort	   Transformt   SectNumc           B   s,   e  Z d  Z d Z d „  Z d d d „ Z RS(   sS  
    Automatically assigns numbers to the titles of document sections.

    It is possible to limit the maximum section level for which the numbers
    are added.  For those sections that are auto-numbered, the "autonum"
    attribute is set, informing the contents table generator that a different
    form of the TOC should be used.
    iÆ  c         C   s  |  j  j j d d  ƒ |  _ |  j  j j d d ƒ |  _ |  j  j j d d ƒ |  _ |  j  j j d d ƒ |  _ |  j  j j	 |  j  ƒ |  j
 j j rÂ |  j d  k r¯ t j |  _ n  |  j |  j
 ƒ nH |  j |  j
 j _ |  j |  j
 j _ |  j |  j
 j _ |  j |  j
 j _ d  S(   Nt   deptht   starti   t   prefixt    t   suffix(   t	   startnodet   detailst   gett   Nonet   maxdeptht
   startvalueR   R
   t   parentt   removet   documentt   settingst   sectnum_xformt   syst   maxintt   update_section_numberst   sectnum_deptht   sectnum_startt   sectnum_prefixt   sectnum_suffix(   t   self(    (    s=   /usr/lib/python2.7/dist-packages/docutils/transforms/parts.pyt   apply    s    i    c   	      C   sè   | d 7} | r d } n	 |  j  } x¿ | D]· } t | t j ƒ r) | t | ƒ f } | d } t j d |  j d j | ƒ |  j d
 d d g ƒ} | j	 d | ƒ d | d	 <| |  j
 k  rÓ |  j | | | ƒ n  | d 7} q) q) Wd  S(   Ni   i    R	   t   .u   Â i   t   classest   sectnumt   autou   Â Â Â (   R   t
   isinstanceR   t   sectiont   strt	   generatedR   t   joinR
   t   insertR   R   (	   R   t   nodeR   R   R!   t   childt   numberst   titleR&   (    (    s=   /usr/lib/python2.7/dist-packages/docutils/transforms/parts.pyR   0   s"    
		
!
(    (   t   __name__t
   __module__t   __doc__t   default_priorityR   R   (    (    (    s=   /usr/lib/python2.7/dist-packages/docutils/transforms/parts.pyR      s   		t   Contentsc           B   s2   e  Z d  Z d Z d „  Z d d „ Z d „  Z RS(   sè  
    This transform generates a table of contents from the entire document tree
    or from a single branch.  It locates "section" elements and builds them
    into a nested bullet list, which is placed within a "topic" created by the
    contents directive.  A title is either explicitly specified, taken from
    the appropriate language module, or omitted (local table of contents).
    The depth may be specified.  Two-way references between the table of
    contents and section titles are generated (requires Writer support).

    This transform requires a startnode, which contains generation
    options and provides the location for the generated table of contents (the
    startnode is replaced by the table of contents "topic").
    iÐ  c         C   s\  y |  j  j j } Wn t k
 r, t } n X|  j j } d | k r‹ |  j j j } x= t | t	 j
 ƒ px t | t	 j  ƒ s‡ | j } qW Wn	 |  j  } |  j j d d |  _ d | k rÇ | d |  _ n |  j  j j |  _ | r|  j j j j | ƒ |  j j j |  j ƒ nJ |  j | ƒ } t | ƒ r<|  j j | ƒ n |  j j j j |  j j ƒ d  S(   Nt   localt   idsi    t	   backlinks(   R   R   t   use_latex_toct   AttributeErrort   FalseR   R   R   R#   R   R$   t   toc_idR4   t   toc_backlinkst
   attributest   updateR   t   build_contentst   lent   replace_self(   R   t   toc_by_writerR   R   t   contents(    (    s=   /usr/lib/python2.7/dist-packages/docutils/transforms/parts.pyR   X   s,    
	i    c         C   sÌ  | d 7} g  | D] } t  | t j ƒ r | ^ q } g  } d } |  j j j d t j ƒ } x/| D]'} | d }	 |	 j d ƒ }
 |  j |	 ƒ } t j	 d d d | d d | Œ} |  j
 j | ƒ } t j d d | ƒ } t j d | ƒ } |  j d k rR|	 j t j	 ƒ d  k rR|  j d k r0| |	 d <qR|  j d	 k rR|  j |	 d <qRn  | | k  r}|  j | | ƒ } | | 7} n  | j | ƒ qc W| rÄt j d | Œ } |
 rÀ| d
 j d ƒ n  | Sg  Sd  S(   Ni   i    R   R"   R	   t   refidR3   t   entryt   topR    s   auto-toc(   s   entrys   top(   R#   R   R$   R   R   R   R   R   t   copy_and_filtert	   referenceR   t   set_idt	   paragrapht	   list_itemR4   t	   next_nodeR   R8   R<   t   appendt   bullet_list(   R   R)   t   levelt   sectt   sectionst   entriest   autonumR   R$   R,   R"   t	   entrytextRE   t   ref_idRB   t   itemt   subsectsR@   (    (    s=   /usr/lib/python2.7/dist-packages/docutils/transforms/parts.pyR<   v   s<    
+
	c         C   s&   t  |  j ƒ } | j | ƒ | j ƒ  S(   s@   Return a copy of a title, with references, images, etc. removed.(   t   ContentsFilterR   t	   walkaboutt   get_entry_text(   R   R)   t   visitor(    (    s=   /usr/lib/python2.7/dist-packages/docutils/transforms/parts.pyRD   —   s    (   R-   R.   R/   R0   R   R<   RD   (    (    (    s=   /usr/lib/python2.7/dist-packages/docutils/transforms/parts.pyR1   F   s
   	!RU   c           B   sM   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z e Z e Z e Z	 e Z
 RS(   c         C   s   |  j  ƒ  j S(   N(   t   get_tree_copyt   children(   R   (    (    s=   /usr/lib/python2.7/dist-packages/docutils/transforms/parts.pyRW       s    c         C   s   t  j ‚ d  S(   N(   R   t   SkipNode(   R   R)   (    (    s=   /usr/lib/python2.7/dist-packages/docutils/transforms/parts.pyt   visit_citation_reference£   s    c         C   s   t  j ‚ d  S(   N(   R   R[   (   R   R)   (    (    s=   /usr/lib/python2.7/dist-packages/docutils/transforms/parts.pyt   visit_footnote_reference¦   s    c         C   s<   | j  d ƒ r/ |  j j t j | d ƒ ƒ n  t j ‚ d  S(   Nt   alt(   t   hasattrR   RJ   R   t   TextR[   (   R   R)   (    (    s=   /usr/lib/python2.7/dist-packages/docutils/transforms/parts.pyt   visit_image©   s     c         C   s   t  j ‚ d  S(   N(   R   t   SkipDeparture(   R   R)   (    (    s=   /usr/lib/python2.7/dist-packages/docutils/transforms/parts.pyt    ignore_node_but_process_children®   s    (   R-   R.   RW   R\   R]   Ra   Rc   t   visit_interpretedt   visit_problematict   visit_referencet   visit_target(    (    (    s=   /usr/lib/python2.7/dist-packages/docutils/transforms/parts.pyRU   ž   s   					(   R/   t   __docformat__t   reR   t   docutilsR   R   t   docutils.transformsR   R   R   R1   t   TreeCopyVisitorRU   (    (    (    s=   /usr/lib/python2.7/dist-packages/docutils/transforms/parts.pyt   <module>   s   4X