[Zope-Checkins] CVS: Products/ExternalMethod - ExternalMethod.py:1.51.68.2.22.1

Tres Seaver tseaver at palladion.com
Sat May 28 20:42:12 EDT 2005


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

Modified Files:
      Tag: tseaver-hasattr_geddon-branch
	ExternalMethod.py 
Log Message:

  - Removed all uses of the 'hasattr' builtin from the core, where
    the object being tested derives (or might) from Persistent.
    XXX:  currently, this branch imports a 'safe_hasattr' from ZODB.utils,
    which adds a dependency on ZODB for some packages;  we probably
    need a better location, and perhas a C implementation?


=== Products/ExternalMethod/ExternalMethod.py 1.51.68.2 => 1.51.68.2.22.1 ===
--- Products/ExternalMethod/ExternalMethod.py:1.51.68.2	Thu Jul  1 02:22:46 2004
+++ Products/ExternalMethod/ExternalMethod.py	Sat May 28 20:41:31 2005
@@ -25,6 +25,7 @@
 from Globals import DevelopmentMode
 from App.Management import Navigation
 from ComputedAttribute import ComputedAttribute
+from ZODB.utils import safe_hasattr
 
 manage_addExternalMethodForm=DTMLFile('dtml/methodAdd', globals())
 
@@ -139,8 +140,10 @@
     def getFunction(self, reload=0):
 
         f=getObject(self._module, self._function, reload)
-        if hasattr(f,'im_func'): ff=f.im_func
-        else: ff=f
+        if safe_hasattr(f,'im_func'):
+            ff=f.im_func
+        else:
+            ff=f
 
         self._v_func_defaults  = ff.func_defaults
         self._v_func_code = FuncCode(ff,f is not ff)
@@ -152,7 +155,7 @@
     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
+        if (not safe_hasattr(self, '_v_last_read') or
             (ts != self._v_last_read)):
             self._v_f=self.getFunction(1)
             self._v_last_read=ts
@@ -162,23 +165,23 @@
         # if the module code changed
         def getFuncDefaults(self):
             self.reloadIfChanged()
-            if not hasattr(self, '_v_func_defaults'):
+            if not safe_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'):
+            if not safe_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'):
+            if not safe_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'):
+            if not safe_hasattr(self, '_v_func_code'):
                 self._v_f = self.getFunction()
             return self._v_func_code
 
@@ -215,7 +218,7 @@
         if DevelopmentMode:
             self.reloadIfChanged()
 
-        if hasattr(self, '_v_f'):
+        if safe_hasattr(self, '_v_f'):
             f=self._v_f
         else:
             f=self.getFunction()
@@ -239,7 +242,7 @@
     def module(self): return self._module
 
     def filepath(self):
-        if not hasattr(self, '_v_filepath'):
+        if not safe_hasattr(self, '_v_filepath'):
             self._v_filepath=getPath('Extensions', self._module,
                                      suffixes=('','py','pyc','pyp'))
         return self._v_filepath



More information about the Zope-Checkins mailing list