You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.0 KiB

4 years ago
  1. import abc
  2. from collections.abc import Mapping, MutableMapping
  3. class _TypingMeta(abc.ABCMeta):
  4. # A fake metaclass to satisfy typing deps in runtime
  5. # basically MultiMapping[str] and other generic-like type instantiations
  6. # are emulated.
  7. # Note: real type hints are provided by __init__.pyi stub file
  8. def __getitem__(self, key):
  9. return self
  10. class MultiMapping(Mapping, metaclass=_TypingMeta):
  11. @abc.abstractmethod
  12. def getall(self, key, default=None):
  13. raise KeyError
  14. @abc.abstractmethod
  15. def getone(self, key, default=None):
  16. raise KeyError
  17. class MutableMultiMapping(MultiMapping, MutableMapping):
  18. @abc.abstractmethod
  19. def add(self, key, value):
  20. raise NotImplementedError
  21. @abc.abstractmethod
  22. def extend(self, *args, **kwargs):
  23. raise NotImplementedError
  24. @abc.abstractmethod
  25. def popone(self, key, default=None):
  26. raise KeyError
  27. @abc.abstractmethod
  28. def popall(self, key, default=None):
  29. raise KeyError