Coverage for src/lexigram/web/types.py: 98%
48 statements
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-25 04:37 +0800
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-25 04:37 +0800
1"""Web Framework Types and Data Structures
3This module defines the core types, enums, and data structures used throughout
4the Lexigram Web framework. These provide type safety and consistent interfaces.
5"""
7from __future__ import annotations
9from abc import ABC
10from enum import IntEnum, StrEnum
11from typing import Any
13from lexigram.web.config import ServerConfig, WebProviderConfig
15# Re-export key types from submodules
16from lexigram.web.protocols import ParamMetadata
17from lexigram.web.routing.versioning import VersioningConfig, VersioningStrategy
20# HTTP Method enum for type safety
21class HTTPMethod(StrEnum):
22 """HTTP methods supported by the framework"""
24 GET = "GET"
25 POST = "POST"
26 PUT = "PUT"
27 DELETE = "DELETE"
28 PATCH = "PATCH"
29 HEAD = "HEAD"
30 OPTIONS = "OPTIONS"
31 TRACE = "TRACE"
34# Content type constants
35class ContentType(StrEnum):
36 """Common content types"""
38 JSON = "application/json"
39 FORM = "application/x-www-form-urlencoded"
40 MULTIPART = "multipart/form-data"
41 TEXT = "text/plain"
42 HTML = "text/html"
43 XML = "application/xml"
46# Status code groups for convenience
47class StatusCode(IntEnum):
48 """HTTP status code constants"""
50 # 2xx Success
51 OK = 200
52 CREATED = 201
53 ACCEPTED = 202
54 NO_CONTENT = 204
56 # 3xx Redirection
57 MOVED_PERMANENTLY = 301
58 FOUND = 302
59 NOT_MODIFIED = 304
61 # 4xx Client Error
62 BAD_REQUEST = 400
63 UNAUTHORIZED = 401
64 FORBIDDEN = 403
65 NOT_FOUND = 404
66 METHOD_NOT_ALLOWED = 405
67 CONFLICT = 409
68 UNPROCESSABLE_ENTITY = 422
69 TOO_MANY_REQUESTS = 429
71 # 5xx Server Error
72 INTERNAL_SERVER_ERROR = 500
73 NOT_IMPLEMENTED = 501
74 BAD_GATEWAY = 502
75 SERVICE_UNAVAILABLE = 503
76 GATEWAY_TIMEOUT = 504
79class PipeBase(ABC):
80 """Base class for pipes (optional convenience).
82 Provides a no-op implementation that subclasses can override.
83 """
85 async def transform(self, value: Any, metadata: ParamMetadata) -> Any:
86 """Default implementation just returns the value."""
87 return value
90__all__ = [
91 # HTTP types
92 "ContentType",
93 "HTTPMethod",
94 "ParamMetadata",
95 "PipeBase",
96 # Configuration types
97 "ServerConfig",
98 "StatusCode",
99 # Versioning types
100 "VersioningConfig",
101 "VersioningStrategy",
102 "WebProviderConfig",
103]