blackfennec.structure package

Subpackages

Submodules

blackfennec.structure.boolean module

class blackfennec.structure.boolean.Boolean(value: bool = False)[source]

Bases: ValueStructure[bool]

Core Type Boolean, represents booleans in the domain model.

accept(visitor: Visitor[TVisitor]) TVisitor[source]

blackfennec.structure.list module

class blackfennec.structure.list.List(value: Optional[list[T]] = None)[source]

Bases: Structure[list[T]]

Core type List, a list of Structures

accept(visitor: Visitor[TVisitor]) TVisitor[source]
add_item(item: T) None[source]

Append item to list.

Parameters

item (Structure) – Item to append.

remove_item(item: T) None[source]

Remove item from List.

Parameters

item (Structure) – Item to remove.

Raises

KeyError – If the item passed is not in list and hence cannot be removed.

replace_item(old_item: T, new_item: T) None[source]

Replace old_item with new_item.

Parameters
  • old_item (Structure) – Item to be replaced.

  • new_item (Structure) – Item to replace with.

Raises

KeyError – If old_item is not in list.

property value: list[T]

Property for value of this structure.

blackfennec.structure.map module

class blackfennec.structure.map.Map(value: Optional[dict[str, T]] = None)[source]

Bases: Structure[dict[str, T]]

Core type Map, a set of keys with values

accept(visitor: Visitor[TVisitor]) TVisitor[source]
add_item(key: str, value: T) None[source]

Custom set item hook, adds self as parent or raises error.

Parameters
  • key (str) – The key for the inserted item.

  • value (Structure) – The item which will be inserted.

Raises

ValueError – If the key already exists

remove_item(key: str) None[source]

Custom delete hook, resets parent for removed structure.

Parameters

key (any) – The key of the item to delete.

Raises

KeyError – If the item with the key to delete is not contained in map.

rename_key(old_key: str, new_key: str) None[source]
replace_item(key: str, new_value: T) None[source]
property value: dict[str, T]

Property for value of this structure.

blackfennec.structure.null module

class blackfennec.structure.null.Null[source]

Bases: Structure[None]

Core Type Null, represents null values in the domain model.

accept(visitor: Visitor[TVisitor]) TVisitor[source]
property value: None

Property for value of this structure.

blackfennec.structure.number module

class blackfennec.structure.number.Number(value: int | float = 0)[source]

Bases: ValueStructure[int | float]

Core Type Number, represents numbers in the domain model.

accept(visitor: Visitor[TVisitor]) TVisitor[source]

blackfennec.structure.reference module

class blackfennec.structure.reference.Reference(navigators: list[blackfennec.structure.reference_navigation.navigator.Navigator])[source]

Bases: Structure[list[Navigator]]

Core Type Reference, represents references in the domain model.

TYPE = None
accept(visitor: Visitor[TVisitor]) TVisitor[source]
resolve() Structure[source]

Resolves Reference navigation

Returns

destination to which the reference_navigation points

Return type

Structure

property value: list[blackfennec.structure.reference_navigation.navigator.Navigator]

Property for value of this structure.

blackfennec.structure.string module

class blackfennec.structure.string.String(value: str = '')[source]

Bases: ValueStructure[str]

Core Type String, represents strings in the domain model.

accept(visitor: Visitor[TVisitor]) TVisitor[source]

blackfennec.structure.structure module

class blackfennec.structure.structure.Structure[source]

Bases: Observable, Generic[T]

Abstract base class for all types (Structures).

abstract accept(visitor: Visitor[TVisitor]) TVisitor[source]
property parent: Optional[Structure]

Property for parent of this structure.

property root: Optional[Structure]

Readonly property for Root of this structure.

property structure
abstract property value: T

Property for value of this structure.

class blackfennec.structure.structure.ValueStructure(value: T)[source]

Bases: Structure[T]

Abstract base class for all structures that have a value.

property value: T

Property for value of this structure.

blackfennec.structure.structure_serializer module

class blackfennec.structure.structure_serializer.StructureSerializer(reference_serializer: JsonReferenceSerializer)[source]

Bases: object

Serializer allows black-fennec structures to be serialized to native Python datatypes and vice versa

deserialize(raw: Optional[Union[dict, list, str, bool, Number]]) Structure[source]

Checks if object is an instance of a specific type and returns the parsed black-fennec structure

Parameters

raw (Union[dict, list, str, bool, numbers.Number, None]) – native Python datatype

Returns

Subclass of Structure

Return type

Structure

Raises

NotImplementedError – If the type contained in the passed native Python datatype is unhandled.

serialize(structure: Structure) Optional[Union[dict, list, str, bool, Number]][source]

Serializes a black-fennec structure to a native Python datatype

Parameters

structure (Structure) – A black-fennec structure

Returns

A native Python datatype

Return type

Union[dict, list, str, bool, numbers.Number, None]

Raises

NotImplementedError – If the type contained in the passed Structure is unhandled

blackfennec.structure.visitor module

class blackfennec.structure.visitor.Visitor[source]

Bases: Generic[T]

Base class for all visitors as defined by the visitor pattern.

This class is generic in T, the return type of the visit_* methods.

visit_boolean(subject: Boolean) T[source]
visit_list(subject: List) T[source]
visit_map(subject: Map) T[source]
visit_null(subject: Null)[source]
visit_number(subject: Number) T[source]
visit_reference(subject: Reference) T[source]
visit_string(subject: String) T[source]
visit_structure(subject: Structure) T[source]

Module contents