bibble._interface

Type Aliases

StringBlock

Enums

Capability_f

A Flag for where middlewares can be in the read/write stack

Protocols

AdaptiveMiddleware_p

Middleware that looks up defined transforms using the type name, by mro.

BidirectionalMiddleware_p

A Single middleware that holds the logic for reading and writing,

BlockMiddleware_p

A (non-adaptive) block middleware has 'transform_x' methods

CustomWriteBlock_p

Writers can be Visitors, in which case they call ths visit method on

DependentMiddleware_p

For middlewares that depend on a middleware to be able to work themselves.

EntrySkipper_p

A whitelist based test for middlewares.

FieldMatcher_p

The protocol util.FieldMatcher_m relies on

Library_p

The core methods of a library

Middleware_p

A Middleware is something with a 'transform' method

PairStack_p

Protocol for both storing both read and write middlewares

ReadTime_p

Protocol for signifying a middleware is for use on parsing bibtex to

Reader_p

Readers take source text, or a file, or a directory,

StrTransformer_p

Describes the StringTransform_m

WriteTime_p

Protocol for signifying middleware is for use on writing data to bibtex

Writer_p

Writers take a library, format it, and write it to a file.

Module Contents

bibble._interface.StringBlock: TypeAlias = model.String
class bibble._interface.Capability_f(*args, **kwds)[source]

Bases: enum.Flag

A Flag for where middlewares can be in the read/write stack

dependent
insist_end
insist_front
read_time
report
transform
validate
write_time
class bibble._interface.AdaptiveMiddleware_p[source]

Bases: Protocol

Middleware that looks up defined transforms using the type name, by mro. The form for method lookup is either: - transform_{type(block).__class__} - {direction}_transform_{type(block).__class__}

An adaptive middleware doesn’t need all the ‘transform_X’ methods a BlockMiddleware_p does.

get_transforms_for(
block,
*,
direction=None,
) <Unknown>[source]
Parameters:
  • block (Block)

  • direction (jgdv.Maybe[str])

Return type:

list[collections.abc.Callable[[Block, Library_p], list[Block]]]

class bibble._interface.BidirectionalMiddleware_p[source]

Bases: Protocol

A Single middleware that holds the logic for reading and writing, Intended for undoing what is done on read, prior to writing.

eg: Latex Decoding, then Encoding

read_transform(library) <Unknown>[source]
Parameters:

library (Library_p)

Return type:

Library_p

write_transform(library) <Unknown>[source]
Parameters:

library (Library_p)

Return type:

Library_p

class bibble._interface.BlockMiddleware_p[source]

Bases: Protocol

A (non-adaptive) block middleware has ‘transform_x’ methods

transform(library) <Unknown>[source]
Parameters:

library (Library_p)

Return type:

Library_p

transform_block(block, library) <Unknown>[source]
Parameters:
Return type:

list[Block]

transform_entry(entry, library) <Unknown>[source]
Parameters:
Return type:

list[Block]

transform_explicit_comment(
comment,
library,
) <Unknown>[source]
Parameters:
  • comment (bibtexparser.model.ExplicitComment)

  • library (Library_p)

Return type:

list[Block]

transform_implicit_comment(
comment,
library,
) <Unknown>[source]
Parameters:
  • comment (bibtexparser.model.ImplicitComment)

  • library (Library_p)

Return type:

list[Block]

transform_preamble(preamble, library) <Unknown>[source]
Parameters:
  • preamble (bibtexparser.model.Preamble)

  • library (Library_p)

Return type:

list[Block]

transform_string(string, library) <Unknown>[source]
Parameters:
  • string (bibtexparser.model.StringBlock)

  • library (Library_p)

Return type:

list[Block]

class bibble._interface.CustomWriteBlock_p[source]

Bases: Protocol

Writers can be Visitors, in which case they call ths visit method on blocks

visit(writer) <Unknown>[source]
Parameters:

writer (Writer_p)

Return type:

list[str]

class bibble._interface.DependentMiddleware_p[source]

Bases: Protocol

For middlewares that depend on a middleware to be able to work themselves.

eg: metadata applicator requires path reader

requires_in_parse_stack() <Unknown>[source]
Return type:

list[type]

requires_in_same_stack() <Unknown>[source]
Return type:

list[type]

class bibble._interface.EntrySkipper_p[source]

Bases: Protocol

A whitelist based test for middlewares. Middleware’s set their skiplist on init, and can call ‘should_skip_entry’ when transforming blocks

eg: for only processing type=’article’ entries, not books

set_entry_skiplist(whitelist) <Unknown>[source]
Parameters:

whitelist (list[str])

Return type:

None

should_skip_entry(entry, library) <Unknown>[source]
Parameters:
  • entry (Entry)

  • library (bibtexparser.library.Library)

