Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/filelock/_error.py: 57%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

37 statements  

1from __future__ import annotations 

2 

3 

4class Timeout(TimeoutError): # ruff:ignore[error-suffix-on-exception-name] # public exception name; renaming breaks the API 

5 """Raised when the lock could not be acquired in *timeout* seconds.""" 

6 

7 def __init__(self, lock_file: str) -> None: 

8 super().__init__() 

9 self._lock_file = lock_file 

10 

11 def __reduce__(self) -> tuple[type[Timeout], tuple[str]]: 

12 # __init__ needs lock_file, so pickle must restore it as a constructor arg 

13 return self.__class__, (self._lock_file,) 

14 

15 def __str__(self) -> str: # pragma: needs hard-link 

16 return f"The file lock '{self._lock_file}' could not be acquired." 

17 

18 def __repr__(self) -> str: 

19 return f"{self.__class__.__name__}({self.lock_file!r})" 

20 

21 @property 

22 def lock_file(self) -> str: 

23 """The path of the file lock.""" 

24 return self._lock_file 

25 

26 

27class SoftFileLockLifetimeWarning(DeprecationWarning): 

28 """The configured soft-lock lifetime permits overlapping live holders after expiry.""" 

29 

30 

31class LeaseSettingsMismatch(ValueError): # ruff:ignore[error-suffix-on-exception-name] # public exception name; renaming breaks the API 

32 """A lease contender disagrees with the published claim about how long the lease lasts.""" 

33 

34 

35class SoftFileLockProtocolError(OSError): 

36 """Raised when strict soft-lock state cannot be interpreted without risking overlap.""" 

37 

38 def __init__(self, lock_file: str, claim_name: str | None, reason: str) -> None: 

39 self._lock_file = lock_file 

40 self._claim_name = claim_name 

41 self._reason = reason 

42 super().__init__(self.__str__()) 

43 

44 def __reduce__( 

45 self, 

46 ) -> tuple[type[SoftFileLockProtocolError], tuple[str, str | None, str]]: # pragma: needs hard-link 

47 return self.__class__, (self._lock_file, self._claim_name, self._reason) 

48 

49 def __str__(self) -> str: 

50 location = self._lock_file if self._claim_name is None else f"{self._lock_file}: claim {self._claim_name!r}" 

51 return f"Invalid strict soft-lock state at {location}: {self._reason}" 

52 

53 @property 

54 def lock_file(self) -> str: # pragma: needs hard-link 

55 """The requested lock path.""" 

56 return self._lock_file 

57 

58 @property 

59 def claim_name(self) -> str | None: # pragma: needs hard-link 

60 """The claim that caused the error, if scanning identified one.""" 

61 return self._claim_name 

62 

63 @property 

64 def reason(self) -> str: # pragma: needs hard-link 

65 """The protocol validation failure.""" 

66 return self._reason 

67 

68 

69__all__ = [ 

70 "LeaseSettingsMismatch", 

71 "SoftFileLockLifetimeWarning", 

72 "SoftFileLockProtocolError", 

73 "Timeout", 

74]