[Zodb-checkins] CVS: Zope/lib/python/ZODB - Mount.py:1.10.42.1

Shane Hathaway shane@digicool.com
Fri, 21 Dec 2001 14:21:45 -0500


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

Modified Files:
      Tag: Zope-2_4-branch
	Mount.py 
Log Message:
Backported Mount.py fixes.  Might help stability.


=== Zope/lib/python/ZODB/Mount.py 1.10 => 1.10.42.1 ===
+#
+# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
 # 
-# Zope Public License (ZPL) Version 1.0
-# -------------------------------------
-# 
-# Copyright (c) Digital Creations.  All rights reserved.
-# 
-# This license has been certified as Open Source(tm).
-# 
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are
-# met:
-# 
-# 1. Redistributions in source code must retain the above copyright
-#    notice, this list of conditions, and the following disclaimer.
-# 
-# 2. Redistributions in binary form must reproduce the above copyright
-#    notice, this list of conditions, and the following disclaimer in
-#    the documentation and/or other materials provided with the
-#    distribution.
-# 
-# 3. Digital Creations requests that attribution be given to Zope
-#    in any manner possible. Zope includes a "Powered by Zope"
-#    button that is installed by default. While it is not a license
-#    violation to remove this button, it is requested that the
-#    attribution remain. A significant investment has been put
-#    into Zope, and this effort will continue if the Zope community
-#    continues to grow. This is one way to assure that growth.
-# 
-# 4. All advertising materials and documentation mentioning
-#    features derived from or use of this software must display
-#    the following acknowledgement:
-# 
-#      "This product includes software developed by Digital Creations
-#      for use in the Z Object Publishing Environment
-#      (http://www.zope.org/)."
-# 
-#    In the event that the product being advertised includes an
-#    intact Zope distribution (with copyright and license included)
-#    then this clause is waived.
-# 
-# 5. Names associated with Zope or Digital Creations must not be used to
-#    endorse or promote products derived from this software without
-#    prior written permission from Digital Creations.
-# 
-# 6. Modified redistributions of any form whatsoever must retain
-#    the following acknowledgment:
-# 
-#      "This product includes software developed by Digital Creations
-#      for use in the Z Object Publishing Environment
-#      (http://www.zope.org/)."
-# 
-#    Intact (re-)distributions of any official Zope release do not
-#    require an external acknowledgement.
-# 
-# 7. Modifications are encouraged but must be packaged separately as
-#    patches to official Zope releases.  Distributions that do not
-#    clearly separate the patches from the original work must be clearly
-#    labeled as unofficial distributions.  Modifications which do not
-#    carry the name Zope may be packaged in any form, as long as they
-#    conform to all of the clauses above.
-# 
-# 
-# Disclaimer
-# 
-#   THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY
-#   EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-#   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-#   PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL DIGITAL CREATIONS OR ITS
-#   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-#   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-#   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
-#   USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-#   ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-#   OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
-#   OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-#   SUCH DAMAGE.
-# 
-# 
-# This software consists of contributions made by Digital Creations and
-# many individuals on behalf of Digital Creations.  Specific
-# attributions are listed in the accompanying credits file.
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (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
 # 
 ##############################################################################
 """Mounted database support
@@ -100,20 +28,18 @@
 # dblock is locked every time dbs is accessed.
 dblock=thread.allocate_lock()
 
-try:
-    # Make special provisions for ZClasses if we're in a Zope
-    # installation.
-    from Zope.ClassFactory import ClassFactory
-    
-    def RootDefsClassFactory(jar, module, name):
-        # Use the class definitions given at
-        # the root of the Zope installation.
-        while hasattr(jar, '_mount_parent_jar'):
-            jar = jar._mount_parent_jar
-        return ClassFactory(jar, module, name)
-except:
-    ClassFactory = None
-    RootDefsClassFactory = None
+
+def parentClassFactory(jar, module, name):
+    # Use the class factory from the parent database.
+    parent_db = getattr(getattr(jar, '_mount_parent_jar', None),
+                        '_db', None)
+    if parent_db is None:
+        _globals = {}
+        _silly = ('__doc__',)
+        return getattr(__import__(
+            module, _globals, _globals, _silly), name)
+    else:
+        return parent_db._classFactory(jar, module, name)
 
 
 class MountPoint(Persistence.Persistent, Acquisition.Implicit):
@@ -176,11 +102,8 @@
                 newMount = 1
                 dbs[params] = (db, {self.__mountpoint_id:1})
 
-                if RootDefsClassFactory is not None and \
-                   getattr(self, '_classDefsFromRoot', 1):
-                    db.setClassFactory(RootDefsClassFactory)
-                elif ClassFactory is not None:
-                    db.setClassFactory(ClassFactory)
+                if getattr(self, '_classDefsFromRoot', 1):
+                    db.setClassFactory(parentClassFactory)
             else:
                 db, mounts = dbInfo
                 # Be sure this object is in the list of mount points.
@@ -340,13 +263,14 @@
             self.mp = None
             # Detect whether we should close the database.
             close_db = self.close_db
-            t = mp._v_data
+            t = mp.__dict__.get('_v_data', None)
             if t is not None:
-                mp._v_data = None
+                del mp.__dict__['_v_data']
                 data = t[0]
-                if not close_db and getattr(data, '_v__object_deleted__', 0):
+                if not close_db and data.__dict__.get(
+                    '_v__object_deleted__', 0):
                     # This mount point has been deleted.
-                    del data._v__object_deleted__
+                    del data.__dict__['_v__object_deleted__']
                     close_db = 1
             # Close the child connection.
             try: del conn._mount_parent_jar