forked from ucloud/ucloud-sdk-python3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathabstract.py
More file actions
60 lines (49 loc) · 1.48 KB
/
Copy pathabstract.py
File metadata and controls
60 lines (49 loc) · 1.48 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
import typing
from ucloud.core import exc
class Field(object):
def __init__(
self,
required: bool = False,
default: typing.Any = None,
dump_to: str = None,
load_from: str = None,
strict: bool = None,
**kwargs
):
self.required = required
self.default = default
self.dump_to = dump_to
self.load_from = load_from
self.options = kwargs
self.strict = bool(strict) # None as False
def dumps(self, value, **kwargs):
raise NotImplementedError
def loads(self, value, **kwargs):
raise NotImplementedError
@staticmethod
def fail(name, expected, got):
msg = "invalid field {}, expect {}, got {}".format(name, expected, got)
raise exc.ValidationException(msg)
class Schema(object):
fields = {}
def __init__(
self,
required: bool = False,
default: typing.Union[typing.Callable, typing.Any] = dict,
dump_to: str = None,
load_from: str = None,
strict: bool = False,
case_sensitive: bool = False,
**kwargs
):
self.required = required
self.default = default
self.dump_to = dump_to
self.load_from = load_from
self.options = kwargs
self.strict = strict
self.case_sensitive = case_sensitive
def dumps(self, d: dict) -> dict:
raise NotImplementedError
def loads(self, d: dict) -> dict:
raise NotImplementedError