This repository was archived by the owner on Dec 25, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy path__init__.hbs
More file actions
143 lines (129 loc) · 3.11 KB
/
__init__.hbs
File metadata and controls
143 lines (129 loc) · 3.11 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# coding: utf-8
{{> _helper_header }}
import typing
import typing_extensions
from .schema import (
get_class,
none_type_,
classproperty,
Bool,
FileIO,
Schema,
SingletonMeta,
AnyTypeSchema,
UnsetAnyTypeSchema,
INPUT_TYPES_ALL
)
from .schemas import (
ListSchema,
NoneSchema,
NumberSchema,
IntSchema,
Int32Schema,
Int64Schema,
Float32Schema,
Float64Schema,
StrSchema,
UUIDSchema,
DateSchema,
DateTimeSchema,
DecimalSchema,
BytesSchema,
FileSchema,
BinarySchema,
BoolSchema,
NotAnyTypeSchema,
OUTPUT_BASE_TYPES,
DictSchema
)
from .validation import (
PatternInfo,
ValidationMetadata,
immutabledict
)
from .format import (
as_date,
as_datetime,
as_decimal,
as_uuid
)
def typed_dict_to_instance(t_dict: typing_extensions._TypedDictMeta) -> typing.Mapping: # type: ignore
res = {}
for key, val in t_dict.__annotations__.items():
if isinstance(val, typing._GenericAlias): # type: ignore
# typing.Type[W] -> W
val_cls = typing_extensions.get_args(val)[0]
res[key] = val_cls
return res
X = typing.TypeVar('X', bound=typing.Tuple)
def tuple_to_instance(tup: typing.Type[X]) -> X:
res = []
for arg in typing_extensions.get_args(tup):
if isinstance(arg, typing._GenericAlias): # type: ignore
# typing.Type[Schema] -> Schema
arg_cls = typing_extensions.get_args(arg)[0]
res.append(arg_cls)
return tuple(res) # type: ignore
class Unset:
"""
An instance of this class is set as the default value for object type(dict) properties that are optional
When a property has an unset value, that property will not be assigned in the dict
"""
pass
unset: Unset = Unset()
def key_unknown_error_msg(key: str) -> str:
return (f"Invalid key. The key {key} is not a known key in this payload. "
"If this key is an additional property, use get_additional_property_"
)
def raise_if_key_known(
key: str,
required_keys: typing.FrozenSet[str],
optional_keys: typing.FrozenSet[str]
):
if key in required_keys or key in optional_keys:
raise ValueError(f"The key {key} is a known property, use get_property to access its value")
__all__ = [
'get_class',
'none_type_',
'classproperty',
'Bool',
'FileIO',
'Schema',
'SingletonMeta',
'AnyTypeSchema',
'UnsetAnyTypeSchema',
'INPUT_TYPES_ALL',
'ListSchema',
'NoneSchema',
'NumberSchema',
'IntSchema',
'Int32Schema',
'Int64Schema',
'Float32Schema',
'Float64Schema',
'StrSchema',
'UUIDSchema',
'DateSchema',
'DateTimeSchema',
'DecimalSchema',
'BytesSchema',
'FileSchema',
'BinarySchema',
'BoolSchema',
'NotAnyTypeSchema',
'OUTPUT_BASE_TYPES',
'DictSchema',
'PatternInfo',
'ValidationMetadata',
'immutabledict',
'as_date_',
'as_datetime_',
'as_decimal_',
'as_uuid_',
'typed_dict_to_instance',
'tuple_to_instance',
'Unset',
'unset',
'key_unknown_error_msg',
'raise_if_key_known'
]