bagofholding.content module

Content controls the decomposition of python objects into their component parts, along with a record of what type of object they are, and gathering any relevant metadata.

Content is not, of itself, concerned with what you _do_ with this decompositon. That is handled via the “packer” protocol (for us, the relevant implementation of this is “bags”).

class bagofholding.content.BespokeItem[source]

Bases: ReflexiveItem[ItemType, PackerType], Generic[ItemType, PackerType], ABC

class bagofholding.content.Bool[source]

Bases: BuiltinItem[bool]

classmethod unpack(packer: Packer, path: str, unpacking: UnpackingArguments) bool[source]
class bagofholding.content.BuiltinGroup[source]

Bases: ReflexiveGroup[BuiltinGroupType], Generic[BuiltinGroupType], ABC

classmethod pack(obj: PackingType, packer: Packer, path: str, packing: PackingArguments) None[source]
class bagofholding.content.BuiltinItem[source]

Bases: ReflexiveItem[BuiltinItemType, Packer], Generic[BuiltinItemType], ABC

class bagofholding.content.Bytearray[source]

Bases: BuiltinItem[bytearray]

classmethod unpack(packer: Packer, path: str, unpacking: UnpackingArguments) bytearray[source]
class bagofholding.content.Bytes[source]

Bases: BuiltinItem[bytes]

classmethod unpack(packer: Packer, path: str, unpacking: UnpackingArguments) bytes[source]
class bagofholding.content.Complex[source]

Bases: BuiltinItem[complex]

classmethod unpack(packer: Packer, path: str, unpacking: UnpackingArguments) complex[source]
class bagofholding.content.Content[source]

Bases: Generic[PackingType, UnpackingType, PackerType], ABC

classmethod full_name() str[source]
abstractmethod classmethod pack(obj: PackingType, packer: PackerType, path: str, packing: PackingArguments) None[source]
abstractmethod classmethod unpack(packer: PackerType, path: str, unpacking: UnpackingArguments) UnpackingType[source]
class bagofholding.content.Dict[source]

Bases: BuiltinGroup[dict[Any, Any]]

classmethod unpack(packer: Packer, path: str, unpacking: UnpackingArguments) dict[Any, Any][source]
class bagofholding.content.Float[source]

Bases: BuiltinItem[float]

classmethod unpack(packer: Packer, path: str, unpacking: UnpackingArguments) float[source]
class bagofholding.content.FrozenSet[source]

Bases: Indexable[frozenset[Any]]

recast

alias of frozenset

class bagofholding.content.Global[source]

Bases: Item[type[type] | LambdaType | str, Any, Packer]

classmethod unpack(packer: Packer, path: str, unpacking: UnpackingArguments) Any[source]
class bagofholding.content.Group[source]

Bases: Content[PackingType, UnpackingType, Packer], Generic[PackingType, UnpackingType], ABC

class bagofholding.content.HasContents(*args, **kwargs)[source]

Bases: Sized, Iterable[str], Protocol

class bagofholding.content.Indexable[source]

Bases: BuiltinGroup[IndexableType], Generic[IndexableType], ABC

recast: type[IndexableType]
classmethod unpack(packer: Packer, path: str, unpacking: UnpackingArguments) IndexableType[source]
class bagofholding.content.Item[source]

Bases: Content[PackingType, UnpackingType, PackerType], Generic[PackingType, UnpackingType, PackerType], ABC

classmethod pack(obj: PackingType, packer: PackerType, path: str, packing: PackingArguments) None[source]
class bagofholding.content.List[source]

Bases: Indexable[list[Any]]

recast

alias of list

class bagofholding.content.Long[source]

Bases: BuiltinItem[int]

classmethod unpack(packer: Packer, path: str, unpacking: UnpackingArguments) int[source]
class bagofholding.content.NoneItem[source]

Bases: Item[type[None], None, Packer]

classmethod unpack(packer: Packer, path: str, unpacking: UnpackingArguments) None[source]
class bagofholding.content.NotData[source]

Bases: object

class bagofholding.content.Packer(*args, **kwargs)[source]

Bases: Protocol

