[Zodb-checkins] SVN: ZODB/trunk/ Merge of r30182 in the 3.4 branch:

Florent Guillaume fg at nuxeo.com
Tue Apr 26 09:10:25 EDT 2005


Log message for revision 30183:
  Merge of r30182 in the 3.4 branch:
  
  A ``getBeforeCommitHooks()`` method has been added to Transaction. It
  returns an iterable producing the registered beforeCommit hooks.
  

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

-=-
Modified: ZODB/trunk/NEWS.txt
===================================================================
--- ZODB/trunk/NEWS.txt	2005-04-26 13:03:07 UTC (rev 30182)
+++ ZODB/trunk/NEWS.txt	2005-04-26 13:10:25 UTC (rev 30183)
@@ -2,6 +2,8 @@
 ==========================
 Release date: DD-MMM-YYYY
 
+A ``getBeforeCommitHooks()`` method has been added to Transaction. It
+returns an iterable producing the registered beforeCommit hooks.
 
 What's new in ZODB3 3.4a5?
 ==========================

Modified: ZODB/trunk/src/transaction/_transaction.py
===================================================================
--- ZODB/trunk/src/transaction/_transaction.py	2005-04-26 13:03:07 UTC (rev 30182)
+++ ZODB/trunk/src/transaction/_transaction.py	2005-04-26 13:10:25 UTC (rev 30183)
@@ -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/trunk/src/transaction/interfaces.py
===================================================================
--- ZODB/trunk/src/transaction/interfaces.py	2005-04-26 13:03:07 UTC (rev 30182)
+++ ZODB/trunk/src/transaction/interfaces.py	2005-04-26 13:10:25 UTC (rev 30183)
@@ -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/trunk/src/transaction/tests/test_transaction.py
===================================================================
--- ZODB/trunk/src/transaction/tests/test_transaction.py	2005-04-26 13:03:07 UTC (rev 30182)
+++ ZODB/trunk/src/transaction/tests/test_transaction.py	2005-04-26 13:10:25 UTC (rev 30183)
@@ -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