o
    gh                     @   sP   d Z dZddlmZmZmZ G dd deZG dd de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.
reStructuredText    )	languagesApplicationErrorTransformSpecc                   @   s   e Zd ZdS )TransformErrorN)__name__
__module____qualname__ r
   r
   Z/home/ubuntu/cloudmapper/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Zdd ZdS )	Transformz;
    Docutils transform component abstract base class.
    Nc                 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	   __doc__default_priorityr   r   r
   r
   r
   r   r   !   s    
r   c                   @   sL   e Zd ZdZdd ZdddZdd Zdd	d
Zdd Zdd Z	dd Z
dS )Transformerz
    Stores transforms (`Transform` classes) and applies them to document
    trees.  Also keeps track of components by component type name.
    c                 C   s:   g | _ 	 g | _	 || _	 g | _	 d| _	 i | _	 d| _d S )Nr   )
transformsunknown_reference_resolversr   appliedsorted
componentsserialno)r   r   r
   r
   r   r   G   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.
        Nr   )r   get_priority_stringr   appendr    )r   transform_classpriorityr   priority_stringr
   r
   r   add_transforma   s   


zTransformer.add_transformc                 C   s4   |D ]}|  |j}| j||di f qd| _dS )z3Store multiple transforms, with default priorities.Nr   )r#   r   r   r$   r    )r   transform_listr%   r'   r
   r
   r   add_transformso   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.Nr   )	transformr   r#   r   r$   r    )r   pendingr&   r%   r'   r
   r
   r   add_pendingx   s   


zTransformer.add_pendingc                 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   sz   |D ]}|du r	q|  |  || j|j< qd| _g }|D ]}||j qtdd |D }| jdd |D  dS )z
        Store each component's default transforms, with default priorities.
        Also, store components by type name in a mapping for later lookup.
        Nr   c                 s   s    | ]}|j |fV  qd S r   )r&   .0fr
   r
   r   	<genexpr>   s    z7Transformer.populate_from_components.<locals>.<genexpr>c                 s   s    | ]}|d  V  qdS )r.   Nr
   r/   r
   r
   r   r2      s    )r*   get_transformsr!   component_typer    extendr   )r   r!   	componentr   idecorated_listr
   r
   r   populate_from_components   s   z$Transformer.populate_from_componentsc                 C   s   | j j| j j | jrC| js| j  | j  d| _| j \}}}}|| j |d}|j	di | | j
||||f | jsdS dS )z6Apply all of the stored transforms, in priority order.r.   )r   Nr
   )r   r   attach_observernote_transform_messager   r    sortreversepopr   r   r$   )r   r&   r%   r,   r   r+   r
   r
   r   apply_transforms   s   

zTransformer.apply_transformsr   )r   r   r	   r   r   r(   r*   r-   r#   r9   r?   r
   r
   r
   r   r   @   s    

	
	r   N)
r   __docformat__docutilsr   r   r   r   objectr   r   r
   r
   r
   r   <module>   s   