o
    î?À]h  ã                   @   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
   ú>/usr/lib/python3/dist-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   