Coverage for src / lexigram / contracts / web / guard.py: 100%
7 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-08-19 05:41 +0800
« prev ^ index » next coverage.py v7.13.5, created at 2026-08-19 05:41 +0800
1"""Web guard protocols.
3Defines the core interface for guards that protect routes.
4"""
6from __future__ import annotations
8from typing import TYPE_CHECKING, Any, Protocol, runtime_checkable
10if TYPE_CHECKING:
11 from lexigram.contracts.web.execution_context import ExecutionContextProtocol
14@runtime_checkable
15class GuardProtocol(Protocol):
16 """Protocol for web guards.
18 Guards determine whether a request should be handled by a specific route.
19 They run before interceptors and handlers.
20 """
22 async def can_activate(self, context: ExecutionContextProtocol) -> bool:
23 """Determine if the request can proceed.
25 Args:
26 context: The execution context for the request.
28 Returns:
29 True if the request is allowed, False otherwise.
30 """
31 ...
33 async def handle_rejection(self, context: ExecutionContextProtocol) -> Any:
34 """Handle guard rejection by returning a response.
36 Args:
37 context: The execution context for the request.
39 Returns:
40 A response object indicating the rejection.
41 """
42 ...
45__all__ = ["GuardProtocol"]