exceptions.py 850 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. """
  2. TODO:
  3. """
  4. from __future__ import annotations
  5. __all__ = [
  6. "Error",
  7. "ParserError",
  8. "UniquenessError",
  9. ]
  10. from typing import Any, Optional
  11. class Error(Exception):
  12. """Base class for rdflib exceptions."""
  13. def __init__(self, msg: Optional[str] = None):
  14. Exception.__init__(self, msg)
  15. self.msg = msg
  16. class ParserError(Error):
  17. """RDF Parser error."""
  18. def __init__(self, msg: str):
  19. Error.__init__(self, msg)
  20. self.msg: str = msg
  21. def __str__(self) -> str:
  22. return self.msg
  23. class UniquenessError(Error):
  24. """A uniqueness assumption was made in the context, and that is not true"""
  25. def __init__(self, values: Any):
  26. Error.__init__(
  27. self,
  28. "\
  29. Uniqueness assumption is not fulfilled. Multiple values are: %s"
  30. % values,
  31. )