bsfs.utils package#

class bsfs.utils.UCID#

Bases: object

Generate 256-bit content IDs.

Effectively computes a cryptographic hash over the content.

static from_buffer(buffer: IOBase) str#

Read the content from a buffer.

static from_bytes(content: bytes) str#

Get the content from as bytes.

static from_dict(content: dict) str#

Get the content from a dict.

static from_path(path: str) str#

Read the content from a file.

class bsfs.utils.URI(value: str)#

Bases: str

URI additions to built-in strings.

Provides properties to access the different components of an URI, according to RFC 3986 (https://datatracker.ietf.org/doc/html/rfc3986).

Note that this class does not actually validate an URI but only offers access to components of a well-formed URI. Use urllib.parse for more advanced purposes.

property authority: str#

Return the authority part of the URI, including userinfo and port.

static compose(path: str, scheme: str | None = None, authority: str | None = None, user: str | None = None, host: str | None = None, port: int | None = None, query: str | None = None, fragment: str | None = None)#

URI composition from components.

If the host argument is supplied, the authority is composed of user, host, and port arguments, and the authority argument is ignored. Note that if the host is an IPv6 address, it must be enclosed in brackets.

property fragment: str#

Return the fragment part of the URI.

get(component: str, default: Any | None = None) Any | None#

Return the component or a default value.

property host: str#

Return the host part of the URI.

static is_parseable(query: str) bool#

Return True if the query can be decomposed into the URI components.

Note that a valid URI is always parseable, however, an invalid URI might be parseable as well. The return value of this method makes no claim about the validity of an URI!

join(*args) URI#

Concatenate any number of strings.

The string whose method is called is inserted in between each given string. The result is returned as a new string.

Example: ‘.’.join([‘ab’, ‘pq’, ‘rs’]) -> ‘ab.pq.rs’

lower(*args) URI#

Return a copy of the string converted to lowercase.

lstrip(*args) URI#

Return a copy of the string with leading whitespace removed.

If chars is given and not None, remove characters in chars instead.

property path: str#

Return the path part of the URI.

property port: int#

Return the port part of the URI.

property query: str#

Return the query part of the URI.

replace(*args) URI#

Return a copy with all occurrences of substring old replaced by new.

count

Maximum number of occurrences to replace. -1 (the default value) means replace all occurrences.

If the optional argument count is given, only the first count occurrences are replaced.

rstrip(*args) URI#

Return a copy of the string with trailing whitespace removed.

If chars is given and not None, remove characters in chars instead.

property scheme: str#

Return the protocol/scheme part of the URI.

strip(*args) URI#

Return a copy of the string with leading and trailing whitespace removed.

If chars is given and not None, remove characters in chars instead.

upper(*args) URI#

Return a copy of the string converted to uppercase.

property userinfo: str#

Return the userinfo part of the URI.

class bsfs.utils.UUID(seed: int | None = None)#

Bases: Iterator, Callable

Generate 256-bit universally unique IDs.

This is a ‘best-effort’ kind of implementation that tries to ensure global uniqueness, even tough actual uniqueness cannot be guaranteed. The approach is different from python’s uuid module (which implements RFC 4122) in that it generates longer UUIDs and in that it cannot be reconstructed whether two UUIDs were generated on the same system.

The ID is a cryptographic hash over several components: * host * system * process * thread * random * time * cpu cycles * content (if available)

host: str#
process: str#
system: str#
thread: str#
bsfs.utils.normalize_args(*args: ArgType | Iterable[ArgType] | Iterator[ArgType]) Tuple[ArgType, ...]#

Arguments to a function can be passed as individual arguments, list-like structures, or iterables. This function processes any of these styles and returns a tuple of the respective items. Typically used within a function provide a flexible interface but sill have parameters in a normalized form.

Examples:

>>> normalize_args(0,1,2)
(1,2,3)
>>> normalize_args([0,1,2])
(1,2,3)
>>> normalize_args(range(3))
(1,2,3)
bsfs.utils.typename(obj) str#

Return the type name of obj.

Submodules#