-
-
Notifications
You must be signed in to change notification settings - Fork 620
/
base.py
63 lines (47 loc) · 1.31 KB
/
base.py
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
"""Abstract base classes.
These are necessary to avoid circular imports between schema.py and fields.py.
.. warning::
This module is treated as private API.
Users should not need to use this module directly.
"""
from __future__ import annotations
from abc import ABC, abstractmethod
class FieldABC(ABC):
"""Abstract base class from which all Field classes inherit."""
parent = None
name = None
root = None
@abstractmethod
def serialize(self, attr, obj, accessor=None):
pass
@abstractmethod
def deserialize(self, value):
pass
@abstractmethod
def _serialize(self, value, attr, obj, **kwargs):
pass
@abstractmethod
def _deserialize(self, value, attr, data, **kwargs):
pass
class SchemaABC(ABC):
"""Abstract base class from which all Schemas inherit."""
@abstractmethod
def dump(self, obj, *, many: bool | None = None):
pass
@abstractmethod
def dumps(self, obj, *, many: bool | None = None):
pass
@abstractmethod
def load(self, data, *, many: bool | None = None, partial=None, unknown=None):
pass
@abstractmethod
def loads(
self,
json_data,
*,
many: bool | None = None,
partial=None,
unknown=None,
**kwargs,
):
pass