[Zodb-checkins] CVS: Zope/lib/python/ZODB - DB.py:1.37

Brian Lloyd brian@zope.com
Wed, 9 Jan 2002 13:54:21 -0500


Update of /cvs-repository/Zope/lib/python/ZODB
In directory cvs.zope.org:/tmp/cvs-serv27592

Modified Files:
	DB.py 
Log Message:
Merged '__module__' dependency fix from Zope 2.5 branch.


=== Zope/lib/python/ZODB/DB.py 1.36 => 1.37 ===
-#
+# 
 # Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
 # 
 # This software is subject to the provisions of the Zope Public License,
@@ -72,20 +72,15 @@
         self._storage=storage
         storage.registerDB(self, None)
         if not hasattr(storage,'tpc_vote'): storage.tpc_vote=lambda *args: None
-        try:
-            storage.load('\0\0\0\0\0\0\0\0','')
-        except KeyError:
-            # Create the database's root in the storage if it doesn't exist
+        try: storage.load('\0\0\0\0\0\0\0\0','')
+        except:
             import PersistentMapping
-            root = PersistentMapping.PersistentMapping()
-            # Manually create a pickle for the root to put in the storage.
-            # The pickle must be in the special ZODB format.
-            file = cStringIO.StringIO()
-            p = cPickle.Pickler(file, 1)
-            p.dump((root.__class__, None))
-            p.dump(root.__getstate__())
-            t = Transaction()
-            t.description = 'initial database creation'
+            file=cStringIO.StringIO()
+            p=cPickle.Pickler(file,1)
+            p.dump((PersistentMapping.PersistentMapping,None))
+            p.dump({'_container': {}})
+            t=Transaction()
+            t.description='initial database creation'
             storage.tpc_begin(t)
             storage.store('\0\0\0\0\0\0\0\0', None, file.getvalue(), '', t)
             storage.tpc_vote(t)
@@ -159,7 +154,9 @@
         detail={}
         def f(con,detail=detail,have_detail=detail.has_key):
             for oid, ob in con._cache.items():
-                c="%s.%s" % (ob.__class__.__module__, ob.__class__.__name__)
+                module = getattr(ob.__class__, '__module__', '')
+                module = module and '%s.' % module or ''
+                c="%s%s" % (module, ob.__class__.__name__)
                 if have_detail(c): detail[c]=detail[c]+1
                 else: detail[c]=1
         
@@ -182,13 +179,15 @@
                         id=d['id']
                     elif d.has_key('__name__'):
                         id=d['__name__']
-    
+
+                module = getattr(ob.__class__, '__module__', '')
+                module = module and '%s.' % module or ''
+
                 detail.append({
                     'conn_no': cn,
                     'oid': oid,
                     'id': id,
-                    'klass': "%s.%s" % (ob.__class__.__module__,
-                                        ob.__class__.__name__),
+                    'klass': "%s%s" % (module, ob.__class__.__name__),
                     'rc': rc(ob)-4,
                     'state': ob._p_changed,
                     #'references': con.references(oid),