Skip to content

blackbull.asgi

blackbull.asgi

ASGI protocol types: event-type string constants and typed event wrappers.

Two responsibilities, both framework-side:

  • ASGIEvent: namespace of ASGI 3.0 event-type strings, used for match/case dispatch and equality checks across both the framework and (importing from here) the server stack.
  • ResponseStart / ResponseBody: dict-subclass wrappers for the two outgoing response event shapes so middleware can dispatch on Python type rather than string comparison. Both subclass dict so isinstance(e, dict) remains True — required for beartype and any ASGI send callable annotated event: dict.

ASGIEvent

Namespace for ASGI protocol event type strings (ASGI 3.0 spec).

ResponseBody

Bases: dict

http.response.body event with typed property access.

ResponseStart

Bases: dict

http.response.start event with typed property access.

parse_response_event(event)

Wrap event in the appropriate typed subclass for dispatch.

The returned object IS the event dict (shallow copy) — pass it directly to downstream send callables without re-serialisation. Trailers and unknown event types are returned unchanged.