fleche.digest

Attributes

logger

DIGEST_LENGTH

T

_HOOKS

_EP_HOOKS

_TYPES_WITHOUT_DIGEST

Exceptions

Unhashable

Exception raised when an object cannot be digested.

Classes

Digest

str(object='') -> str

Hook

Functions

get_hooks()

add_hook(hook)

load_entry_points()

_digest_mapping(→ bytes)

digest(→ Digest)

_digest_bytes(→ bytes)

Returns bytes representing the SHA-256 digest of value.

Module Contents

fleche.digest.logger[source]
exception fleche.digest.Unhashable[source]

Bases: Exception

Exception raised when an object cannot be digested.

class fleche.digest.Digest[source]

Bases: str

str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.

expand(cache=None) Digest[source]

Expand a short digest prefix to its full-length digest using the cache.

Parameters:

cache – A cache instance to use. If None, uses the current context’s cache.

Returns:

The full-length Digest.

shrink(cache=None) Digest[source]

Shrink a digest to its shortest unambiguous prefix using the cache.

Parameters:

cache – A cache instance to use. If None, uses the current context’s cache.

Returns:

The shortest unambiguous Digest prefix.

fleche.digest.DIGEST_LENGTH = 64[source]
fleche.digest.T[source]
class fleche.digest.Hook[source]

Bases: Generic[T]

type: T[source]
digest: Callable[[T], str | Digest][source]
fleche.digest._HOOKS = [][source]
fleche.digest._EP_HOOKS = [][source]
fleche.digest._TYPES_WITHOUT_DIGEST: set[type][source]
fleche.digest.get_hooks()[source]
fleche.digest.add_hook(hook: Hook | tuple[Type[T], Callable[[T], str]])[source]
fleche.digest.load_entry_points()[source]
fleche.digest._digest_mapping(m, contents: collections.abc.Mapping) bytes[source]
fleche.digest.digest(value: Any) Digest[source]
fleche.digest._digest_bytes(value: Any) bytes[source]

Returns bytes representing the SHA-256 digest of value.

All recursive call sites pass the result directly to m.update().

Wire-format note: currently returns m.hexdigest().encode() (64 UTF-8 hex bytes) so the bytes fed into parent hashes are identical to the previous digest(v).encode() calls — no backwards-incompatible change. To gain the raw-bytes speedup (Issue #440), change only the final return here to m.digest() (32 bytes), update digest() to call .hex() instead of .decode(), and change the encode() calls on the early-return paths (Digest pass-through, hooks, __digest__) to bytes.fromhex(...). That must be coordinated with a hash_version bump and a Cache.redigest migration.