[Checkins] SVN: zc.zodbobjecteventsmp/branches/dev/ first cut

Jim Fulton jim at zope.com
Mon Oct 5 12:26:34 EDT 2009


Log message for revision 104801:
  first cut

Changed:
  U   zc.zodbobjecteventsmp/branches/dev/README.txt
  U   zc.zodbobjecteventsmp/branches/dev/buildout.cfg
  U   zc.zodbobjecteventsmp/branches/dev/setup.py
  A   zc.zodbobjecteventsmp/branches/dev/src/zc/zodbobjecteventsmp/
  A   zc.zodbobjecteventsmp/branches/dev/src/zc/zodbobjecteventsmp/README.txt
  A   zc.zodbobjecteventsmp/branches/dev/src/zc/zodbobjecteventsmp/__init__.py
  A   zc.zodbobjecteventsmp/branches/dev/src/zc/zodbobjecteventsmp/tests.py

-=-
Modified: zc.zodbobjecteventsmp/branches/dev/README.txt
===================================================================
--- zc.zodbobjecteventsmp/branches/dev/README.txt	2009-10-05 16:19:57 UTC (rev 104800)
+++ zc.zodbobjecteventsmp/branches/dev/README.txt	2009-10-05 16:26:33 UTC (rev 104801)
@@ -1,14 +1,15 @@
-Title Here
-**********
+Experimental Monkey Patch to Subscribe to invalidations
+=======================================================
 
+Sometimes, we wanna know when objects change.  zc.zodbobjecteventsmp
+provides a monkey patch that let's us do this.
 
-To learn more, see
+Eventually, ZODB will grow a built-in hook for this.
 
-
 Changes
 *******
 
-0.1 (yyyy-mm-dd)
-================
+0.1.0 (2009-10-05)
+==================
 
 Initial release

Modified: zc.zodbobjecteventsmp/branches/dev/buildout.cfg
===================================================================
--- zc.zodbobjecteventsmp/branches/dev/buildout.cfg	2009-10-05 16:19:57 UTC (rev 104800)
+++ zc.zodbobjecteventsmp/branches/dev/buildout.cfg	2009-10-05 16:26:33 UTC (rev 104801)
@@ -4,7 +4,7 @@
 
 [test]
 recipe = zc.recipe.testrunner
-eggs = 
+eggs = zc.zodbobjecteventsmp
 
 [py]
 recipe = zc.recipe.egg

Modified: zc.zodbobjecteventsmp/branches/dev/setup.py
===================================================================
--- zc.zodbobjecteventsmp/branches/dev/setup.py	2009-10-05 16:19:57 UTC (rev 104800)
+++ zc.zodbobjecteventsmp/branches/dev/setup.py	2009-10-05 16:26:33 UTC (rev 104801)
@@ -11,9 +11,9 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
-name, version = 'zc.', '0'
+name, version = 'zc.zodbobjecteventsmp', '0'
 
