Route helpers for contracts checker.
contracts.routes
| Name | Type | Default | Description |
|---|---|---|---|
type
|
|
— | |
qualified_name
|
|
— | |
element_type
|
|
— | |
description
|
|
— | |
source_file
|
|
— | |
line_number
|
|
— | |
is_autodoc
|
|
— | |
autodoc_element
|
|
— | |
_autodoc_template
|
|
— | |
_autodoc_url_path
|
|
— | |
_autodoc_page_type
|
|
— | |
title
|
|
— | |
doc_content_hash
|
|
— |
Symbols on this page
Normalize path for lookup (strip slashes, empty becomes '').
Map a URL-bearing template attribute name to HTTP method.
Map route path to allowed methods.
Check if URL could match a route pattern.
Pre-segment routes for O(1) static and O(parametric) URL matching.
Returns (static_routes, parametric_routes). For static URLs use dict lookup; for parametric URLs scan only parametric_routes.
Find route matching URL. O(1) for static, O(parametric) for parametric.
_normalize_path
function
def _normalize_path(path: str) -> str
Normalize path for lookup (strip slashes, empty becomes '').
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
path
|
str
|
— |
attr_to_method
function
def attr_to_method(attr: str, method_override: str | None = None) -> str
Map a URL-bearing template attribute name to HTTP method.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
attr
|
str
|
— | |
method_override
|
str | None
|
None
|
collect_route_paths
function
def collect_route_paths(router: Router) -> dict[str, frozenset[str]]
Map route path to allowed methods.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
router
|
Router
|
— |
path_matches_route
function
def path_matches_route(url: str, route_path: str) -> bool
Check if URL could match a route pattern.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
url
|
str
|
— | |
route_path
|
str
|
— |
build_route_index
function
def build_route_index(route_paths: dict[str, frozenset[str]]) -> tuple[dict[str, tuple[str, frozenset[str]]], list[tuple[str, frozenset[str]]]]
Pre-segment routes for O(1) static and O(parametric) URL matching.
Returns (static_routes, parametric_routes). For static URLs use dict lookup; for parametric URLs scan only parametric_routes.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
route_paths
|
dict[str, frozenset[str]]
|
— |
find_matching_route
function
def find_matching_route(url: str, static_routes: dict[str, tuple[str, frozenset[str]]], parametric_routes: list[tuple[str, frozenset[str]]]) -> tuple[str, frozenset[str]] | None
Find route matching URL. O(1) for static, O(parametric) for parametric.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
url
|
str
|
— | |
static_routes
|
dict[str, tuple[str, frozenset[str]]]
|
— | |
parametric_routes
|
list[tuple[str, frozenset[str]]]
|
— |
View source · /home/runner/work/chirp/chirp/site/../src/chirp/contracts/routes.py:1