o
    �w#[  ã                   @   sX   d Z dZddlmZ ddlmZmZ G dd„ deƒZG dd„ deƒZG d	d
„ d
eƒZ	dS )z
Miscellaneous transforms.
ÚreStructuredTexté    )Únodes)Ú	TransformÚTransformErrorc                   @   ó   e Zd ZdZdZdd„ ZdS )Ú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                 C   s$   | j }|jd |ƒ |j |¡ d S )NÚcallback)Ú	startnodeÚdetailsÚparentÚremove)ÚselfÚpending© r   ú:/usr/lib/python3/dist-packages/docutils/transforms/misc.pyÚapply   s   zCallBack.applyN©Ú__name__Ú
__module__Ú__qualname__Ú__doc__Údefault_priorityr   r   r   r   r   r      s    
r   c                   @   r   )ÚClassAttributez|
    Move the "class" attribute specified in the "pending" node into the
    immediately following non-comment element.
    éÒ   c                 C   sÂ   | j }|j}|}|rDt| |¡d t|ƒƒD ]&}|| }t|tjƒs(t|tjƒr)q|d  |j	d 7  < |j 
|¡  d S |}|j}|s
| jjjd|j	d  t |j|j¡|jd�}| |¡ d S )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(   r   r   r   r   ,   s0   
ÿóÿüzClassAttribute.applyNr   r   r   r   r   r   #   s    r   c                   @   s$   e Zd ZdZdZdd„ Zdd„ ZdS )Ú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                 C   s"   | j  tj¡D ]}|  |¡ qd S )N)r&   Útraverser   Ú
transitionÚvisit_transition)r   Únoder   r   r   r   `   s   ÿzTransitions.applyc                 C   sŽ  |j  |¡}d }|dks&t|j d tjƒrC|dks&t|j d tjƒrC|dkrCt|j tjƒs6t|j tjƒs6J ‚| jjj	d|j
|jd�}nt|j |d  tjƒrZ| jjj	d|j
|jd�}|rg|j  ||¡ |d7 }|t|j ƒk spJ ‚|t|j ƒd kr{d S |}|t|j ƒd kr¶|j }|j d u r§| jjj	d|jd�}|j  |j  |¡d |¡ d S |j  |¡}|t|j ƒd ks†|j  |¡ |j  |d |¡ d S )	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(   r4   r   r0   Úinsertr"   r   )r   r2   r!   r(   Úsiblingr   r   r   r1   d   sR   ÿÿÿþý
þõzTransitions.visit_transitionN)r   r   r   r   r   r   r1   r   r   r   r   r.   F   s
    r.   N)
r   Ú__docformat__Údocutilsr   Údocutils.transformsr   r   r   r   r.   r   r   r   r   Ú<module>   s   #