U C^z@sNdZdZddlmZmZmZGdddeZGdddZGdd d eZd 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. ZreStructuredText) languagesApplicationError TransformSpecc@s eZdZdS)TransformErrorN)__name__ __module__ __qualname__r r B/tmp/pip-install-6_kvzl1k/docutils/docutils/transforms/__init__.pyrsrc@s&eZdZdZdZdddZddZdS) Transformz; Docutils transform component abstract base class. NcCs$||_||_t|jj|j|_dS)zA Initial setup for in-place document transforms. N)document startnoderZ get_languagesettingsZ language_codereporterlanguage)selfr r r r r __init__*szTransform.__init__cKs tddS)z5Override to apply the transform to the document tree.z"subclass must override this methodN)NotImplementedError)rkwargsr r r apply;szTransform.apply)N)rrr__doc__default_priorityrrr r r r r !s r c@sLeZdZdZddZdddZddZdd d Zd d Zd dZ ddZ dS) Transformerz Stores transforms (`Transform` classes) and applies them to document trees. Also keeps track of components by component type name. cCs.g|_g|_||_g|_d|_i|_d|_dS)Nr) transformsunknown_reference_resolversr appliedsorted componentsserialno)rr r r r rGszTransformer.__init__NcKs6|dkr|j}||}|j||d|fd|_dS)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)rget_priority_stringrappendr)rtransform_classpriorityrpriority_stringr r r add_transformas  zTransformer.add_transformcCs4|D]$}||j}|j||difqd|_dS)z3Store multiple transforms, with default priorities.Nr)rrrr r)rZtransform_listr!r#r r r add_transformsos zTransformer.add_transformscCs<|j}|dkr|j}||}|j|||ifd|_dS)z4Store a transform with an associated `pending` node.Nr) transformrrrr r)rpendingr"r!r#r r r add_pendingxs  zTransformer.add_pendingcCs|jd7_d||jfS)z Return a string, `priority` combined with `self.serialno`. This ensures FIFO order on transforms with identical priority. z %03d-%03d)r)rr"r r r rszTransformer.get_priority_stringcCs~|D](}|dkrq||||j|j<qd|_g}|D]}||jqsz8Transformer.populate_from_components..cSsg|] }|dqS)r)r r*r r r r-s)r%Zget_transformsrZcomponent_typerextendrsort)rr componentriZdecorated_listr r r populate_from_componentssz$Transformer.populate_from_componentscCs~|jj|jj|jrz|js8|j|jd|_|j\}}}}||j|d}|j f||j ||||fqdS)z6Apply all of the stored transforms, in priority order.r))r N) r rZattach_observerZnote_transform_messagerrr/reversepoprrr )rr"r!r'rr&r r r apply_transformss   zTransformer.apply_transforms)N)N) rrrrrr$r%r(rr2r5r r r r r@s   rN) rZ __docformat__Zdocutilsrrrrr rr r r r s