[Zodb-checkins] SVN: ZODB/trunk/src/ Primary thrust here is to
teach ZODB about zope.interface,
Tim Peters
tim.one at comcast.net
Tue Jun 22 13:46:01 EDT 2004
Log message for revision 25940:
Primary thrust here is to teach ZODB about zope.interface,
and include that in the ZODB project. While we're at it,
include zope.testing too, as zope.interface depends on that,
and we had copied zope.testing.loggingsupport.py into ZODB
earlier anyway (and delete that unique copy here now).
This also merges some changes made to the ZODB copy in
Zope3 back into ZODB.
-=-
Modified: ZODB/trunk/src/ZODB/Connection.py
===================================================================
--- ZODB/trunk/src/ZODB/Connection.py 2004-06-22 17:32:32 UTC (rev 25939)
+++ ZODB/trunk/src/ZODB/Connection.py 2004-06-22 17:43:52 UTC (rev 25940)
@@ -35,6 +35,8 @@
from ZODB.TmpStore import TmpStore
from ZODB.utils import oid_repr, z64, positive_id
from ZODB.serialize import ObjectWriter, ConnectionObjectReader, myhasattr
+from ZODB.interfaces import IConnection
+from zope.interface import implements
global_reset_counter = 0
@@ -147,6 +149,7 @@
getTransferCounts
"""
+ implements(IConnection)
_tmp = None
_code_timestamp = 0
Modified: ZODB/trunk/src/ZODB/interfaces.py
===================================================================
--- ZODB/trunk/src/ZODB/interfaces.py 2004-06-22 17:32:32 UTC (rev 25939)
+++ ZODB/trunk/src/ZODB/interfaces.py 2004-06-22 17:43:52 UTC (rev 25940)
@@ -16,19 +16,10 @@
$Id$
"""
-try:
- from zope.interface import Interface, Attribute
-except ImportError:
- class Interface:
- pass
+import zope.interface
+from zope.interface import Attribute
- class Attribute:
- def __init__(self, __name__, __doc__):
- self.__name__ = __name__
- self.__doc__ = __doc__
-
-
-class IDataManager(Interface):
+class IDataManager(zope.interface.Interface):
"""Objects that manage transactional storage.
These object's may manage data for other objects, or they may manage
@@ -145,7 +136,7 @@
"""
-class ITransaction(Interface):
+class ITransaction(zope.interface.Interface):
"""Object representing a running transaction.
Objects with this interface may represent different transactions
@@ -224,3 +215,26 @@
"""
# XXX is this this allowed to cause an exception here, during
# the two-phase commit, or can it toss data silently?
+
+class IConnection(zope.interface.Interface):
+ """ZODB connection.
+
+ XXX: This interface is incomplete.
+ """
+
+ def add(ob):
+ """Add a new object 'obj' to the database and assign it an oid.
+
+ A persistent object is normally added to the database and
+ assigned an oid when it becomes reachable to an object already in
+ the database. In some cases, it is useful to create a new
+ object and use its oid (_p_oid) in a single transaction.
+
+ This method assigns a new oid regardless of whether the object
+ is reachable.
+
+ The object is added when the transaction commits. The object
+ must implement the IPersistent interface and must not
+ already be associated with a Connection.
+ """
+
Deleted: ZODB/trunk/src/ZODB/tests/loggingsupport.py
===================================================================
--- ZODB/trunk/src/ZODB/tests/loggingsupport.py 2004-06-22 17:32:32 UTC (rev 25939)
+++ ZODB/trunk/src/ZODB/tests/loggingsupport.py 2004-06-22 17:43:52 UTC (rev 25940)
@@ -1,122 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2004 Zope Corporation 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.
-#
-##############################################################################
-"""Support for testing logging code
-
-If you want to test that your code generates proper log output, you
-can create and install a handler that collects output:
-
- >>> handler = InstalledHandler('foo.bar')
-
-The handler is installed into loggers for all of the names passed. In
-addition, the logger level is set to 1, which means, log
-everything. If you want to log less than everything, you can provide a
-level keyword argument. The level setting effects only the named
-loggers.
-
-Then, any log output is collected in the handler:
-
- >>> logging.getLogger('foo.bar').exception('eek')
- >>> logging.getLogger('foo.bar').info('blah blah')
-
- >>> for record in handler.records:
- ... print record.name, record.levelname
- ... print ' ', record.getMessage()
- foo.bar ERROR
- eek
- foo.bar INFO
- blah blah
-
-A similar effect can be gotten by just printing the handler:
-
- >>> print handler
- foo.bar ERROR
- eek
- foo.bar INFO
- blah blah
-
-After checking the log output, you need to uninstall the handler:
-
- >>> handler.uninstall()
-
-At which point, the handler won't get any more log output.
-Let's clear the handler:
-
- >>> handler.clear()
- >>> handler.records
- []
-
-And then log something:
-
- >>> logging.getLogger('foo.bar').info('blah')
-
-and, sure enough, we still have no output:
-
- >>> handler.records
- []
-
-$Id$
-"""
-
-import logging
-
-class Handler(logging.Handler):
-
- def __init__(self, *names, **kw):
- logging.Handler.__init__(self)
- self.names = names
- self.records = []
- self.setLoggerLevel(**kw)
-
- def setLoggerLevel(self, level=1):
- self.level = level
- self.oldlevels = {}
-
- def emit(self, record):
- self.records.append(record)
-
- def clear(self):
- del self.records[:]
-
- def install(self):
- for name in self.names:
- logger = logging.getLogger(name)
- self.oldlevels[name] = logger.level
- logger.setLevel(self.level)
- logger.addHandler(self)
-
- def uninstall(self):
- for name in self.names:
- logger = logging.getLogger(name)
- logger.setLevel(self.oldlevels[name])
- logger.removeHandler(self)
-
- def __str__(self):
- return '\n'.join(
- [("%s %s\n %s" %
- (record.name, record.levelname,
- '\n'.join([line
- for line in record.getMessage().split('\n')
- if line.strip()])
- )
- )
- for record in self.records]
- )
-
-
-class InstalledHandler(Handler):
-
- def __init__(self, *names):
- Handler.__init__(self, *names)
- self.install()
-
Modified: ZODB/trunk/src/ZODB/tests/testConnection.py
===================================================================
--- ZODB/trunk/src/ZODB/tests/testConnection.py 2004-06-22 17:32:32 UTC (rev 25939)
+++ ZODB/trunk/src/ZODB/tests/testConnection.py 2004-06-22 17:43:52 UTC (rev 25940)
@@ -22,6 +22,7 @@
from ZODB.config import databaseFromString
from ZODB.utils import p64, u64
from ZODB.tests.warnhook import WarningsHook
+from zope.interface.verify import verifyObject
class ConnectionDotAdd(unittest.TestCase):
@@ -595,6 +596,15 @@
return None
+class TestConnectionInterface(unittest.TestCase):
+
+ def test_connection_interface(self):
+ from ZODB.interfaces import IConnection
+ db = databaseFromString("<zodb>\n<mappingstorage/>\n</zodb>")
+ cn = db.open()
+ verifyObject(IConnection, cn)
+
+
class StubDatabase:
def __init__(self):
@@ -608,4 +618,5 @@
def test_suite():
s = unittest.makeSuite(ConnectionDotAdd, 'check')
s.addTest(doctest.DocTestSuite())
+ s.addTest(unittest.makeSuite(TestConnectionInterface))
return s
Modified: ZODB/trunk/src/ZODB/tests/testFileStorage.py
===================================================================
--- ZODB/trunk/src/ZODB/tests/testFileStorage.py 2004-06-22 17:32:32 UTC (rev 25939)
+++ ZODB/trunk/src/ZODB/tests/testFileStorage.py 2004-06-22 17:43:52 UTC (rev 25940)
@@ -227,7 +227,7 @@
>>> from ZODB.FileStorage import FileStorage
>>> from ZODB.DB import DB
>>> import transaction
- >>> from ZODB.tests.loggingsupport import InstalledHandler
+ >>> from zope.testing.loggingsupport import InstalledHandler
Arrange to capture log messages -- they're an important part of
this test!
Added: ZODB/trunk/src/zope/__init__.py
===================================================================
--- ZODB/trunk/src/zope/__init__.py 2004-06-22 17:32:32 UTC (rev 25939)
+++ ZODB/trunk/src/zope/__init__.py 2004-06-22 17:43:52 UTC (rev 25940)
@@ -0,0 +1 @@
+# Empty __init__ to make this a package.
Property changes on: ZODB/trunk/src/zope/__init__.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied: ZODB/trunk/src/zope/interface (from rev 25936, Zope3/trunk/src/zope/interface)
Copied: ZODB/trunk/src/zope/testing (from rev 25936, Zope3/trunk/src/zope/testing)
More information about the Zodb-checkins
mailing list