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

Casey Duncan casey@zope.com
Fri, 24 May 2002 15:23:51 -0400


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

Modified Files:
      Tag: Zope-2_5-branch
	ExternalMethod.py 
Log Message:
backported external method bug fix from trunk


=== Zope/lib/python/Products/ExternalMethod/ExternalMethod.py 1.45.16.2 => 1.45.16.3 ===
 from Globals import Persistent, DTMLFile, MessageDialog, HTML
 import OFS.SimpleItem, Acquisition
-from string import split, join, find, lower
 import AccessControl.Role, sys, os, stat, traceback
 from OFS.SimpleItem import pretty_tb
 from App.Extensions import getObject, getPath, FuncCode
@@ -81,8 +80,9 @@
 
     meta_type = 'External Method'
 
-    func_defaults = ComputedAttribute(lambda self: self._v_func_defaults)
-    func_code = ComputedAttribute(lambda self: self._v_func_code)
+    func_defaults = ComputedAttribute(lambda self: self.getFuncDefaults())
+    func_code = ComputedAttribute(lambda self: self.getFuncCode())
+
 
     ZopeTime=Acquisition.Acquired
     HelpSys=Acquisition.Acquired
@@ -142,12 +142,43 @@
 
         self._v_func_defaults  = ff.func_defaults
         self._v_func_code = FuncCode(ff,f is not ff)
-          
+ 
         self._v_f=f
 
         return f
 
-
+    def reloadIfChanged(self):
+        # If the file has been modified since last loaded, force a reload.
+        ts=os.stat(self.filepath())[stat.ST_MTIME]
+        if (not hasattr(self, '_v_last_read') or 
+            (ts != self._v_last_read)):
+            self._v_f=self.getFunction(1)
+            self._v_last_read=ts
+
+    if DevelopmentMode:
+        # In development mode we do an automatic reload 
+        # if the module code changed
+        def getFuncDefaults(self):
+            self.reloadIfChanged()
+            if not hasattr(self, '_v_func_defaults'):
+                self._v_f = self.getFunction()
+            return self._v_func_defaults
+
+        def getFuncCode(self):
+            self.reloadIfChanged()
+            if not hasattr(self, '_v_func_code'):
+                self._v_f = self.getFunction()
+            return self._v_func_code
+    else:
+        def getFuncDefaults(self):
+            if not hasattr(self, '_v_func_defaults'):
+                self._v_f = self.getFunction()
+            return self._v_func_defaults
+
+        def getFuncCode(self):
+            if not hasattr(self, '_v_func_code'):
+                self._v_f = self.getFunction()
+            return self._v_func_code
 
     def __call__(self, *args, **kw):
         """Call an ExternalMethod
@@ -179,14 +210,8 @@
                 "external method could not be called " \
                 "because the file does not exist"
             
-
         if DevelopmentMode:
-            # If the file has been modified since last loaded, force a reload.
-            ts=os.stat(self.filepath())[stat.ST_MTIME]
-            if (not hasattr(self, '_v_last_read') or 
-                (ts != self._v_last_read)):
-                self._v_f=self.getFunction(1)
-                self._v_last_read=ts
+            self.reloadIfChanged()
 
         if hasattr(self, '_v_f'):
             f=self._v_f