Skip to content

blackbull.utils

blackbull.utils

Shared utilities and enumerations.

Provides:

  • Scheme: StrEnum with http and websocket values used throughout routing.
  • check_port: returns True when a host/port is not yet in use.
  • pop_safe: moves a key between dicts with an optional rename, no-op when absent.
  • parse_post_data: parses application/x-www-form-urlencoded bodies.
  • EventEmitter: lightweight async event-emitter backed by asyncio.create_task.

EventEmitter

Lightweight async event-emitter backed by asyncio.create_task.

Experimental

This class is under active development and its API is not yet stable. Do not use in production code — method signatures and behaviour may change without notice.

Listeners registered with on are called every time the event fires. Listeners registered with once are called exactly once, then removed.

on(event, listener)

Register a lister to this class. This listener will be called unless removed.

once(event, listener)

Register a lister to this class.

serializable

Bases: ABC

Abstract base for serializable classes. Subclasses must implement save() and load().

check_port(host='localhost', port=None)

Returns True: Port is not used. Returns False: Port is used.

pop_safe(key, source, target, *, new_key=None)

Move source[key] into target (under new_key if given), if present.

Returns target unchanged when key is absent from source.