
    4 f                     `    d Z dZddlmZmZmZ  G d de      Z G d d      Z G d d	e      Zy
)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                       e Zd Zy)TransformErrorN)__name__
__module____qualname__     R/var/www/equiseq/venv/lib/python3.11/site-packages/docutils/transforms/__init__.pyr   r      s    r   r   c                   $    e Zd ZdZdZ	 ddZd Zy)	Transformz1Docutils transform component abstract base class.Nc                     || _         	 || _        	 t        j                  |j                  j
                  |j                        | _        y)zA
        Initial setup for in-place document transforms.
        N)document	startnoder   get_languagesettingslanguage_codereporterlanguage)selfr   r   s      r   __init__zTransform.__init__(   sI    
 !-"	 "..++X->->@5r   c                     t        d      )z5Override to apply the transform to the document tree.z"subclass must override this method)NotImplementedError)r   kwargss     r   applyzTransform.apply9   s    !"FGGr   N)r	   r
   r   __doc__default_priorityr   r   r   r   r   r   r   "   s    ;I6"Hr   r   c                   >    e Zd ZdZd Zd
dZd Zd
dZd Zd Z	d	 Z
y)Transformera  
    Store "transforms" and apply them to the document tree.

    Collect lists of `Transform` instances and "unknown_reference_resolvers"
    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
    c                 r    g | _         	 g | _        	 || _        	 g | _        	 d| _        	 i | _        	 d| _        y )NFr   )
transformsunknown_reference_resolversr   appliedsorted
componentsserialno)r   r   s     r   r   zTransformer.__init__K   sS    	 ,.(J J32	
 	r   Nc                     ||j                   }| j                  |      }| j                  j                  ||d|f       d| _        y)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_strings        r   add_transformzTransformer.add_transformg   sJ     &77H228<otV<	>r   c                     |D ]<  }| j                  |j                        }| j                  j                  ||di f       > d| _        y)z3Store multiple transforms, with default priorities.NF)r,   r!   r%   r-   r(   )r   transform_listr.   r0   s       r   add_transformszTransformer.add_transformsu   sQ    - 	>O"66002OOO"" /4<>	>
 r   c                     |j                   }||j                  }| j                  |      }| j                  j	                  |||i f       d| _        y)z4Store a transform with an associated `pending` node.NF)	transformr!   r,   r%   r-   r(   )r   pendingr/   r.   r0   s        r   add_pendingzTransformer.add_pending~   sS    !++&77H228<ow;	=r   c                 N    | xj                   dz  c_         d|| j                   fz  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/   s     r   r,   zTransformer.get_priority_string   s&     	h666r   c                 @   g }|D ]f  }t        |t              s| j                  |j                                || j                  |j
                  <   |j                  |j                         h d| _        d }|j                  |       | xj                  |z  c_        y)an  
        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                     | j                   S r   )r/   )fs    r   keyfunz4Transformer.populate_from_components.<locals>.keyfun   s    ::r   )keyN)

isinstancer   r4   get_transformsr)   component_typeextendr&   r(   sort)r   r)   	resolvers	componentr>   s        r   populate_from_componentsz$Transformer.populate_from_components   s     	# 	DIi7	 8 8 :;8ADOOI445YBBC	D 	6"((I5(r   c                    | j                   j                  j                  | j                   j                         | j                  r| j
                  s#| j                  j                  d       d| _        | j                  j                         \  }}}} || j                   |      } |j                  di | | j                  j                  ||||f       | j                  ryy)z6Apply all of the stored transforms, in priority order.T)reverse)r   Nr   )r   r   attach_observernote_transform_messager%   r(   rD   popr   r'   r-   )r   r/   r.   r7   r   r6   s         r   apply_transformszTransformer.apply_transforms   s    ..MM00	2oo;; $$T$2"9=9L9L9N6How'IIIOO%f%LL?GV LM oor   r   )r	   r
   r   r    r   r1   r4   r8   r,   rG   rM   r   r   r   r#   r#   >   s+    
8762Nr   r#   N)	r    __docformat__docutilsr   r   r   r   r   r#   r   r   r   <module>rP      sC   
& # @ ?	% 	H H8yN- yNr   