o
    i                     @  sb   d Z ddlmZ dZddlZddlmZmZmZ G dd deZ	G dd	 d	Z
G d
d deZdS )a  
This package contains modules for standard tree transforms available
to Docutils components. Tree transforms serve a variety of purposes:

- To tie up certain syntax-specific "loose ends" that remain after the
  initial parsing of the input plaintext. These transforms are used to
  supplement a limited syntax.

- To automate the internal linking of the document tree (hyperlink
  references, footnote references, etc.).

- To extract useful information from the document tree. These
  transforms may be used to construct (for example) indexes and tables
  of contents.

Each transform is an optional step that a Docutils component may
choose to perform on the parsed document.
    )annotationsreStructuredTextN)	languagesApplicationErrorTransformSpecc                   @  s   e Zd ZdS )TransformErrorN)__name__
__module____qualname__ r   r   b/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/docutils/transforms/__init__.pyr   !   s    r   c                   @  s*   e Zd ZdZdZ	 d	d
ddZdd ZdS )	Transformz1Docutils transform component abstract base class.NreturnNonec                 C  s(   || _ 	 || _	 t|jj|j| _dS )zA
        Initial setup for in-place document transforms.
        N)document	startnoder   get_languagesettingslanguage_codereporterlanguage)selfr   r   r   r   r   __init__+   s   
zTransform.__init__c                 K  s   t d)z5Override to apply the transform to the document tree.z"subclass must override this method)NotImplementedError)r   kwargsr   r   r   apply<   s   zTransform.applyNr   r   )r   r	   r
   __doc__default_priorityr   r   r   r   r   r   r   %   s    r   c                   @  sZ   e Zd ZdZdddZddddZdd	d
ZddddZdddZdddZ	dddZ
dS )Transformerac  
    Store "transforms" and apply them to the document tree.

    Collect lists of `Transform` instances from Docutils
    components (`TransformSpec` instances).
    Apply collected "transforms" to the document tree.

    Also keeps track of components by component type name.

    https://docutils.sourceforge.io/docs/peps/pep-0258.html#transformer
    r   r   c                 C  s:   g | _ 	 g | _	 || _	 g | _	 d| _	 i | _	 d| _d S )NFr   )
transformsunknown_reference_resolversr   appliedsorted
componentsserialno)r   r   r   r   r   r   N   s   zTransformer.__init__Nc                 K  s6   |du r|j }| |}| j||d|f d| _dS )a+  
        Store a single transform.  Use `priority` to override the default.
        `kwargs` is a dictionary whose contents are passed as keyword
        arguments to the `apply` method of the transform.  This can be used to
        pass application-specific data to the transform instance.
        NF)r   get_priority_stringr!   appendr$   )r   transform_classpriorityr   priority_stringr   r   r   add_transformm   s   


zTransformer.add_transformc                 C  s4   |D ]}|  |j}| j||di f qd| _dS )z3Store multiple transforms, with default priorities.NF)r'   r   r!   r(   r$   )r   transform_listr)   r+   r   r   r   add_transforms{   s   

zTransformer.add_transformsc                 C  s<   |j }|du r
|j}| |}| j|||i f d| _dS )z4Store a transform with an associated `pending` node.NF)	transformr   r'   r!   r(   r$   )r   pendingr*   r)   r+   r   r   r   add_pending   s   


zTransformer.add_pendingstrc                 C  s   |  j d7  _ d|| j f S )z
        Return a string, `priority` combined with `self.serialno`.

        This ensures FIFO order on transforms with identical priority.
           z	%03d-%03d)r&   )r   r*   r   r   r   r'      s   zTransformer.get_priority_stringc                 C  s   g }|D ]}t |tsq| |  || j|j< ||j qd| _dd }|j	|d |  j|7  _| jrAt
jdtdd dS dS )	ao  
        Store each component's default transforms and reference resolvers.

        Transforms are stored with default priorities for later sorting.
        "Unknown reference resolvers" are sorted and stored.
        Components that don't inherit from `TransformSpec` are ignored.

        Also, store components by type name in a mapping for later lookup.
        Fc                 S  s   | j S r   )r*   )fr   r   r   keyfun   s   z4Transformer.populate_from_components.<locals>.keyfun)keyztThe `unknown_reference_resolvers` hook chain will be removed in Docutils 1.0.
Use a transform to resolve references.   )
stacklevelN)
isinstancer   r.   get_transformsr%   component_typeextendr"   r$   sortwarningswarnDeprecationWarning)r   r%   	resolvers	componentr5   r   r   r   populate_from_components   s    


z$Transformer.populate_from_componentsc                 C  s   | j j| j j | jr>| js| jjdd d| _| j \}}}}|| j |d}|jdi | | j	
||||f | js| j j| j j dS )z6Apply all of the stored transforms, in priority order.T)reverse)r   Nr   )r   r   attach_observernote_transform_messager!   r$   r=   popr   r#   r(   detach_observer)r   r*   r)   r0   r   r/   r   r   r   apply_transforms   s   
zTransformer.apply_transformsr   r   )r   r2   )r   r	   r
   r   r   r,   r.   r1   r'   rC   rI   r   r   r   r   r    A   s    

	


	r    )r   
__future__r   __docformat__r>   docutilsr   r   r   r   r   r    r   r   r   r   <module>   s   