#!/usr/bin/env python# -*- coding: utf-8 -*-"""Interfaces for nti.transactions."""from__future__importprint_function,absolute_import,divisionfromzope.interfaceimportInterfacefromzope.interfaceimportAttributefromzope.interfaceimportimplementerfromtransaction.interfacesimportTransactionErrorfromtransaction.interfacesimportITransaction# pylint:disable=no-method-argument,inherit-non-class# Sigh. The Python 2 version of pylint raises this.# pylint:disable=too-many-ancestors
[docs]classIExtendedTransaction(ITransaction):"""Extensions to the transaction api."""defnti_commit():""" Like ``commit``, but produces a :obj:`perfmetrics.Metric` ``transaction.commit`` metric. """defnti_abort():""" Like ``abort``, but produces a :obj:`perfmetrics.Metric` ``transaction.abort`` metric. """
[docs]classCommitFailedError(TransactionError):""" Committing the active transaction failed for an unknown and unexpected reason. This is raised instead of raising very generic system exceptions such as TypeError. """
[docs]classAbortFailedError(TransactionError):""" Aborting the active transaction failed for an unknown and unexpected reason. This is raised instead of raising very generic system exceptions such as ValueError and AttributeError. """
[docs]classTransactionLifecycleError(TransactionError):""" Raised when an application commits or aborts a transaction while the transaction controller believes it is in control. *Applications must not raise this exception.* This may have happened many times; we cannot detect that. This is a programming error. """
[docs]classForeignTransactionError(TransactionLifecycleError):""" Raised when a transaction manager has its transaction changed while a controlling transaction loop believes it is in control. The handler first aborted or committed the transaction, and then began a new one. Possibly many times. A kind of `TransactionLifecycleError`. *Applications must not raise this exception.* This is a programming error. """
[docs]classILoopInvocation(Interface):""" Description of why a loop was invoked. """handler=Attribute("The handler to run.")loop=Attribute("The loop doing the running.")args=Attribute("The arguments passed to the handler")kwargs=Attribute("The keyword arguments passed to the handler.")
[docs]classILoopEvent(Interface):""" Base class for event loop events. The *handler_args* and *handler_kwargs* should not be mutated in place or assigned to. These are a convenience for accessing the attributes of the *invocation* attribute. .. versionchanged:: 4.2.0 Add the *handler_args* and *handler_kwargs*. """invocation=Attribute("An ILoopInvocation.")handler_args=Attribute("The positional arguments for the handler, or ()")handler_kwargs=Attribute("The keyword arguments for the handler, or {}")
[docs]classIAfterTransactionBegan(ILoopEvent):""" A new transaction has begun. """tx=Attribute("The transaction.")
[docs]classIWillAttemptTransaction(ILoopEvent):""" Base class for attempt events. """tx=Attribute("The transaction.")attempt_number=Attribute("The number of the attempt. Starts at 0.")
# We get this in Python 2# pylint:disable=too-many-ancestors
[docs]classIWillFirstAttempt(IWillAttemptTransaction):""" The first attempt. """
[docs]classIWillRetryAttempt(IWillAttemptTransaction):""" A retry attempt. """
[docs]classIWillLastAttempt(IWillRetryAttempt):""" The final retry. """
[docs]classIWillSleepBetweenAttempts(ILoopEvent):""" Will sleep between attempts. If the ``sleep_time`` attribute is modified, that will be the time slept. """sleep_time=Attribute("The time to sleep.")
[docs]classIWillFirstAttemptWithRequest(IWillFirstAttempt):""" The first attempt, but with a request object. .. versionadded:: 4.2.0 """request=Attribute("The request object that will be used.")
[docs]classIWillRetryAttemptWithRequest(IWillRetryAttempt):""" A retry attempt with a request object. .. versionadded:: 4.2.0 """request=Attribute("The request object that will be used.")
[docs]classIWillLastAttemptWithRequest(IWillLastAttempt):""" The final retry with a request object. .. versionadded:: 4.2.0 """request=Attribute("The request object that will be used.")