ó
!eÕKc           @   sx   d  Z  d Z d d l m Z d d l m Z m Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d	 e f d
 „  ƒ  YZ	 d S(   s   
Miscellaneous transforms.
t   reStructuredTextiÿÿÿÿ(   t   nodes(   t	   Transformt   TransformErrort   CallBackc           B   s   e  Z d  Z d Z d „  Z RS(   s  
    Inserts a callback into a document.  The callback is called when the
    transform is applied, which is determined by its priority.

    For use with `nodes.pending` elements.  Requires a ``details['callback']``
    entry, a bound method or function which takes one parameter: the pending
    node.  Other data can be stored in the ``details`` attribute or in the
    object hosting the callback method.
    iÞ  c         C   s.   |  j  } | j d | ƒ | j j | ƒ d  S(   Nt   callback(   t	   startnodet   detailst   parentt   remove(   t   selft   pending(    (    s<   /usr/lib/python2.7/dist-packages/docutils/transforms/misc.pyt   apply   s    	(   t   __name__t
   __module__t   __doc__t   default_priorityR   (    (    (    s<   /usr/lib/python2.7/dist-packages/docutils/transforms/misc.pyR      s   
t   ClassAttributec           B   s   e  Z d  Z d Z d „  Z RS(   s|   
    Move the "class" attribute specified in the "pending" node into the
    immediately following non-comment element.
    iÒ   c         C   s  |  j  } | j } | } x¢ | r¼ x• t | j | ƒ d t | ƒ ƒ D]b } | | } t | t j ƒ sD t | t j ƒ r~ qD n  | d c | j	 d 7<| j j
 | ƒ d  SW| } | j } q W|  j j j d | j	 d t j | j | j ƒ d | j ƒ} | j | ƒ d  S(   Ni   t   classest   classs,   No suitable element following "%s" directivet	   directivet   line(   R   R   t   ranget   indext   lent
   isinstanceR   t	   Invisiblet   system_messageR   R	   t   documentt   reportert   errort   literal_blockt	   rawsourceR   t   replace_self(   R
   R   R   t   childR   t   elementR   (    (    s<   /usr/lib/python2.7/dist-packages/docutils/transforms/misc.pyR   ,   s(    			)
(   R   R   R   R   R   (    (    (    s<   /usr/lib/python2.7/dist-packages/docutils/transforms/misc.pyR   #   s   t   Transitionsc           B   s&   e  Z d  Z d Z d „  Z d „  Z RS(   s¡  
    Move transitions at the end of sections up the tree.  Complain
    on transitions after a title, at the beginning or end of the
    document, and after another transition.

    For example, transform this::

        <section>
            ...
            <transition>
        <section>
            ...

    into this::

        <section>
            ...
        <transition>
        <section>
            ...
    i>  c         C   s1   x* |  j  j t j ƒ D] } |  j | ƒ q Wd  S(   N(   R   t   traverseR   t
   transitiont   visit_transition(   R
   t   node(    (    s<   /usr/lib/python2.7/dist-packages/docutils/transforms/misc.pyR   `   s    c         C   s-  | j  j | ƒ } d  } | d k sn t | j  d t j ƒ rÈ | d k sn t | j  d t j ƒ rÈ | d k rÈ t | j  t j ƒ sž t | j  t j ƒ sž t	 ‚ |  j j
 j d d | j d | j ƒ} nG t | j  | d t j ƒ r|  j j
 j d d | j d | j ƒ} n  | r5| j  j | | ƒ | d 7} n  | t | j  ƒ k  sPt	 ‚ | t | j  ƒ d k rmd  S| } xŒ | t | j  ƒ d k r| j  } | j  d  k rì|  j j
 j d d | j ƒ} | j  j | j  j | ƒ d | ƒ d  S| j  j | ƒ } qvW| j  j | ƒ | j  j | d | ƒ d  S(	   Ni    i   i   s4   Document or section may not begin with a transition.t   sourceR   sZ   At least one body element must separate transitions; adjacent transitions are not allowed.s'   Document may not end with a transition.(   R   R   t   NoneR   R   t   titlet   subtitleR   t   sectiont   AssertionErrorR   R   R)   R   R&   t   insertR   R	   (   R
   R(   R   R   t   sibling(    (    s<   /usr/lib/python2.7/dist-packages/docutils/transforms/misc.pyR'   d   sD    	#(   R   R   R   R   R   R'   (    (    (    s<   /usr/lib/python2.7/dist-packages/docutils/transforms/misc.pyR$   F   s   	N(
   R   t   __docformat__t   docutilsR   t   docutils.transformsR   R   R   R   R$   (    (    (    s<   /usr/lib/python2.7/dist-packages/docutils/transforms/misc.pyt   <module>   s   #