
    dd	                     f    d Z dZddlmZ ddlmZ  G d de      Z G d de      Z G d	 d
e      Zy)z
Miscellaneous transforms.
reStructuredText    )nodes)	Transformc                       e Zd ZdZdZd Zy)CallBacka  
    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                 |    | j                   } |j                  d   |       |j                  j                  |       y )Ncallback)	startnodedetailsparentremove)selfpendings     :/usr/lib/python3/dist-packages/docutils/transforms/misc.pyapplyzCallBack.apply   s0    ..#
#G,g&    N__name__
__module____qualname____doc__default_priorityr    r   r   r   r      s     'r   r   c                       e Zd ZdZdZd Zy)ClassAttributez|
    Move the "class" attribute specified in the "pending" node into the
    immediately following non-comment element.
       c                    | j                   }|j                  }|}|rt        |j                  |      dz   t	        |            D ]r  }||   }t        |t        j                        st        |t        j                        r=|dxx   |j                  d   z  cc<   |j                  j                  |        y  |}|j                  }|r| j                  j                  j                  d|j                  d   z  t        j                  |j                  |j                        |j                         }|j#                  |       y )N   classesclassz,No suitable element following "%s" directive	directiveline)r
   r   rangeindexlen
isinstancer   	Invisiblesystem_messager   r   documentreportererrorliteral_block	rawsourcer#   replace_self)r   r   r   childr%   elementr,   s          r   r   zClassAttribute.apply,   s   ..v||E2Q6FD ' -w8!'5+?+?@	"goog&>>"%%g.'   &&,,:ook*+ 1 173D3DE	 - 
 	U#r   Nr   r   r   r   r   r   #   s    
 $r   r   c                        e Zd ZdZdZd Zd Zy)Transitionsa  
    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                     | j                   j                  t        j                        D ]  }| j	                  |        y )N)r*   findallr   
transitionvisit_transition)r   nodes     r   r   zTransitions.apply`   s4    MM))%*:*:; 	(D!!$'	(r   c                    |j                   j                  |      }d }|dk(  sXt        |j                   d   t        j                        r|dk(  s,t        |j                   d   t        j
                        r|dk(  rt        |j                   t        j                        s&t        |j                   t        j                        sJ | j                  j                  j                  d|j                  |j                        }nft        |j                   |dz
     t        j                        r<| j                  j                  j                  d|j                  |j                        }|r!|j                   j                  ||       |dz  }|t        |j                         k  sJ |t        |j                         dz
  k7  ry |}|t        |j                         dz
  k(  r|j                   }|j                   j| j                  j                  j                  d|j                        }|j                   j                  |j                   j                  |      dz   |       y |j                   j                  |      }|t        |j                         dz
  k(  r|j                   j                  |       |j                   j                  |dz   |       y )	Nr   r      z4Document or section may not begin with a transition.)sourcer#   zZAt least one body element must separate transitions; adjacent transitions are not allowed.z'Document may not end with a transition.r"   )r   r%   r'   r   titlesubtitler*   sectionr+   r,   r;   r#   r6   insertr&   r   )r   r8   r%   r,   siblings        r   r7   zTransitions.visit_transitiond   s9   !!$'QJ$++a.%++6!t{{1~u~~>aZt{{ENN;!$++u}}=? >MM**00F{{ 1 4E EAI.0@0@AMM**008{{ 1 4E KKue,QJEs4;;''''C$q((s7>>*Q..nnG~~% ..44= 5 $ ""4;;#4#4T#:Q#>FNN((1E s7>>*Q.. 	4 eai.r   N)r   r   r   r   r   r   r7   r   r   r   r3   r3   F   s    , (,/r   r3   N)	r   __docformat__docutilsr   docutils.transformsr   r   r   r3   r   r   r   <module>rD      s>   
 #  )'y '( $Y  $FJ/) J/r   