|
| 1 | +from collections.abc import Callable, Iterable, Sequence |
| 2 | +from typing import Any, Protocol, TypeVar, overload |
| 3 | +from typing_extensions import TypeVarTuple, Unpack |
| 4 | + |
| 5 | +from zope.interface import Interface |
| 6 | + |
| 7 | +_T = TypeVar("_T") |
| 8 | +_Ts = TypeVarTuple("_Ts") |
| 9 | + |
| 10 | +class _Attempt(Protocol): |
| 11 | + def __enter__(self) -> ITransaction: ... |
| 12 | + def __exit__(self, t: object, v: object, tb: object, /) -> bool | None: ... |
| 13 | + |
| 14 | +class _DataManager(Protocol): |
| 15 | + @property |
| 16 | + def transaction_manager(self) -> ITransactionManager: ... |
| 17 | + def abort(self, transaction: ITransaction, /) -> object: ... |
| 18 | + def tpc_begin(self, transaction: ITransaction, /) -> object: ... |
| 19 | + def commit(self, transaction: ITransaction, /) -> object: ... |
| 20 | + def tpc_vote(self, transaction: ITransaction, /) -> object: ... |
| 21 | + def tpc_finish(self, transaction: ITransaction, /) -> object: ... |
| 22 | + def tpc_abort(self, transaction: ITransaction, /) -> object: ... |
| 23 | + def sortKey(self) -> str: ... |
| 24 | + |
| 25 | +class _Synchronizer(Protocol): |
| 26 | + def beforeCompletion(self, transaction: ITransaction, /) -> object: ... |
| 27 | + def afterCompletion(self, transaction: ITransaction, /) -> object: ... |
| 28 | + def newTransaction(self, transaction: ITransaction, /) -> object: ... |
| 29 | + |
| 30 | + |
| 31 | +class ITransactionManager(Interface): |
| 32 | + explicit: bool |
| 33 | + def begin() -> ITransaction: ... |
| 34 | + def get() -> ITransaction: ... |
| 35 | + def commit() -> object: ... |
| 36 | + def abort() -> object: ... |
| 37 | + def doom() -> object: ... |
| 38 | + def isDoomed() -> bool: ... |
| 39 | + def savepoint(optimistic: bool = False) -> ISavepoint: ... |
| 40 | + def registerSynch(synch: _Synchronizer) -> object: ... |
| 41 | + def unregisterSynch(synch: _Synchronizer) -> object: ... |
| 42 | + def clearSynchs() -> object: ... |
| 43 | + def registeredSynchs() -> bool: ... |
| 44 | + def attempts(number: int = 3) -> Iterable[_Attempt]: ... |
| 45 | + @overload |
| 46 | + def run(func: Callable[[], _T], tries: int = 3) -> _T: ... |
| 47 | + @overload |
| 48 | + def run(func: None = None, tries: int = 3) -> Callable[[Callable[[], _T]], _T]: ... |
| 49 | + @overload |
| 50 | + def run(tries: int, /) -> Callable[[Callable[[], _T]], _T]: ... |
| 51 | + |
| 52 | +class ITransaction(Interface): |
| 53 | + user: str |
| 54 | + description: str |
| 55 | + extension: dict[str, Any] |
| 56 | + def commit() -> object: ... |
| 57 | + def abort() -> object: ... |
| 58 | + def doom() -> object: ... |
| 59 | + def savepoint(optimistic: bool = False) -> ISavepoint: ... |
| 60 | + def join(datamanager: _DataManager) -> object: ... |
| 61 | + def note(text: str) -> object: ... |
| 62 | + def setExtendedInfo(name: str, value: object) -> object: ... |
| 63 | + @overload |
| 64 | + def addBeforeCommitHook(hook: Callable[[], object], args: tuple[()] = (), kws: None = None) -> object: ... |
| 65 | + @overload |
| 66 | + def addBeforeCommitHook(hook: Callable[[Unpack[_Ts]], object], args: tuple[Unpack[_Ts]], kws: None = None) -> object: ... |
| 67 | + @overload |
| 68 | + def addBeforeCommitHook(hook: Callable[..., object], args: Sequence[Any], kws: dict[str, Any]) -> object: ... |
| 69 | + def getBeforeCommitHooks() -> Iterable[tuple[Callable[..., object], Sequence[Any], dict[str, Any]]]: ... |
| 70 | + @overload |
| 71 | + def addAfterCommitHook(hook: Callable[[bool], object], args: tuple[()] = (), kws: None = None) -> object: ... |
| 72 | + @overload |
| 73 | + def addAfterCommitHook(hook: Callable[[bool, Unpack[_Ts]], object], args: tuple[Unpack[_Ts]], kws: None = None) -> object: ... |
| 74 | + @overload |
| 75 | + def addAfterCommitHook(hook: Callable[[bool, Unpack[tuple[Any, ...]]], object], args: Sequence[Any], kws: dict[str, Any]) -> object: ... |
| 76 | + def getAfterCommitHooks() -> Iterable[tuple[Callable[[bool, Unpack[tuple[Any, ...]]], object], Sequence[Any], dict[str, Any]]]: ... |
| 77 | + @overload |
| 78 | + def addBeforeAbortHook(hook: Callable[[], object], args: tuple[()] = (), kws: None = None) -> object: ... |
| 79 | + @overload |
| 80 | + def addBeforeAbortHook(hook: Callable[[Unpack[_Ts]], object], args: tuple[Unpack[_Ts]], kws: None = None) -> object: ... |
| 81 | + @overload |
| 82 | + def addBeforeAbortHook(hook: Callable[..., object], args: Sequence[Any], kws: dict[str, Any]) -> object: ... |
| 83 | + def getBeforeAbortHooks() -> Iterable[tuple[Callable[..., object], Sequence[Any], dict[str, Any]]]: ... |
| 84 | + @overload |
| 85 | + def addAfterAbortHook(hook: Callable[[], object], args: tuple[()] = (), kws: None = None) -> object: ... |
| 86 | + @overload |
| 87 | + def addAfterAbortHook(hook: Callable[[Unpack[_Ts]], object], args: tuple[Unpack[_Ts]], kws: None = None) -> object: ... |
| 88 | + @overload |
| 89 | + def addAfterAbortHook(hook: Callable[..., object], args: Sequence[Any], kws: dict[str, Any]) -> object: ... |
| 90 | + def getAfterAbortHooks() -> Iterable[tuple[Callable[..., object], Sequence[Any], dict[str, Any]]]: ... |
| 91 | + def set_data(ob: object, data: object) -> object: ... |
| 92 | + def data(ob: object) -> Any: ... |
| 93 | + def isRetryableError(error: BaseException) -> bool: ... |
| 94 | + |
| 95 | +class IDataManager(Interface): |
| 96 | + transaction_manager: ITransactionManager |
| 97 | + def abort(transaction: ITransaction) -> object: ... |
| 98 | + def tpc_begin(transaction: ITransaction) -> object: ... |
| 99 | + def commit(transaction: ITransaction) -> object: ... |
| 100 | + def tpc_vote(transaction: ITransaction) -> object: ... |
| 101 | + def tpc_finish(transaction: ITransaction) -> object: ... |
| 102 | + def tpc_abort(transaction: ITransaction) -> object: ... |
| 103 | + def sortKey() -> str: ... |
| 104 | + |
| 105 | +class ISavepointDataManager(IDataManager): |
| 106 | + def savepoint() -> IDataManagerSavepoint: ... |
| 107 | + |
| 108 | +class IRetryDataManager(IDataManager): |
| 109 | + def should_retry(exception: BaseException) -> bool: ... |
| 110 | + |
| 111 | +class IDataManagerSavepoint(Interface): |
| 112 | + def rollback() -> object: ... |
| 113 | + |
| 114 | +class ISavepoint(Interface): |
| 115 | + def rollback() -> object: ... |
| 116 | + valid: bool |
| 117 | + |
| 118 | +class InvalidSavepointRollbackError(Exception): ... |
| 119 | + |
| 120 | +class ISynchronizer(Interface): |
| 121 | + def beforeCompletion(transaction: ITransaction) -> object: ... |
| 122 | + def afterCompletion(transaction: ITransaction) -> object: ... |
| 123 | + def newTransaction(transaction: ITransaction) -> object: ... |
| 124 | + |
| 125 | +class TransactionError(Exception): ... |
| 126 | +class TransactionFailedError(TransactionError): ... |
| 127 | +class DoomedTransaction(TransactionError): ... |
| 128 | +class TransientError(TransactionError): ... |
| 129 | +class NoTransaction(TransactionError): ... |
| 130 | +class AlreadyInTransaction(TransactionError): ... |
0 commit comments