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

Modified Files:
      Tag: tseaver-hasattr_geddon-branch
        DT_InSV.py DT_String.py DT_Util.py DT_Var.py DT_With.py 
        pDocumentTemplate.py ustr.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/DocumentTemplate/DT_InSV.py 1.22 => 1.22.134.1 ===
--- Packages/DocumentTemplate/DT_InSV.py:1.22   Wed Aug 14 18:29:52 2002
+++ Packages/DocumentTemplate/DT_InSV.py        Sat May 28 20:41:30 2005
@@ -18,6 +18,7 @@
 
 from math import sqrt
 import re
+from ZODB.utils import safe_hasattr
 TupleType=type(())
 try:
     import Missing
@@ -354,7 +355,7 @@
             suffix=key[l+1:]
             prefix=key[:l]
 
-        if hasattr(self, suffix):
+        if safe_hasattr(self, suffix):
             try: v=data[prefix+'-index']
             except: pass
             else: return getattr(self,suffix)(v)


=== Packages/DocumentTemplate/DT_String.py 1.51 => 1.51.132.1 ===
--- Packages/DocumentTemplate/DT_String.py:1.51 Wed Aug 14 18:29:52 2002
+++ Packages/DocumentTemplate/DT_String.py      Sat May 28 20:41:30 2005
@@ -14,6 +14,7 @@
 
 import thread,re,exceptions,os
 
+from ZODB.utils import safe_hasattr
 from DT_Util import ParseError, InstanceDict, TemplateDict, render_blocks, str
 from DT_Var import Var, Call, Comment
 from DT_Return import ReturnTag, DTReturn
@@ -165,14 +166,14 @@
             if s: result.append(s)
             start=l+len(tag)
 
-            if hasattr(command,'blockContinuations'):
+            if safe_hasattr(command,'blockContinuations'):
                 start=self.parse_block(text, start, result, tagre,
                                        tag, l, args, command)
             else:
                 try:
                     if command is Var: r=command(args, self.varExtra(mo))
                     else: r=command(args)
-                    if hasattr(r,'simple_form'): r=r.simple_form
+                    if safe_hasattr(r,'simple_form'): r=r.simple_form
                     result.append(r)
                 except ParseError, m: self.parse_error(m[0],tag,text,l)
 
@@ -213,7 +214,7 @@
 
             if command:
                 start=l+len(tag)
-                if hasattr(command, 'blockContinuations'):
+                if safe_hasattr(command, 'blockContinuations'):
                     # New open tag.  Need to find closing tag.
                     start=self.parse_close(text, start, tagre, tag, l,
                                            command, args)
@@ -234,7 +235,7 @@
                 else:
                     try:
                         r=scommand(blocks)
-                        if hasattr(r,'simple_form'): r=r.simple_form
+                        if safe_hasattr(r,'simple_form'): r=r.simple_form
                         result.append(r)
                     except ParseError, m: self.parse_error(m[0],stag,text,l)
 
@@ -252,7 +253,7 @@
 
             start=l+len(tag)
             if command:
-                if hasattr(command, 'blockContinuations'):
+                if safe_hasattr(command, 'blockContinuations'):
                     # New open tag.  Need to find closing tag.
                     start=self.parse_close(text, start, tagre, tag, l,
                                            command,args)
@@ -404,9 +405,10 @@
         # print '============================================================'
 
         if mapping is None: mapping = {}
-        if hasattr(mapping, 'taintWrapper'): mapping = mapping.taintWrapper()
+        if safe_hasattr(mapping, 'taintWrapper'):
+            mapping = mapping.taintWrapper()
 
-        if not hasattr(self,'_v_cooked'):
+        if not safe_hasattr(self,'_v_cooked'):
             try: changed=self.__changed__()
             except: changed=1
             self.cook()


=== Packages/DocumentTemplate/DT_Util.py 1.89.12.2 => 1.89.12.2.22.1 ===
--- Packages/DocumentTemplate/DT_Util.py:1.89.12.2      Thu Apr 29 16:34:29 2004
+++ Packages/DocumentTemplate/DT_Util.py        Sat May 28 20:41:30 2005
@@ -18,6 +18,7 @@
 from RestrictedPython.Guards import safe_builtins
 from RestrictedPython.Utilities import utility_builtins
 from RestrictedPython.Eval import RestrictionCapableEval
+from ZODB.utils import safe_hasattr
 
 test = utility_builtins['test'] # for backwards compatibility, dont remove!
 
@@ -153,7 +154,7 @@
 
 def render(self, v):
     "Render an object in the way done by the 'name' attribute"
-    if hasattr(v, '__render_with_namespace__'):
+    if safe_hasattr(v, '__render_with_namespace__'):
         v = v.__render_with_namespace__(self)
     else:
         vbase = getattr(v, 'aq_base', v)


