Skip to content

StoreType Enum

Bases: Enum

Source code in magic_storage/_store_type.py
class StoreType(Enum):
    # basic storage type
    TEXT = TEXT_BIT
    BINARY = BYTES_BIT
    # complex storage type
    JSON = (
        TEXT_BIT
        | SUPPORT_LIST_BIT
        | SUPPORT_TUPLE_BIT
        | SUPPORT_DICT_BIT
        | SUPPORT_STR_BIT
        | JSON_BIT
    )
    PICKLE = BYTES_BIT | SUPPORT_ANY_BIT | PICKLE_BIT

    def __str__(self) -> str:
        return self.name

    def __repr__(self) -> str:
        return f"{self.name}:{self.value:>08b}"

    def is_text(self) -> bool:
        return bool(self.value & TEXT_BIT)

    def is_binary(self) -> bool:  # pragma: no cover
        return bool(self.value & BYTES_BIT)

    @classmethod
    def iter_text(cls) -> Iterable[StoreType]:
        return filter(lambda e: e.is_text(), cls)

    @classmethod
    def iter_binary(cls) -> Iterable[StoreType]:  # pragma: no cover
        return filter(lambda e: e.is_binary(), cls)

Last update: August 5, 2022
Created: August 5, 2022