base.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # -*- coding: utf-8 -*-
  2. """Abstract base classes.
  3. These are necessary to avoid circular imports between core.py and fields.py.
  4. """
  5. import copy
  6. class FieldABC(object):
  7. """Abstract base class from which all Field classes inherit.
  8. """
  9. parent = None
  10. name = None
  11. def serialize(self, attr, obj, accessor=None):
  12. raise NotImplementedError
  13. def deserialize(self, value):
  14. raise NotImplementedError
  15. def _serialize(self, value, attr, obj, **kwargs):
  16. raise NotImplementedError
  17. def _deserialize(self, value, attr, data, **kwargs):
  18. raise NotImplementedError
  19. def __deepcopy__(self, memo):
  20. ret = copy.copy(self)
  21. return ret
  22. class SchemaABC(object):
  23. """Abstract base class from which all Schemas inherit."""
  24. def dump(self, obj, many=None):
  25. raise NotImplementedError
  26. def dumps(self, obj, many=None, *args, **kwargs):
  27. raise NotImplementedError
  28. def load(self, data, many=None, partial=None, unknown=None):
  29. raise NotImplementedError
  30. def loads(
  31. self, json_data, many=None, partial=None, unknown=None,
  32. **kwargs
  33. ):
  34. raise NotImplementedError