bib.bibtexparser.middlewares.middleware¶
Classes¶
BlockMiddleware ¶
Bases: Middleware, ABC
Transform a library on a per-block basis.
The BlockMiddleware replaces a block with zero, one or more new (transformed) blocks.
Changes may rely on the state of the overall library, but must not change the state of the library directly, except if allow_inplace_modification is true.
Source code in pybibtexer/bib/bibtexparser/middlewares/middleware.py
Functions¶
metadata_key classmethod ¶
Tt is the identifier of the middleware.
This key is used to identify the middleware in a blocks metadata.
transform_block ¶
Transform a block.
:param block: Block to transform. :param library: Library containing the block. Should typically not be modified during the transformation, but be considered as read-only. If the library is modified, make sure to set the allow_multithreading constructor argument to false :return: Transformed block. If the block should be removed, return None. If the block should be replaced by multiple blocks, return a collection of blocks. If the block should be replaced by a single block, return the single block. If the block should not be modified, return a copy of the original block. The returned block has to be a new instance, except if self.allow_inplace_modification is True (in which case the block may also return the original block).
Source code in pybibtexer/bib/bibtexparser/middlewares/middleware.py
transform_entry ¶
Transform an entry. Called by transform_block if the block is an entry.
Note: This method modifies the passed entry. For a method respecting the allow_inplace_modification property, you should use transform or transform_block instead.
Source code in pybibtexer/bib/bibtexparser/middlewares/middleware.py
transform_explicit_comment ¶
Transform an explicit comment. Called by transform_block if the block is an explicit comment.
Note: This method modifies the passed explicit comment. For a method respecting the allow_inplace_modification property, you should use transform or transform_block instead.
Source code in pybibtexer/bib/bibtexparser/middlewares/middleware.py
transform_implicit_comment ¶
Transform an implicit comment. Called by transform_block if the block is an implicit comment.
Note: This method modifies the passed implicit comment. For a method respecting the allow_inplace_modification property, you should use transform or transform_block instead.
Source code in pybibtexer/bib/bibtexparser/middlewares/middleware.py
transform_preamble ¶
Transform a preamble. Called by transform_block if the block is a preamble.
Note: This method modifies the passed preamble. For a method respecting the allow_inplace_modification property, you should use transform or transform_block instead.
Source code in pybibtexer/bib/bibtexparser/middlewares/middleware.py
transform_string ¶
Transform a string. Called by transform_block if the block is a string.
Note: This method modifies the passed string. For a method respecting the allow_inplace_modification property, you should use transform or transform_block instead.
Source code in pybibtexer/bib/bibtexparser/middlewares/middleware.py
LibraryMiddleware ¶
Bases: Middleware, ABC
Changes an overall library at once (not just on a per-block basis).
Examples of library-wide changes are: - Re-Sorting the blocks in the library. - Transforming the library instance to a custom subclass of Library.
Whatever can be done in a BlockMiddleware, should be done in a BlockMiddleware (and not in a LibraryMiddleware), for performance reasons (e.g. deleting blocks, ...).
Source code in pybibtexer/bib/bibtexparser/middlewares/middleware.py
Functions¶
transform ¶
Transform a library.
:param library: Library to transform. :return: Transformed library. If the library should not be modified, return a copy of the original library. The returned library has to be a new instance, except if self.allow_inplace_modification is True (in which case the library may also return the original library).
Source code in pybibtexer/bib/bibtexparser/middlewares/middleware.py
Middleware ¶
Bases: ABC
Implements a function to transform a block or library.
Abstract Class. You should extend either BlockMiddleware or LibraryMiddleware
Create a new Middleware.
:param allow_inplace_modification: See corresponding property. :param allow_parallel_execution: See corresponding property.
Source code in pybibtexer/bib/bibtexparser/middlewares/middleware.py
Attributes¶
allow_inplace_modification property ¶
If true, the middleware may modify the block in-place.
I.e., if true, the output of transform may be the same instance as the input. If false, new instances must be returned.
allow_parallel_execution property ¶
True indicates that the middleware is threadsafe.
Functions¶
transform abstractmethod ¶
Apply transformation to a library. Main entrypoint of the middleware.