accessories

Accessory functions.

TRACE = 5

Custom TRACE log level, below DEBUG (10).

encoding_from_lang(lang)[source]

Parse encoding from LANG environment value.

Returns the encoding portion if present, or None if the LANG value does not contain an encoding suffix (no ‘.’ separator).

Parameters:

lang (str) – LANG environment value (e.g., ‘en_US.UTF-8@misc’)

Return type:

Optional[str]

Returns:

Encoding string (e.g., ‘UTF-8’) or None if no encoding found.

Example:

>>> encoding_from_lang('en_US.UTF-8@misc')
'UTF-8'
>>> encoding_from_lang('en_IL')
None
name_unicode(ucs)[source]

Return 7-bit ascii printable of any string.

Return type:

str

eightbits(number)[source]

Binary representation of number padded to 8 bits.

Example:

>>> eightbits(ord('a'))
'0b01100001'
Return type:

str

hexdump(data, prefix='')[source]

Format data as hexdump -C style output.

Each 16-byte row shows the offset, hex bytes grouped 8+8, and printable ASCII on the right:

00000000  48 65 6c 6c 6f 20 57 6f  72 6c 64 0d 0a         |Hello World..|
Parameters:
  • data (bytes) – Raw bytes to format.

  • prefix (str) – String prepended to every line (e.g. ">>  ").

Return type:

str

make_logger(name, loglevel='info', logfile=None, logfmt='%(levelname)s %(filename)s:%(lineno)d %(message)s', filemode='a')[source]

Create and return simple logger for given arguments.

Return type:

Logger

repr_mapping(mapping)[source]

Return printable string, ‘key=value [key=value …]’ for mapping.

Return type:

str

function_lookup(pymod_path)[source]

Return callable function target from standard module.function path.

Return type:

Callable[..., Any]

make_reader_task(reader, size=4096)[source]

Return asyncio task wrapping coroutine of reader.read(size).

Return type:

Task[Any]