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

Modified Files:
      Tag: tseaver-hasattr_geddon-branch
        APIHelpTopic.py HelpSys.py HelpUtil.py ObjectRef.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?


=== Packages/HelpSys/APIHelpTopic.py 1.15.68.2 => 1.15.68.2.22.1 ===
--- Packages/HelpSys/APIHelpTopic.py:1.15.68.2  Tue May  4 15:09:00 2004
+++ Packages/HelpSys/APIHelpTopic.py    Sat May 28 20:41:30 2005
@@ -21,6 +21,7 @@
 from Globals import DTMLFile
 from Globals import InitializeClass
 from Globals import Persistent
+from ZODB.utils import safe_hasattr
 
 import HelpTopic
 
@@ -55,7 +56,7 @@
                 if type(v)==types.ClassType:
                     # A class.
                     self.apis.append(APIDoc(v, 0))
-                elif (hasattr(v, 'isImplementedByInstancesOf')):
+                elif (safe_hasattr(v, 'isImplementedByInstancesOf')):
                     # A scarecrow interface.
                     self.apis.append(APIDoc(v, 1))
                 elif type(v)==types.FunctionType:
@@ -120,7 +121,7 @@
 ##            self.extends.append((names[2], url))
 
         # constructor information
-##        if hasattr(klass, '__constructor__'):
+##        if safe_hasattr(klass, '__constructor__'):
 ##            self.constructor=MethodDoc(klass.__constructor__)
 
         # Get info on methods and attributes, ignore special items
@@ -128,7 +129,7 @@
         self.methods=[]
         from Interface.Method import Method
         for k,v in klass.namesAndDescriptions():
-            if hasattr(v, 'getSignatureInfo'):
+            if safe_hasattr(v, 'getSignatureInfo'):
                 self.methods.append(MethodDoc(v, 1))
             else:
                 self.attributes.append(AttributeDoc(k, v.__doc__))
@@ -148,7 +149,7 @@
         self.doc=trim_doc_string(klass.__doc__)
 
         # inheritence information
-        if hasattr(klass,'__extends__'):
+        if safe_hasattr(klass,'__extends__'):
             self.extends=[]
             for base in klass.__extends__:
                 names=base.split( '.')
@@ -156,7 +157,7 @@
                 self.extends.append((names[2], url))
 
         # constructor information
-        if hasattr(klass, '__constructor__'):
+        if safe_hasattr(klass, '__constructor__'):
             self.constructor=MethodDoc(klass.__constructor__)
 
         # Get info on methods and attributes, ignore special items
@@ -238,7 +239,7 @@
             self.kwargs = func.kwargs
 
     def _createFromFunc(self, func):
-        if hasattr(func, 'im_func'):
+        if safe_hasattr(func, 'im_func'):
             func=func.im_func
 
         self.name=func.__name__


=== Packages/HelpSys/HelpSys.py 1.24.68.2 => 1.24.68.2.24.1 ===
--- Packages/HelpSys/HelpSys.py:1.24.68.2       Tue Apr 13 02:00:17 2004
+++ Packages/HelpSys/HelpSys.py Sat May 28 20:41:30 2005
@@ -17,6 +17,7 @@
 from Globals import Persistent, DTMLFile, HTML
 from Products.ZCatalog.ZCatalog import ZCatalog
 from Products.ZCatalog.Lazy import LazyCat
+from ZODB.utils import safe_hasattr
 from cgi import escape
 import Products
 import HelpTopic
@@ -255,7 +256,7 @@
         dtmltopics=[]
         zpttopics=[]
         for topic in self.objectValues('Help Topic'):
-            if hasattr(topic,'isAPIHelpTopic') and topic.isAPIHelpTopic:
+            if safe_hasattr(topic,'isAPIHelpTopic') and topic.isAPIHelpTopic:
                 apitopics.append(topic)
             else:
                 try:


=== Packages/HelpSys/HelpUtil.py 1.12 => 1.12.132.1 ===
--- Packages/HelpSys/HelpUtil.py:1.12   Wed Aug 14 17:34:42 2002
+++ Packages/HelpSys/HelpUtil.py        Sat May 28 20:41:30 2005
@@ -17,6 +17,7 @@
 
 import Globals, Acquisition
 import StructuredText.StructuredText
+from ZODB.utils import safe_hasattr
 import sys, os,  re
 
 
@@ -62,7 +63,7 @@
         return self._obj_
 
     def get_docstring(self):
-        if hasattr(self._obj_, '__doc__'):
+        if safe_hasattr(self._obj_, '__doc__'):
             doc=self._obj_.__doc__
             if not doc: doc=''
             return doc
@@ -79,7 +80,7 @@
         return str(stx_class(doc))
 
     def version(self):
-        if hasattr(self._obj_, '__version__'):
+        if safe_hasattr(self._obj_, '__version__'):
             return self._obj_.__version__
 
     tpId   =get_name
