Typing & semi-public classes

The delb.typing module contains abstract classes that define the interfaces for XML node types, internally used classes and type aliases that can be of interest for re-use in applications and extensions.

Node types

These classes should be used in type annotations and can be used for type tests with isinstance().

abstract class delb.typing.XMLNodeType

Defines the interfaces that all node type representations share. All node type implementations are a subclass of this one.

abstract class delb.typing.ParentNodeType

Defines the interfaces for nodes that can contain further nodes.

abstract class delb.typing.CommentNodeType

Defines the interfaces for delb.nodes.CommentNode.

abstract class delb.typing.ProcessingInstructionNodeType

Defines the interfaces for delb.nodes.ProcessingInstructionNode.

abstract class delb.typing.TagNodeType

Defines the interfaces for delb.nodes.TagNode.

abstract class delb.typing.TextNodeType

Defines the interfaces for delb.nodes.TextNode.

Type aliases

Internally attributes data is handled strictly as:

delb.typing._AttributesData

alias of dict[tuple[str, str], str]

The dictionary’s key type is actually defined as delb.typing.QualifiedName.

Filter functions are defined as:

delb.typing.Filter

alias of Callable[[XMLNodeType], bool]

Parseable input streams are:

delb.typing.InputStream

alias of AnyStr | BinaryIO

Loaders are defined as:

delb.typing.Loader

alias of Callable[[Any, SimpleNamespace], LoaderResult]

The order of loaders is defined with help of:

delb.typing.LoaderConstraint

alias of Loader | Iterable[Loader] | None

Loaders may return a string that explains why it wouldn’t successfully process the given input to the user:

delb.typing.LoaderResult

alias of Sequence[XMLNodeType] | str

Protocols

XML parser adapters must be able to process that they fetch from a binary stream reader’s read method:

class delb.typing.BinaryReader(*args, **kwargs)[source]
close()[source]
read(n: int = -1) bytes[source]

Semi-public classes

Namespace to prefix mappings are formalized as:

delb.typing.NamespaceDeclarations

alias of Mapping[str | None, str]

Methods that add nodes to a tree take a variety of input data:

delb.typing.NodeSource

alias of str | XMLNodeType | _TagDefinition

XML names are simply kept as tuple of namespace and local name:

delb.typing.QualifiedName

alias of tuple[str, str]

Definitions that are used for convenient tree building are held in:

class _delb.nodes._TagDefinition(local_name: str, attributes: dict[AttributeAccessor, str] | None = None, children: tuple[NodeSource, ...] = ())[source]

Instances of this class describe tag nodes that are constructed from the context they are used in (commonly additions to a tree) and the properties that this description holds. For the sake of slick code they are not instantiated directly, but with the delb.tag() function.

attributes: dict[AttributeAccessor, str] | None
children: tuple[NodeSource, ...]
local_name: str