[Zope-Checkins] CVS: Zope/lib/python/Products/ExternalMethod - ExternalMethod.py:1.45.16.1

Jim Fulton jim@zope.com
Mon, 22 Apr 2002 18:49:16 -0400


Update of /cvs-repository/Zope/lib/python/Products/ExternalMethod
In directory cvs.zope.org:/tmp/cvs-serv7350

Modified Files:
      Tag: Zope-2_5-branch
	ExternalMethod.py 
Log Message:
Fixed bug: External methods pickled function code and globals, which
was really stupid. It caused problems because func_defaults might
be non-unpicklable (e.g. includes somemodule.rfind).

Added simple unit test to allow me to fix the bug.



=== Zope/lib/python/Products/ExternalMethod/ExternalMethod.py 1.45 => 1.45.16.1 ===
     """
 
-    meta_type='External Method'
-    func_defaults=()
-    func_code=None
+    meta_type = 'External Method'
+    _v_func_defaults = ()
+    _v_func_code = None
 
     ZopeTime=Acquisition.Acquired
     HelpSys=Acquisition.Acquired
@@ -137,17 +137,10 @@
         f=getObject(self._module, self._function, reload)
         if hasattr(f,'im_func'): ff=f.im_func
         else: ff=f
-           
-        if check:
-            # Check to make sure function signature is the same.
-            # Otherwise, we may end up causing an unwanted change.
 
-            if self.func_defaults != ff.func_defaults:
-                self.func_defaults  = ff.func_defaults
-            
-            func_code=FuncCode(ff,f is not ff)
-            if func_code != self.func_code: self.func_code=func_code
-    
+        self._v_func_defaults  = ff.func_defaults
+        self._v_func_code = FuncCode(ff,f is not ff)
+          
         self._v_f=f
 
         return f
@@ -197,15 +190,15 @@
             f=self._v_f
         else: f=self.getFunction()
 
-        __traceback_info__=args, kw, self.func_defaults
+        __traceback_info__=args, kw, self._v_func_defaults
 
         try: return apply(f,args,kw)
         except TypeError, v:
             tb=sys.exc_info()[2]
             try:
-                if ((self.func_code.co_argcount-
-                     len(self.func_defaults or ()) - 1 == len(args))
-                    and self.func_code.co_varnames[0]=='self'):
+                if ((self._v_func_code.co_argcount-
+                     len(self._v_func_defaults or ()) - 1 == len(args))
+                    and self._v_func_code.co_varnames[0]=='self'):
                     return apply(f,(self.aq_parent.this(),)+args,kw)
                 
                 raise TypeError, v, tb