=== Packages/DocumentTemplate/DT_Var.py 1.59.12.1 => 1.59.12.1.30.1 ===
--- Packages/DocumentTemplate/DT_Var.py:1.59.12.1       Mon Nov 17 17:34:06 2003
+++ Packages/DocumentTemplate/DT_Var.py Sat May 28 20:41:30 2005
@@ -162,6 +162,7 @@
 from types import StringType
 from Acquisition import aq_base
 from ZPublisher.TaintedString import TaintedString
+from ZODB.utils import safe_hasattr
 
 class Var:
     name='var'
@@ -237,7 +238,7 @@
             fmt=args['fmt']
             if have_arg('null') and not val and val != 0:
                 try:
-                    if hasattr(val, fmt):
+                    if safe_hasattr(val, fmt):
                         val = _get(val, fmt)()
                     elif special_formats.has_key(fmt):
                         if fmt == 'html-quote' and \
@@ -255,14 +256,14 @@
                             val = fmt % val
                 except:
                     t, v= sys.exc_type, sys.exc_value
-                    if hasattr(sys, 'exc_info'): t, v = sys.exc_info()[:2]
+                    if safe_hasattr(sys, 'exc_info'): t, v = sys.exc_info()[:2]
                     if val is None or not str(val): return args['null']
                     raise t, v
 
             else:
                 # We duplicate the code here to avoid exception handler
                 # which tends to screw up stack or leak
-                if hasattr(val, fmt):
+                if safe_hasattr(val, fmt):
                     val = _get(val, fmt)()
                 elif special_formats.has_key(fmt):
                     if fmt == 'html-quote' and \


=== Packages/DocumentTemplate/DT_With.py 1.15 => 1.15.134.1 ===
--- Packages/DocumentTemplate/DT_With.py:1.15   Wed Aug 14 18:29:52 2002
+++ Packages/DocumentTemplate/DT_With.py        Sat May 28 20:41:30 2005
@@ -38,6 +38,7 @@
 
 from DT_Util import parse_params, name_param, InstanceDict, render_blocks, str
 from DT_Util import TemplateDict
+from ZODB.utils import safe_hasattr
 class With:
     blockContinuations=()
     name='with'
@@ -67,9 +68,9 @@
         if self.only:
             _md=md
             md=TemplateDict()
-            if hasattr(_md, 'guarded_getattr'):
+            if safe_hasattr(_md, 'guarded_getattr'):
                 md.guarded_getattr = _md.guarded_getattr
-            if hasattr(_md, 'guarded_getitem'):
+            if safe_hasattr(_md, 'guarded_getitem'):
                 md.guarded_getitem = _md.guarded_getitem
 
         md._push(v)


=== Packages/DocumentTemplate/pDocumentTemplate.py 1.41.44.1 => 1.41.44.1.22.1 
===
--- Packages/DocumentTemplate/pDocumentTemplate.py:1.41.44.1    Thu Apr 29 
16:34:29 2004
+++ Packages/DocumentTemplate/pDocumentTemplate.py      Sat May 28 20:41:30 2005
@@ -21,6 +21,7 @@
 import sys, types
 from types import StringType, UnicodeType, TupleType
 from ustr import ustr
+from ZODB.utils import safe_hasattr
 
 import warnings
 warnings.warn('pDocumentTemplate is not longer in active use. '
@@ -40,8 +41,8 @@
 
 def safe_callable(ob):
     # Works with ExtensionClasses and Acquisition.
-    if hasattr(ob, '__class__'):
-        if hasattr(ob, '__call__'):
+    if safe_hasattr(ob, '__class__'):
+        if safe_hasattr(ob, '__call__'):
             return 1
         else:
             return type(ob) in ClassTypes
@@ -61,7 +62,7 @@
         else: self.guarded_getattr = guarded_getattr
 
     def has_key(self,key):
-        return hasattr(self.self,key)
+        return safe_hasattr(self.self,key)
 
     def keys(self):
         return self.self.__dict__.keys()
@@ -147,7 +148,7 @@
 
         v = self.dicts[key]
         if call:
-            if hasattr(v, '__render_with_namespace__'):
+            if safe_hasattr(v, '__render_with_namespace__'):
                 return v.__render_with_namespace__(self)
             vbase = getattr(v, 'aq_base', v)
             if safe_callable(vbase):


=== Packages/DocumentTemplate/ustr.py 1.4 => 1.4.82.1 ===
--- Packages/DocumentTemplate/ustr.py:1.4       Mon Dec 16 18:19:07 2002
+++ Packages/DocumentTemplate/ustr.py   Sat May 28 20:41:30 2005
@@ -12,6 +12,7 @@
 ##############################################################################
 
 from types import StringType, UnicodeType, InstanceType
+from ZODB.utils import safe_hasattr
 
 nasty_exception_str = Exception.__str__.im_func
 
@@ -51,7 +52,7 @@
 
 
 def _exception_str(exc):
-    if hasattr(exc, 'args'):
+    if safe_hasattr(exc, 'args'):
         if not exc.args:
             return ''
         elif len(exc.args) == 1:

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

Reply via email to