exceptions.py 738 B

123456789101112131415161718192021222324252627282930313233343536
  1. import typing
  2. from . import types
  3. class BaseLockException(Exception): # noqa: N818
  4. # Error codes:
  5. LOCK_FAILED: typing.Final = 1
  6. strerror: typing.Optional[str] = None # ensure attribute always exists
  7. def __init__(
  8. self,
  9. *args: typing.Any,
  10. fh: typing.Union[types.IO, None, int, types.HasFileno] = None,
  11. **kwargs: typing.Any,
  12. ) -> None:
  13. self.fh = fh
  14. self.strerror = (
  15. str(args[1])
  16. if len(args) > 1 and isinstance(args[1], str)
  17. else None
  18. )
  19. Exception.__init__(self, *args)
  20. class LockException(BaseLockException):
  21. pass
  22. class AlreadyLocked(LockException):
  23. pass
  24. class FileToLarge(LockException):
  25. pass