-install_requires = ['setuptools']
+install_requires = ['setuptools', 'ZODB3']
 extras_require = dict(test=['zope.testing'])
 
 entry_points = """

Added: zc.zodbobjecteventsmp/branches/dev/src/zc/zodbobjecteventsmp/README.txt
===================================================================
--- zc.zodbobjecteventsmp/branches/dev/src/zc/zodbobjecteventsmp/README.txt	                        (rev 0)
+++ zc.zodbobjecteventsmp/branches/dev/src/zc/zodbobjecteventsmp/README.txt	2009-10-05 16:26:33 UTC (rev 104801)
@@ -0,0 +1,55 @@
+Experimental Monkey Patch to Subscribe to invalidations
+=======================================================
+
+Sometimes, we wanna know when objects change.  zc.zodbobjecteventsmp
+provides a monkey patch that let's us do this.  Let's create a
+database and patch it.
+
+    >>> import ZODB.utils, ZODB.tests.util, transaction
+    >>> db = ZODB.tests.util.DB()
+
+
+To be notified of changes, we need to provide a function that takes a
+tid and iterable of object ids:
+
+    >>> def notify(tid, oids):
+    ...     # check that the tids are right:
+    ...     conn = db.open()
+    ...     for oid in oids:
+    ...         if not conn.get(oid)._p_serial != tid:
+    ...             print 'oops'
+    ...     print 'changed', sorted(ZODB.utils.u64(oid) for oid in oids)
+
+    >>> import zc.zodbobjecteventsmp
+    >>> zc.zodbobjecteventsmp.patch(db, notify)
+
+    >>> conn = db.open()
+    >>> conn.root.x = conn.root().__class__()
+    >>> conn.root.y = conn.root().__class__()
+    >>> transaction.commit()
+    changed [0]
+
+Note that we're not told about new objects.
+
+    >>> conn.root.x.x = 1
+    >>> conn.root.y.x = 1
+    >>> transaction.commit()
+    changed [1, 2]
+
+Other databases aren't affected:
+
+    >>> db = ZODB.tests.util.DB()
+    >>> conn = db.open()
+    >>> conn.root.x = conn.root().__class__()
+    >>> conn.root.y = conn.root().__class__()
+    >>> transaction.commit()
+    >>> conn.root.x.x = 1
+    >>> conn.root.y.x = 1
+    >>> transaction.commit()
+
+    >>> db.close()
+
+Typically, you'll be interested in a particular set of objects.  To
+look for changes in a specific set, you'd keep track of the set by oid
+and dispatch to an app-level function only when invalidated oids are
+in the set.


Property changes on: zc.zodbobjecteventsmp/branches/dev/src/zc/zodbobjecteventsmp/README.txt
___________________________________________________________________
Added: svn:eol-style
   + native

Added: zc.zodbobjecteventsmp/branches/dev/src/zc/zodbobjecteventsmp/__init__.py
===================================================================
--- zc.zodbobjecteventsmp/branches/dev/src/zc/zodbobjecteventsmp/__init__.py	                        (rev 0)
+++ zc.zodbobjecteventsmp/branches/dev/src/zc/zodbobjecteventsmp/__init__.py	2009-10-05 16:26:33 UTC (rev 104801)
@@ -0,0 +1,27 @@
+##############################################################################
+#
+# Copyright (c) Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+
+# Monkey-patch that provides tracking of object modifications
+
+def patch(db, func):
+    """Monkey patch a database to call the given function.
+
+    When invalidations occur, the fnction will be called with a tid
+    and list of oids.
+    """
+    original = db.invalidate
+    def invalidate(tid, oids, connection=None, version=''):
+        original(tid, oids, connection, version)
+        func(tid, oids)
+    db.invalidate = invalidate


Property changes on: zc.zodbobjecteventsmp/branches/dev/src/zc/zodbobjecteventsmp/__init__.py
___________________________________________________________________
Added: svn:keywords
   + Id
Added: svn:eol-style
   + native

Added: zc.zodbobjecteventsmp/branches/dev/src/zc/zodbobjecteventsmp/tests.py
===================================================================
--- zc.zodbobjecteventsmp/branches/dev/src/zc/zodbobjecteventsmp/tests.py	                        (rev 0)
+++ zc.zodbobjecteventsmp/branches/dev/src/zc/zodbobjecteventsmp/tests.py	2009-10-05 16:26:33 UTC (rev 104801)
@@ -0,0 +1,22 @@
+##############################################################################
+#
+# Copyright (c) Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+
+import unittest
+from zope.testing import doctest
+
+def test_suite():
+    return unittest.TestSuite((
+        doctest.DocFileSuite('README.txt'),
+        ))
+


Property changes on: zc.zodbobjecteventsmp/branches/dev/src/zc/zodbobjecteventsmp/tests.py
___________________________________________________________________
Added: svn:keywords
   + Id
Added: svn:eol-style
   + native



More information about the checkins mailing list