Coverage for src/lexigram/web/hooks.py: 100%

15 statements  

« prev     ^ index     » next       coverage.py v7.15.4, created at 2026-08-25 04:37 +0800

1"""Root hook payload surface for lexigram-web. 

2 

3Defines canonical payload dataclasses for web-related hook points. Actual 

4hook registration and invocation use the framework's string-keyed 

5``HookRegistryProtocol`` action/filter APIs. 

6""" 

7 

8from __future__ import annotations 

9 

10from dataclasses import dataclass 

11 

12__all__ = [ 

13 "WebRequestReceivedHook", 

14 "WebResponsePreparedHook", 

15 "WebServerStartedHook", 

16 "WebServerStoppedHook", 

17] 

18 

19 

20@dataclass(frozen=True, kw_only=True) 

21class WebRequestReceivedHook: 

22 """Payload fired when the ASGI server receives an incoming HTTP request. 

23 

24 Attributes: 

25 path: URL path of the incoming request (e.g. ``"/api/users"``). 

26 method: HTTP verb in upper-case (e.g. ``"GET"``). 

27 """ 

28 

29 path: str 

30 method: str 

31 

32 

33@dataclass(frozen=True, kw_only=True) 

34class WebResponsePreparedHook: 

35 """Payload fired once a response has been assembled, before it is sent. 

36 

37 Attributes: 

38 path: URL path the response belongs to. 

39 status_code: HTTP status code of the prepared response. 

40 """ 

41 

42 path: str 

43 status_code: int 

44 

45 

46@dataclass(frozen=True, kw_only=True) 

47class WebServerStartedHook: 

48 """Payload fired after the ASGI lifespan ``startup`` phase completes.""" 

49 

50 

51@dataclass(frozen=True, kw_only=True) 

52class WebServerStoppedHook: 

53 """Payload fired after an orderly ASGI lifespan ``shutdown`` completes."""