@@ -89,7 +90,7 @@
 
 class moduleobject(object):
     def get_file(self):
-        if hasattr(self._obj_, '__file__'):
+        if safe_hasattr(self._obj_, '__file__'):
             return self._obj_.__file__
 
     def get_modules(self):
@@ -115,7 +116,7 @@
             return '%s %s' % (t, v)
 
     def get_module(self):
-        if hasattr(self._obj_, '__module__'):
+        if safe_hasattr(self._obj_, '__module__'):
             module=sys.modules[self._obj_.__module__]
             return moduleobject(module.__name__, module)
 
@@ -124,7 +125,7 @@
 
     def get_bases(self):
         bases=[]
-        if hasattr(self._obj_, '__bases__'):
+        if safe_hasattr(self._obj_, '__bases__'):
             for base in self._obj_.__bases__:
                 bases.append(classobject(base.__name__, base))
         return bases
@@ -228,14 +229,14 @@
     def get_docstring(self):
         func=self._obj_
         doc=''
-        if hasattr(func, 'im_func'):
+        if safe_hasattr(func, 'im_func'):
             func=func.im_func
-        if hasattr(func, '__doc__'):
+        if safe_hasattr(func, '__doc__'):
             doc=func.__doc__
             if not doc: doc=''
             doc=doc.strip()
-        if hasattr(func, 'func_code'):
-            if hasattr(func.func_code, 'co_varnames'):
+        if safe_hasattr(func, 'func_code'):
+            if safe_hasattr(func.func_code, 'co_varnames'):
                 return doc
         mo=pre_match(doc)
         if mo is not None:
@@ -247,13 +248,13 @@
         func=self._obj_
         method=None
 
-        if hasattr(func, 'im_func'):
+        if safe_hasattr(func, 'im_func'):
             method=1
             func=func.im_func
 
         # Normal functions
-        if hasattr(func, 'func_code'):
-            if hasattr(func.func_code, 'co_varnames'):
+        if safe_hasattr(func, 'func_code'):
+            if safe_hasattr(func.func_code, 'co_varnames'):
                 args=map(lambda x: x,
                      func.func_code.co_varnames[:func.func_code.co_argcount])
                 ndefaults=func.func_defaults
@@ -272,7 +273,7 @@
 
         # Other functions - look for something that smells like
         # a signature at the beginning of the docstring.
-        if hasattr(func, '__doc__'):
+        if safe_hasattr(func, '__doc__'):
             doc=func.__doc__
             if not doc: doc=''
             doc=doc.strip()
@@ -390,7 +391,7 @@
     return type(ob) in _classtypes
 
 def is_method(ob):
-    if type(ob) in _methodtypes or hasattr(ob, 'func_code'):
+    if type(ob) in _methodtypes or safe_hasattr(ob, 'func_code'):
         return 1
     return 0
 


=== Packages/HelpSys/ObjectRef.py 1.10 => 1.10.132.1 ===
--- Packages/HelpSys/ObjectRef.py:1.10  Wed Aug 14 17:34:42 2002
+++ Packages/HelpSys/ObjectRef.py       Sat May 28 20:41:30 2005
@@ -19,6 +19,7 @@
 from HelpUtil import HelpBase, classobject
 from HelpUtil import is_class, is_module
 from Globals import DTMLFile
+from ZODB.utils import safe_hasattr
 from urllib import quote
 
 
@@ -63,10 +64,10 @@
         keys.sort()
         for key in keys:
             fn=mdict[key]
-            if not hasattr(fn._obj_, '__doc__'):
+            if not safe_hasattr(fn._obj_, '__doc__'):
                 continue
             doc=fn._obj_.__doc__
-            if hasattr(fn._obj_, '__class__') and \
+            if safe_hasattr(fn._obj_, '__class__') and \
                fn._obj_.__class__.__doc__ is doc:
                 continue
 
@@ -115,8 +116,8 @@
         hidden=('Control Panel', 'Principia Draft', 'simple item',
                 'Broken Because Product is Gone')
         for k, v in mod.__dict__.items():
-            if is_class(v) and hasattr(v, 'meta_type') and \
-               hasattr(v, '__ac_permissions__'):
+            if is_class(v) and safe_hasattr(v, 'meta_type') and \
+               safe_hasattr(v, '__ac_permissions__'):
                 if callable(v.meta_type):
                     try: meta_type=v.meta_type()
                     except:
@@ -125,7 +126,7 @@
                 else: meta_type=v.meta_type
                 if (meta_type is not None) and (meta_type not in hidden):
                     dict[meta_type]=ObjectItem(k, v)
-            if is_module(v) and hasattr(v, '__path__'):
+            if is_module(v) and safe_hasattr(v, '__path__'):
                 dict=self.hs_search_mod(v, dict)
         return dict
 

_______________________________________________
Zope-Checkins maillist  -  Zope-Checkins@zope.org
http://mail.zope.org/mailman/listinfo/zope-checkins

Reply via email to