o
    i                     @  s`   d Z ddlmZ dZddlmZ ddl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.
    )annotationsreStructuredText)nodes)	Transformc                   @     e Zd ZdZdZd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  returnNonec                 C  s$   | j }|jd | |j| d S )Ncallback)	startnodedetailsparentremove)selfpending r   ^/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/docutils/transforms/misc.pyapply   s   zCallBack.applyNr   r	   __name__
__module____qualname____doc__default_priorityr   r   r   r   r   r      s    
r   c                   @  r   )	ClassAttributezg
    Move the "class" attribute specified in the "pending" node into the
    next visible element.
       r   r	   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   r   %   s    r   c                   @  s(   e Zd ZdZdZd
ddZd
ddZd	S )Transitionsa  
    Move transitions at the end of sections up the tree.  Complain
    on transitions after a title, subtitle, meta, or decoration element,
    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>  r   r	   c                 C  s"   | j tjD ]}| | qd S )N)r(   findallr   
transitionvisit_transition)r   noder   r   r   r   b   s   zTransitions.applyc                 C  s  |j |}| }d}t|j tjtjfsd}n|dks*t|tjtjtj	tj
fr-d}nt|tjr5d}|rr| jjj||d}t |j |< z	|j jdd W n tjy_   ||j |< Y nw ||j |< |j |d	 | |d	7 }t|j tjtjfs~d S |t|j k sJ |t|j d	 krd S |}|t|j d	 kr|j }|j d u r| jjjd
|d}|j | d S |j |}|t|j d	 ks|j | |j |d	 | d S )N z4Transition must be child of <document> or <section>.r   z4Document or section may not begin with a transition.zZAt least one body element must separate transitions; adjacent transitions are not allowed.)	base_nodeF)	recursiver   z'Document may not end with a transition.)r   r#   previous_siblingr%   r   r(   sectiontitlesubtitlemeta
decorationr2   r)   warning	paragraphvalidateValidationErrorinsertr$   appendr   )r   r4   r#   r8   msgr>   siblingr   r   r   r3   f   sV   

zTransitions.visit_transitionNr   )r   r   r   r   r   r   r3   r   r   r   r   r0   H   s
    
r0   N)r   
__future__r   __docformat__docutilsr   docutils.transformsr   r   r   r0   r   r   r   r   <module>   s   #