[Zodb-checkins] SVN: ZODB/branches/3.4/ A ``getBeforeCommitHooks()`` method has been added to Transaction. It

Florent Guillaume fg at nuxeo.com
Tue Apr 26 09:03:07 EDT 2005


Log message for revision 30182:
  A ``getBeforeCommitHooks()`` method has been added to Transaction. It
  returns an iterable producing the registered beforeCommit hooks.
  

Changed:
  U   ZODB/branches/3.4/NEWS.txt
  U   ZODB/branches/3.4/src/transaction/_transaction.py
  U   ZODB/branches/3.4/src/transaction/interfaces.py
  U   ZODB/branches/3.4/src/transaction/tests/test_transaction.py

-=-
Modified: ZODB/branches/3.4/NEWS.txt
===================================================================
--- ZODB/branches/3.4/NEWS.txt	2005-04-26 06:54:19 UTC (rev 30181)
+++ ZODB/branches/3.4/NEWS.txt	2005-04-26 13:03:07 UTC (rev 30182)
@@ -1,3 +1,9 @@
+What's new in ZODB3 3.4 branch
+==============================
+
+A ``getBeforeCommitHooks()`` method has been added to Transaction. It
+returns an iterable producing the registered beforeCommit hooks.
+
 What's new in ZODB3 3.4a5?
 ==========================
 Release date: 25-Apr-2005

Modified: ZODB/branches/3.4/src/transaction/_transaction.py
===================================================================
--- ZODB/branches/3.4/src/transaction/_transaction.py	2005-04-26 06:54:19 UTC (rev 30181)
+++ ZODB/branches/3.4/src/transaction/_transaction.py	2005-04-26 13:03:07 UTC (rev 30182)
@@ -358,8 +358,10 @@
         # Append the exception type and value.
         ft.writelines(traceback.format_exception_only(t, v))
         raise t, v, tb
-        
 
+    def getBeforeCommitHooks(self):
+        return iter(self._before_commit)
+
     def beforeCommitHook(self, hook, *args, **kws):
         self._before_commit.append((hook, args, kws))
 

Modified: ZODB/branches/3.4/src/transaction/interfaces.py
===================================================================
--- ZODB/branches/3.4/src/transaction/interfaces.py	2005-04-26 06:54:19 UTC (rev 30181)
+++ ZODB/branches/3.4/src/transaction/interfaces.py	2005-04-26 13:03:07 UTC (rev 30182)
@@ -189,6 +189,13 @@
         instead.
         """
 
+    def getBeforeCommitHooks():
+        """Return iterable producing the registered beforeCommit hooks.
+
+        A triple (hook, args, kws) is produced for each registered hook.
+        The hooks are produced in the order in which they were registered.
+        """
+
 class ITransactionDeprecated(zope.interface.Interface):
     """Deprecated parts of the transaction API."""
 

Modified: ZODB/branches/3.4/src/transaction/tests/test_transaction.py
===================================================================
--- ZODB/branches/3.4/src/transaction/tests/test_transaction.py	2005-04-26 06:54:19 UTC (rev 30181)
+++ ZODB/branches/3.4/src/transaction/tests/test_transaction.py	2005-04-26 13:03:07 UTC (rev 30182)
@@ -419,6 +419,12 @@
       >>> t = transaction.begin()
       >>> t.beforeCommitHook(hook, '1')
 
+    We can see that the hook is indeed registered.
+
+      >>> [(hook.func_name, args, kws)
+      ...  for hook, args, kws in t.getBeforeCommitHooks()]
+      [('hook', ('1',), {})]
+
     When transaction commit starts, the hook is called, with its
     arguments.
 
@@ -432,6 +438,8 @@
     A hook's registration is consumed whenever the hook is called.  Since
     the hook above was called, it's no longer registered:
 
+      >>> len(list(t.getBeforeCommitHooks()))
+      0
       >>> transaction.commit()
       >>> log
       []
@@ -483,11 +491,21 @@
       ["arg '2' kw1 'no_kw1' kw2 'no_kw2'"]
       >>> reset_log()
 
-    If several hooks are defined, they are called in order.
+    Let's register several hooks.
 
       >>> t = transaction.begin()
       >>> t.beforeCommitHook(hook, '4', kw1='4.1')
       >>> t.beforeCommitHook(hook, '5', kw2='5.2')
+
+    They are returned in the same order by getBeforeCommitHooks.
+
+      >>> [(hook.func_name, args, kws)     #doctest: +NORMALIZE_WHITESPACE
+      ...  for hook, args, kws in t.getBeforeCommitHooks()]
+      [('hook', ('4',), {'kw1': '4.1'}),
+       ('hook', ('5',), {'kw2': '5.2'})]
+
+    And commit also calls them in this order.
+
       >>> t.commit()
       >>> len(log)
       2



More information about the Zodb-checkins mailing list