[Zope3-checkins] CVS: ZODB4/Persistence - Class.py:1.11

Jeremy Hylton jeremy@zope.com
Thu, 12 Dec 2002 16:53:59 -0500


Update of /cvs-repository/ZODB4/Persistence
In directory cvs.zope.org:/tmp/cvs-serv23147/Persistence

Modified Files:
	Class.py 
Log Message:
Refine __getattribute__ in PersistentClassMetaClass.

Always check the _pc_init flag first.  If the persistent class isn't
initialized, don't bother looking for an _p_state instance variable.
It won't exist.  Also, make sure _p_state does get initialized before
_pc_init is set to True.


=== ZODB4/Persistence/Class.py 1.10 => 1.11 ===
--- ZODB4/Persistence/Class.py:1.10	Fri Nov 22 11:54:38 2002
+++ ZODB4/Persistence/Class.py	Thu Dec 12 16:53:58 2002
@@ -233,6 +233,7 @@
 
         extend_attr("_p_oid", None)
         extend_attr("_p_jar", None)
+        extend_attr("_p_state", UPTODATE)
         extend_meth("_p_activate", meta._p_activate)
         extend_meth("_p_deactivate", meta._p_activate)
         extend_meth("__getstate__", meta.__getstate__)
@@ -252,13 +253,20 @@
                 setattr(cls, k, PersistentFunction(v, mod))
 
     def __getattribute__(cls, name):
+        # XXX I'm not sure I understand this code any more.
+        super_meth = super(PersistentClassMetaClass, cls).__getattribute__
+
+        # If we are initializing the class, don't trying to check variables
+        # like _p_state, since they may not be initialized.
+        if not super_meth("_pc_init"):
+            return super_meth(name)
         if (name[0] == "_" and
             not (name.startswith("_p_") or name.startswith("_pc_") or
                  name == "__dict__")):
-            if cls._p_state is None:
+            if cls._p_state == GHOST:
                 cls._p_activate()
                 cls._p_atime = int(time.time() % 86400)
-        return super(PersistentClassMetaClass, cls).__getattribute__(name)
+        return super_meth(name)
 
     def __setattr__(cls, attr, val):
         if not attr.startswith("_pc_") and cls._pc_init: