Classes
TemplateProtocol
2
▼
TemplateProtocol
2
▼
Attributes
| Name | Type | Description |
|---|---|---|
strings |
tuple[str, ...]
|
— |
interpolations |
tuple[Any, ...]
|
— |
TemplateLibProtocol
1
▼
TemplateLibProtocol
1
▼
Attributes
| Name | Type | Description |
|---|---|---|
Template |
type[TemplateProtocol]
|
— |
PatternError
0
▼
Error raised when a regex pattern is invalid or unsafe.
PatternError
0
▼
Error raised when a regex pattern is invalid or unsafe.
ComposablePattern
6
▼
A composable regex pattern with safety validation.
**ComposablePattern wraps a regex pattern strin…
ComposablePattern
6
▼
A composable regex pattern with safety validation.
ComposablePattern wraps a regex pattern string and provides:
- Lazy compilation (pattern is compiled on first use)
- ReDoS validation at creation time
- Safe composition via the | operator
Attributes
| Name | Type | Description |
|---|---|---|
pattern |
— |
The raw regex pattern string |
Methods
pattern
0
str
▼
The raw regex pattern string.
property
pattern
0
str
▼
def pattern(self) -> str
Returns
str
compile
1
re.Pattern[str]
▼
Compile the pattern to a regex object.
compile
1
re.Pattern[str]
▼
def compile(self, flags: int = 0) -> re.Pattern[str]
Parameters
| Name | Type | Description |
|---|---|---|
flags |
— |
Regex flags (re.IGNORECASE, re.MULTILINE, etc.) Default:0
|
Returns
re.Pattern[str]
Compiled re.Pattern object
Internal Methods 3 ▼
__init__
1
▼
Create a composable pattern.
__init__
1
▼
def __init__(self, pattern: str) -> None
Parameters
| Name | Type | Description |
|---|---|---|
pattern |
— |
The regex pattern string |
__or__
1
ComposablePattern
▼
Combine patterns with alternation: pattern1 | pattern2.
Both patterns are wrap…
__or__
1
ComposablePattern
▼
def __or__(self, other: ComposablePattern | str) -> ComposablePattern
Combine patterns with alternation: pattern1 | pattern2.
Both patterns are wrapped in non-capturing groups to prevent group interference.
Parameters
| Name | Type | Description |
|---|---|---|
other |
— |
Returns
ComposablePattern
__repr__
0
str
▼
__repr__
0
str
▼
def __repr__(self) -> str
Returns
str
Functions
_validate_redos_safety
1
None
▼
Validate pattern doesn't contain known ReDoS vulnerabilities.
_validate_redos_safety
1
None
▼
def _validate_redos_safety(pattern: str) -> None
Parameters
| Name | Type | Description |
|---|---|---|
pattern |
str |
r
1
ComposablePattern
▼
The `r` tag for composable regex patterns.
Composes regex patterns safely by w…
r
1
ComposablePattern
▼
def r(template: TemplateProtocol) -> ComposablePattern
Thertag for composable regex patterns.
Composes regex patterns safely by wrapping interpolated values in non-capturing groups. This prevents group index collision and quantifier interference.
Parameters
| Name | Type | Description |
|---|---|---|
template |
TemplateProtocol |
A t-string template with pattern interpolations |
Returns
ComposablePattern
k
1
str
▼
The `k` tag for Kida template strings.
Processes a PEP 750 t-string with autom…
k
1
str
▼
def k(template: TemplateProtocol) -> str
Thektag for Kida template strings.
Processes a PEP 750 t-string with automatic HTML escaping.
Values are escaped unless they implement__html__()(Markup).
Type Safety:
The TemplateProtocol type hint ensures static type checkers (mypy,
pyright) catch misuse likek("string"). Runtime isinstance() check
is omitted for performance (~35% faster). Duck typing allows test mocks.
Parameters
| Name | Type | Description |
|---|---|---|
template |
TemplateProtocol |
Returns
str