Return type:

bool

class bibble._interface.FieldMatcher_p[source]

Bases: Protocol

The protocol util.FieldMatcher_m relies on

A Middleware with the FieldMatcher_m mixin will call the implemented field_h on each field that matches in an entry.

field_h(field, entry) <Unknown>[source]
Parameters:
  • field (Field)

  • entry (Entry)

Return type:

jgdv.Result[list[Field], Exception]

match_on_fields(entry, library) <Unknown>[source]
Parameters:
  • entry (Entry)

  • library (bibtexparser.library.Library)

Return type:

jgdv.Result[Entry, Exception]

set_field_matchers(*, white, black) <Unknown>[source]
Parameters:
Return type:

Self

class bibble._interface.Library_p[source]

Bases: Protocol

The core methods of a library

add(
blocks,
fail_on_duplicate_key=False,
) <Unknown>[source]
Parameters:
  • blocks (list[Block])

  • fail_on_duplicate_key (bool)

Return type:

None

blocks() <Unknown>[source]
Return type:

list[Block]

comments() <Unknown>[source]
Return type:

list[CommentBlock]

entries() <Unknown>[source]
Return type:

list[Entry]

entries_dict() <Unknown>[source]
Return type:

dict[str, Entry]

failed_blocks() <Unknown>[source]
Return type:

list[FailedBlock]

preambles() <Unknown>[source]
Return type:

list[Preamble]

remove(blocks) <Unknown>[source]
Parameters:

blocks (list[Block])

Return type:

None

replace(
old_block,
new_block,
fail_on_duplicate_key=True,
) <Unknown>[source]
Parameters:
  • old_block (Block)

  • new_block (Block)

  • fail_on_duplicate_key (bool)

Return type:

None

strings() <Unknown>[source]
Return type:

list[StringBlock]

strings_dict() <Unknown>[source]
Return type:

dict[str, StringBlock]

class bibble._interface.Middleware_p[source]

Bases: Protocol

A Middleware is something with a ‘transform’ method

transform(library) <Unknown>[source]
Parameters:

library (Library_p)

Return type:

Library_p

class bibble._interface.PairStack_p[source]

Bases: Protocol

Protocol for both storing both read and write middlewares

add(*args, read=None, write=None) <Unknown>[source]
Parameters:
  • args (BidiMiddleware)

  • read (jgdv.Maybe[list | Middleware])

  • write (jgdv.Maybe[list | Middleware])

Return type:

Self

read_stack() <Unknown>[source]
Return type:

list[Middleware]

write_stack() <Unknown>[source]
Return type:

list[Middleware]

class bibble._interface.ReadTime_p[source]

Bases: Protocol

Protocol for signifying a middleware is for use on parsing bibtex to data

on_read() <Unknown>[source]
Return type:

Never

class bibble._interface.Reader_p[source]

Bases: Protocol

Readers take source text, or a file, or a directory, parses the read bibtex, running middlewares on the parsed bibtex

read(
source,
*,
into=None,
append=None,
) <Unknown>[source]
Parameters:
  • source (str | pathlib.Path)

  • into (jgdv.Maybe[bibtexparser.library.Library])

  • append (jgdv.Maybe[list[Middleware]])

Return type:

jgdv.Maybe[bibtexparser.library.Library]

read_dir(
source,
*,
ext,
into=None,
append=None,
) <Unknown>[source]
Parameters:
  • source (pathlib.Path)

  • ext (str)

  • into (jgdv.Maybe[bibtexparser.library.Library])

  • append (jgdv.Maybe[list[Middleware]])

Return type:

jgdv.Maybe[bibtexparser.library.Library]

class bibble._interface.StrTransformer_p[source]

Bases: Protocol

Describes the StringTransform_m

_transform_raw_str(python_string) <Unknown>[source]
Parameters:

python_string (str)

Return type:

jgdv.Result[str, Exception]

transform_strlike(slike) <Unknown>[source]
Parameters:

slike (StrLike)

Return type:

jgdv.Result[StrLike, Exception]

class bibble._interface.WriteTime_p[source]

Bases: Protocol

Protocol for signifying middleware is for use on writing data to bibtex

on_write() <Unknown>[source]
Return type:

Never

class bibble._interface.Writer_p[source]

Bases: Protocol

Writers take a library, format it, and write it to a file. typically it formats as bibtex, but doesn’t have to. (eg: RstWriter)

write(
library,
*,
file=None,
append=None,
) <Unknown>[source]
Parameters:
  • library (bibtexparser.library.Library)

  • file (jgdv.Maybe[pathlib.Path])

  • append (jgdv.Maybe[list[Middleware]])

Return type:

str