-
-
Notifications
You must be signed in to change notification settings - Fork 136
Expand file tree
/
Copy pathutil.py
More file actions
34 lines (22 loc) · 756 Bytes
/
util.py
File metadata and controls
34 lines (22 loc) · 756 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""OpenAPI core schemas util module"""
from base64 import b64decode
from datetime import date
from datetime import datetime
from typing import Any
from typing import Union
from uuid import UUID
from pydantic import SecretStr
def format_date(value: str) -> date:
return datetime.strptime(value, "%Y-%m-%d").date()
def format_uuid(value: Any) -> UUID:
if isinstance(value, UUID):
return value
return UUID(value)
def format_byte(value: str, encoding: str = "utf8") -> str:
return str(b64decode(value), encoding)
def format_number(value: str) -> Union[int, float]:
if isinstance(value, (int, float)):
return value
return float(value)
def format_password(value: str) -> SecretStr:
return SecretStr(value)