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

Jeremy Hylton jeremy@zope.com
Mon, 24 Jun 2002 15:04:30 -0400


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

Modified Files:
	Function.py 
Log Message:
Add handlers for function attributes.


=== Zope3/lib/python/Persistence/Function.py 1.3 => 1.4 ===
                                                self._pf_func.func_name)
 
+    # We need attribute hooks to handle access to _pf_ attributes in a
+    # special way.  All other attributes should be looked up on
+    # _pf_func.
+
+    def __getattr__(self, attr):
+        # If it wasn't found in __dict__, then it must be a function
+        # attribute.
+        return getattr(self._pf_func, attr)
+
+    def __setattr__(self, attr, value):
+        if not self._p_setattr(attr, value):
+            # the persistence machinery didn't handle this attribute,
+            # it must be ours
+            if attr.startswith('_pf_'):
+                self.__dict__[attr] = value
+            else:
+                setattr(self._pf_func, attr, value)
+
+    def __delattr__(self, attr):
+        if not self._p_delattr(attr):
+            # the persistence machinery didn't handle this attribute,
+            # it must be ours
+            if attr.startswith('_pf_'):
+                del self.__dict__[attr]
+            else:
+                delattr(self._pf_func, attr)
+
     def __call__(self, *args, **kwargs):
         # We must make sure that _module is loaded when func is
         # executed because the function may reference a global