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(→ Digest)

_digest(→ Digest)

Generates a SHA256 digest for a given Python object.

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(value: Any) Digest[source]
fleche.digest._digest(value: Any) Digest[source]

Generates a SHA256 digest for a given Python object.

This function handles various types including strings, bytes, integers, floats, booleans, None, dictionaries, numpy arrays, dataclasses, and iterables. If an unhashable type is encountered, an Unhashable exception is raised.

Parameters:

value (Any) – The object to be digested.

Returns:

The SHA256 hexdigest of the object.

Return type:

str

Raises:

Unhashable – If the provided value cannot be digested.