endpoints.py
Provides utils for endpoints.
convert_path_params(endpoint, path_params, converters)
Convert path parameters to necessary types.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
endpoint
|
str
|
Route endpoint. |
required |
path_params
|
dict
|
Path parameters. |
required |
converters
|
dict
|
Converters for path parameter. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Converted path parameters. |
Source code in jetweb/utils/endpoints.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
convert_to_regex(match, converters)
Convert a "{name:type}" placeholder into a named regex group using converters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
match
|
Match
|
Match object with path parameter. |
required |
converters
|
dict
|
Converters for path parameter. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Regex substring for path parameter. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If converter identifier is not known. |
Source code in jetweb/utils/endpoints.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | |
create_pattern(endpoint, converters)
Build a compiled regex pattern from a route endpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
endpoint
|
str
|
Route endpoint. |
required |
converters
|
dict
|
Converters for path parameter. |
required |
Returns:
| Type | Description |
|---|---|
Pattern
|
Pattern object. |
Source code in jetweb/utils/endpoints.py
26 27 28 29 30 31 32 33 34 35 | |
normalize_endpoint(endpoint)
Add leading slash and remove several sequential slashes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
endpoint
|
str
|
Route endpoint. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Normalized route endpoint. |
Source code in jetweb/utils/endpoints.py
55 56 57 58 59 60 61 62 63 | |