create_group(path: str) None[source]
get_bespoke_content_class(obj: object) type[BespokeItem[Any, Self]] | None[source]
join(*paths: str) str[source]
open_group(path: str) HasContents[source]
pack_bool(obj: bool, path: str) None[source]
pack_bytearray(obj: bytearray, path: str) None[source]
pack_bytes(obj: bytes, path: str) None[source]
pack_complex(obj: complex, path: str) None[source]
pack_empty(path: str) None[source]
pack_float(obj: float, path: str) None[source]
pack_long(obj: int, path: str) None[source]
pack_metadata(metadata: Metadata, path: str) None[source]
pack_string(obj: str, path: str) None[source]
unpack_bool(path: str) bool[source]
unpack_bytearray(path: str) bytearray[source]
unpack_bytes(path: str) bytes[source]
unpack_complex(path: str) complex[source]
unpack_float(path: str) float[source]
unpack_long(path: str) int[source]
unpack_metadata(path: str) Metadata[source]
unpack_string(path: str) str[source]
class bagofholding.content.PackingArguments(memo: 'PackingMemoAlias', references: 'ReferencesAlias', require_versions: 'bool', forbidden_modules: 'list[str] | tuple[str, ...]', version_scraping: 'VersionScrapingMap | None', _pickle_protocol: 'SupportsIndex')[source]

Bases: object

forbidden_modules: list[str] | tuple[str, ...]
memo: bidict[int, str]
references: list[object]
require_versions: bool
version_scraping: dict[str, Callable[[str], str | None]] | None
class bagofholding.content.Reducible[source]

Bases: ReflexiveGroup[object]

classmethod pack(obj: object, packer: Packer, path: str, packing: PackingArguments, rv: tuple[Callable[[...], object], tuple[object, ...]] | tuple[Callable[[...], object], tuple[object, ...], object | None] | tuple[Callable[[...], object], tuple[object, ...], object | None, Iterator[object] | None] | tuple[Callable[[...], object], tuple[object, ...], object | None, Iterator[object] | None, Iterator[tuple[object, object]] | None] | tuple[Callable[[...], object] | None, tuple[object, ...] | None, object | None, Iterator[object] | None, Iterator[tuple[object, object]] | None, Callable[[object, object], None] | None] | None = None) None[source]
reduction_fields: ClassVar[tuple[str, str, str, str, str, str]] = ('constructor', 'args', 'state', 'item_iterator', 'kv_iterator', 'setter')
classmethod unpack(packer: Packer, path: str, unpacking: UnpackingArguments) object[source]
class bagofholding.content.Reference[source]

Bases: Item[str, Any, Packer]

classmethod unpack(packer: Packer, path: str, unpacking: UnpackingArguments) Any[source]
class bagofholding.content.ReflexiveGroup[source]

Bases: Group[GroupType, GroupType], Generic[GroupType], ABC

class bagofholding.content.ReflexiveItem[source]

Bases: Item[ItemType, ItemType, PackerType], Generic[ItemType, PackerType], ABC

class bagofholding.content.Set[source]

Bases: Indexable[set[Any]]

recast

alias of set

class bagofholding.content.Str[source]

Bases: BuiltinItem[str]

classmethod unpack(packer: Packer, path: str, unpacking: UnpackingArguments) str[source]
class bagofholding.content.StrKeyDict[source]

Bases: BuiltinGroup[dict[str, Any]]

classmethod unpack(packer: Packer, path: str, unpacking: UnpackingArguments) dict[str, Any][source]
class bagofholding.content.Tuple[source]

Bases: Indexable[tuple[Any, …]]

recast

alias of tuple

class bagofholding.content.Union[source]

Bases: BuiltinGroup[Union]

types.UnionType has no __reduce__() method. Pickle actually gets around this with bespoke logic, and so we need to too.

classmethod unpack(packer: Packer, path: str, unpacking: UnpackingArguments) Union[source]
class bagofholding.content.UnpackingArguments(memo: 'UnpackingMemoAlias', version_validator: 'VersionValidatorType', version_scraping: 'VersionScrapingMap | None')[source]

Bases: object

memo: dict[str, Any]
version_scraping: dict[str, Callable[[str], str | None]] | None
version_validator: Literal['exact', 'semantic-minor', 'semantic-major', 'none'] | Callable[[str, str], bool]
bagofholding.content.get_group_content_class(obj: object) type[Group[Any, Any]] | None[source]
bagofholding.content.has_surrogates(s: str) bool[source]
bagofholding.content.is_simple_string(string: str) bool[source]
bagofholding.content.pack(obj: object, packer: Packer, path: str, memo: bidict[int, str], references: list[object], require_versions: bool, forbidden_modules: list[str] | tuple[str, ...], version_scraping: dict[str, Callable[[str], str | None]] | None, _pickle_protocol: SupportsIndex = 4) None[source]
bagofholding.content.unpack(packer: Packer, path: str, memo: dict[str, Any], version_validator: Literal['exact', 'semantic-minor', 'semantic-major', 'none'] | Callable[[str, str], bool], version_scraping: dict[str, Callable[[str], str | None]] | None) object[source]