find_work.core.types.breadcrumbs#

Construct a breadcrumb trail.

find_work.core.types.breadcrumbs.is_feedable(value: Annotated[bool, Strict(strict=True)] | Annotated[bytes, Strict(strict=True)] | Annotated[int, Strict(strict=True)] | Annotated[str, Strict(strict=True)] | tuple[Annotated[bool, Strict(strict=True)] | Annotated[bytes, Strict(strict=True)] | Annotated[int, Strict(strict=True)] | Annotated[str, Strict(strict=True)] | None, ...] | None) bool#
find_work.core.types.breadcrumbs.encode_value(value: Annotated[bool, Strict(strict=True)] | Annotated[bytes, Strict(strict=True)] | Annotated[int, Strict(strict=True)] | Annotated[str, Strict(strict=True)] | tuple[Annotated[bool, Strict(strict=True)] | Annotated[bytes, Strict(strict=True)] | Annotated[int, Strict(strict=True)] | Annotated[str, Strict(strict=True)] | None, ...]) bytes#
class find_work.core.types.breadcrumbs.Breadcrumbs#

Bases: BaseModel

Construct a predictable key in a chain-like manner.

The following primitives are stored:

  • Booleans

  • Integer numbers

  • Non-empty strings and bytestrings

  • list, tuple, set, frozenset, deque and generators of everything above

The following primitives are ignored:

  • The None object

  • Empty string and bytestrings

  • Empty collections

Everything other raises error.

>>> key = Breadcrumbs()
>>> key.feed(b"bytes")
True
>>> key.feed("string")
True
>>> key.feed("")
False
>>> key.feed_option("count", 42)
True
>>> key.feed_option("flag", True)
True
>>> key.feed_option("keywords", {"wow", "amazing"})
True
>>> bytes(key)
b'bytes\x00string\x00count:42\x00flag:1\x00keywords:amazing\x19wow\x00'
>>> key.hexdigest()
'45c1f10e9d639892a42c7755e59c3dc8eb5d33b83dd2fe4531e99f02a682c233'
hexdigest() str#

Hash the data with SHA-256 and return its hexadecimal digest.

feed(*args: Annotated[bool, Strict(strict=True)] | Annotated[bytes, Strict(strict=True)] | Annotated[int, Strict(strict=True)] | Annotated[str, Strict(strict=True)] | tuple[Annotated[bool, Strict(strict=True)] | Annotated[bytes, Strict(strict=True)] | Annotated[int, Strict(strict=True)] | Annotated[str, Strict(strict=True)] | None, ...] | None) bool#

Update the key with new data.

This operation is irreversible.

Returns:

whether data was accepted

feed_option(key: str, value: Annotated[bool, Strict(strict=True)] | Annotated[bytes, Strict(strict=True)] | Annotated[int, Strict(strict=True)] | Annotated[str, Strict(strict=True)] | tuple[Annotated[bool, Strict(strict=True)] | Annotated[bytes, Strict(strict=True)] | Annotated[int, Strict(strict=True)] | Annotated[str, Strict(strict=True)] | None, ...] | None) bool#

Update the key with new key-value data.

This operation is irreversible.

Returns:

whether data was accepted

model_config: ClassVar[ConfigDict] = {}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_post_init(context: Any, /) None#

This function is meant to behave like a BaseModel method to initialise private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Args:

self: The BaseModel instance. context: The context.