Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/filelock/_error.py: 53%
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
3__lazy_modules__ = ["typing"]
5from typing import Final
8class Timeout(TimeoutError): # ruff:ignore[error-suffix-on-exception-name] # public exception name; renaming breaks the API
9 """Raised when the lock could not be acquired in *timeout* seconds."""
11 def __init__(self, lock_file: str, holder: str | None = None) -> None:
12 super().__init__()
13 self._lock_file = lock_file
14 self._holder = holder
16 def __reduce__(self) -> tuple[type[Timeout], tuple[str], dict[str, object]]:
17 # holder rides in the state so a subclass taking only lock_file, and a 4.0.12 reader, can still unpickle it.
18 return self.__class__, (self._lock_file,), self.__dict__
20 def __str__(self) -> str: # pragma: needs hard-link
21 message: Final = f"The file lock '{self._lock_file}' could not be acquired."
22 if self._holder is None:
23 return message
24 return f"{message} It is held by {self._holder}, which this host cannot probe."
26 def __repr__(self) -> str:
27 return f"{self.__class__.__name__}({self.lock_file!r})"
29 @property
30 def lock_file(self) -> str:
31 """The path of the file lock."""
32 return self._lock_file
35class SoftFileLockLifetimeWarning(FutureWarning):
36 """
37 The configured soft-lock lifetime permits overlapping live holders after expiry.
39 A :class:`FutureWarning` shows by default wherever the lock is configured; a :class:`DeprecationWarning` shows only
40 in ``__main__``.
42 """
45class LeaseSettingsMismatch(ValueError): # ruff:ignore[error-suffix-on-exception-name] # public exception name; renaming breaks the API
46 """A lease contender disagrees with the published claim about how long the lease lasts."""
49class SoftFileLockProtocolError(OSError):
50 """Raised when strict soft-lock state cannot be interpreted without risking overlap."""
52 def __init__(self, lock_file: str, claim_name: str | None, reason: str) -> None:
53 self._lock_file = lock_file
54 self._claim_name = claim_name
55 self._reason = reason
56 super().__init__(self.__str__())
58 def __reduce__(
59 self,
60 ) -> tuple[
61 type[SoftFileLockProtocolError], tuple[str, str | None, str], dict[str, object]
62 ]: # pragma: needs hard-link
63 return self.__class__, (self._lock_file, self._claim_name, self._reason), self.__dict__
65 def __str__(self) -> str:
66 location = self._lock_file if self._claim_name is None else f"{self._lock_file}: claim {self._claim_name!r}"
67 return f"Invalid strict soft-lock state at {location}: {self._reason}"
69 @property
70 def lock_file(self) -> str: # pragma: needs hard-link
71 """The requested lock path."""
72 return self._lock_file
74 @property
75 def claim_name(self) -> str | None: # pragma: needs hard-link
76 """The claim that caused the error, if scanning identified one."""
77 return self._claim_name
79 @property
80 def reason(self) -> str: # pragma: needs hard-link
81 """The protocol validation failure."""
82 return self._reason
85__all__ = [
86 "LeaseSettingsMismatch",
87 "SoftFileLockLifetimeWarning",
88 "SoftFileLockProtocolError",
89 "Timeout",
90]