-
-
Notifications
You must be signed in to change notification settings - Fork 136
Expand file tree
/
Copy pathutil.py
More file actions
29 lines (19 loc) · 636 Bytes
/
util.py
File metadata and controls
29 lines (19 loc) · 636 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
"""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
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") -> bytes:
return b64decode(value)
def format_number(value: str) -> Union[int, float]:
if isinstance(value, (int, float)):
return value
return float(value)