refactor: split changes for api/libs/helper.py (#29875)
This commit is contained in:
@@ -11,6 +11,7 @@ from collections.abc import Generator, Mapping
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from hashlib import sha256
|
from hashlib import sha256
|
||||||
from typing import TYPE_CHECKING, Annotated, Any, Optional, Union, cast
|
from typing import TYPE_CHECKING, Annotated, Any, Optional, Union, cast
|
||||||
|
from uuid import UUID
|
||||||
from zoneinfo import available_timezones
|
from zoneinfo import available_timezones
|
||||||
|
|
||||||
from flask import Response, stream_with_context
|
from flask import Response, stream_with_context
|
||||||
@@ -119,6 +120,19 @@ def uuid_value(value: Any) -> str:
|
|||||||
raise ValueError(error)
|
raise ValueError(error)
|
||||||
|
|
||||||
|
|
||||||
|
def normalize_uuid(value: str | UUID) -> str:
|
||||||
|
if not value:
|
||||||
|
return ""
|
||||||
|
|
||||||
|
try:
|
||||||
|
return uuid_value(value)
|
||||||
|
except ValueError as exc:
|
||||||
|
raise ValueError("must be a valid UUID") from exc
|
||||||
|
|
||||||
|
|
||||||
|
UUIDStrOrEmpty = Annotated[str, AfterValidator(normalize_uuid)]
|
||||||
|
|
||||||
|
|
||||||
def alphanumeric(value: str):
|
def alphanumeric(value: str):
|
||||||
# check if the value is alphanumeric and underlined
|
# check if the value is alphanumeric and underlined
|
||||||
if re.match(r"^[a-zA-Z0-9_]+$", value):
|
if re.match(r"^[a-zA-Z0-9_]+$", value):
|
||||||
|
|||||||
Reference in New Issue
Block a user