Coverage for src/lexigram/web/contributors/registry.py: 67%

12 statements  

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

1"""Web contributor registry. 

2 

3Registry for tracking discovered web contributors that provide controllers 

4and middleware to the web provider. 

5""" 

6 

7from __future__ import annotations 

8 

9from lexigram.contracts.web import WebContributorProtocol 

10 

11 

12class WebContributorRegistry: 

13 """Registry for web contributors discovered via entry-points. 

14 

15 The web provider discovers contributors during registration phase 

16 and stores them in this registry for tracking and debugging purposes. 

17 """ 

18 

19 def __init__(self) -> None: 

20 """Initialize an empty registry.""" 

21 self._contributors: dict[str, WebContributorProtocol] = {} 

22 

23 def register(self, contributor: WebContributorProtocol) -> None: 

24 """Register a web contributor. 

25 

26 Args: 

27 contributor: The contributor instance to register. 

28 """ 

29 self._contributors[contributor.contributor_id] = contributor 

30 

31 def get(self, contributor_id: str) -> WebContributorProtocol | None: 

32 """Get a contributor by ID. 

33 

34 Args: 

35 contributor_id: The unique contributor identifier. 

36 

37 Returns: 

38 The contributor instance or None if not found. 

39 """ 

40 return self._contributors.get(contributor_id) 

41 

42 def get_all(self) -> list[WebContributorProtocol]: 

43 """Get all registered contributors. 

44 

45 Returns: 

46 List of all registered contributors in registration order. 

47 """ 

48 return list(self._contributors.values()) 

49 

50 

51__all__ = ["WebContributorRegistry"]