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
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
1from __future__ import annotations
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."""
7 def __init__(self, lock_file: str) -> None:
8 super().__init__()
9 self._lock_file = lock_file
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,)
15 def __str__(self) -> str: # pragma: needs hard-link
16 return f"The file lock '{self._lock_file}' could not be acquired."
18 def __repr__(self) -> str:
19 return f"{self.__class__.__name__}({self.lock_file!r})"
21 @property
22 def lock_file(self) -> str:
23 """The path of the file lock."""
24 return self._lock_file
27class SoftFileLockLifetimeWarning(DeprecationWarning):
28 """The configured soft-lock lifetime permits overlapping live holders after expiry."""
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."""
35class SoftFileLockProtocolError(OSError):
36 """Raised when strict soft-lock state cannot be interpreted without risking overlap."""
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__())
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)
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}"
53 @property
54 def lock_file(self) -> str: # pragma: needs hard-link
55 """The requested lock path."""
56 return self._lock_file
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
63 @property
64 def reason(self) -> str: # pragma: needs hard-link
65 """The protocol validation failure."""
66 return self._reason
69__all__ = [
70 "LeaseSettingsMismatch",
71 "SoftFileLockLifetimeWarning",
72 "SoftFileLockProtocolError",
73 "Timeout",
74]