[Zope-Checkins] CVS: Zope3/lib/python/Persistence - Function.py:1.3

Jeremy Hylton jeremy@zope.com
Sun, 23 Jun 2002 12:52:57 -0400


Update of /cvs-repository/Zope3/lib/python/Persistence
In directory cvs.zope.org:/tmp/cvs-serv9237

Modified Files:
	Function.py 
Log Message:
Change instance variables to use _pf_ prefix


=== Zope3/lib/python/Persistence/Function.py 1.2 => 1.3 ===
 
     def __init__(self, func, module):
-        self._func = func
-        self._module = module
-        self._code = {}
+        # Use _pf_ as the prefix to minimize the possibility that
+        # these attribute names will conflict with function attributes
+        # found in user code.  It would have been nice to use _p_
+        # since it's already an reserved attribute prefix, but the
+        # base persistent getattr function does not unghostify an
+        # object on refences to _p_ attributes.
+        self._pf_func = func
+        self._pf_module = module
+        self._pf_code = {}
 
     def __repr__(self):
-        return "<PersistentFunction %s.%s>" % (self._module.__name__,
-                                               self._func.func_name)
+        return "<PersistentFunction %s.%s>" % (self._pf_module.__name__,
+                                               self._pf_func.func_name)
 
     def __call__(self, *args, **kwargs):
         # We must make sure that _module is loaded when func is
@@ -39,43 +45,43 @@
         # variable and that global variable must be in the module's
         # __dict__.  We can't use a PersistentMapping because the
         # interpreter requires that globals be a real dict.
-
-        self._module._p_activate()
+        self._pf_module._p_activate()
         
         # XXX What if the function module is deactivated while the
         # function is executing?  It seems like we need to expose
         # refcounts at the Python level to guarantee that this will
         # work.
         
-        return self._func(*args, **kwargs)
+        return self._pf_func(*args, **kwargs)
 
     def __getstate__(self):
         # If func_dict is empty, store None to avoid creating a dict
         # unnecessarily when the function is unpickled
         # XXX new.function doesn't accept a closure
-        func_state = self._func.func_defaults, self._func.func_dict or None
+        func = self._pf_func
+        func_state = func.func_defaults, func.func_dict or None
 
         # Store the code separately from the function
-        code = self._func.func_code
+        code = func.func_code
 
         # The code object is can only be reused in an interpreter
         # running the same version of Python and with the same
         # __debug__ value.  Store code in a dict keyed by these two values.
 
         key = sys.version_info, __debug__
-        if key not in self._code:
-            self._code[key] = get_code_args(code)
+        if key not in self._pf_code:
+            self._pf_code[key] = get_code_args(code)
 
-        return func_state, self._code, self._module
+        return func_state, self._pf_code, self._pf_module
 
     def __setstate__(self, (func, code, mod)):
-        self._code = code
-        self._module = mod
+        self._pf_code = code
+        self._pf_module = mod
 
         # recreate the code object
         code = None
         key = sys.version_info, __debug__
-        co_args = self._code.get(key, None)
+        co_args = self._pf_code.get(key, None)
         if co_args is None:
             assert False, "not implemented yet"
         else:
@@ -85,4 +91,4 @@
         func = new.function(code, mod.__dict__, func_defaults)
         if func_dict:
             func.func_dict.update(func_dict)
-        self._func = func
+        self._pf_func = func