[Zope-Checkins] CVS: Products/PageTemplates - Expressions.py:1.43.44.5.2.1 PageTemplate.py:1.30.10.1.32.1 PageTemplateFile.py:1.28.4.2.30.1

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


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

Modified Files:
      Tag: tseaver-hasattr_geddon-branch
	Expressions.py PageTemplate.py PageTemplateFile.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/PageTemplates/Expressions.py 1.43.44.5 => 1.43.44.5.2.1 ===
--- Products/PageTemplates/Expressions.py:1.43.44.5	Fri Mar 25 14:39:03 2005
+++ Products/PageTemplates/Expressions.py	Sat May 28 20:41:32 2005
@@ -23,6 +23,7 @@
 from TALES import Engine, CompilerError, _valid_name, NAME_RE, \
      Undefined, Default, _parse_expr
 from Acquisition import aq_base, aq_inner, aq_parent
+from ZODB.utils import safe_hasattr
 
 
 _engine = None
@@ -62,7 +63,7 @@
     Calls the object, possibly a document template, or just returns it if
     not callable.  (From DT_Util.py)
     """
-    if hasattr(ob, '__render_with_namespace__'):
+    if safe_hasattr(ob, '__render_with_namespace__'):
         ob = call_with_ns(ob.__render_with_namespace__, ns)
     else:
         base = aq_base(ob)
@@ -259,7 +260,7 @@
 
 
 def restrictedTraverse(object, path, securityManager,
-                       get=getattr, has=hasattr, N=None, M=[],
+                       get=getattr, has=safe_hasattr, N=None, M=[],
                        TupleType=type(()) ):
 
     REQUEST = {'path': path}


=== Products/PageTemplates/PageTemplate.py 1.30.10.1 => 1.30.10.1.32.1 ===
--- Products/PageTemplates/PageTemplate.py:1.30.10.1	Sat Oct  4 14:57:57 2003
+++ Products/PageTemplates/PageTemplate.py	Sat May 28 20:41:32 2005
@@ -27,6 +27,7 @@
 from Expressions import getEngine
 from ExtensionClass import Base
 from ComputedAttribute import ComputedAttribute
+from ZODB.utils import safe_hasattr
 
 
 class PageTemplate(Base):
@@ -55,7 +56,7 @@
     def pt_edit(self, text, content_type):
         if content_type:
             self.content_type = str(content_type)
-        if hasattr(text, 'read'):
+        if safe_hasattr(text, 'read'):
             text = text.read()
         self.write(text)
 
@@ -183,7 +184,7 @@
         self._v_cooked = 1
 
     def html(self):
-        if not hasattr(getattr(self, 'aq_base', self), 'is_html'):
+        if not safe_hasattr(getattr(self, 'aq_base', self), 'is_html'):
             return self.content_type == 'text/html'
         return self.is_html
 


=== Products/PageTemplates/PageTemplateFile.py 1.28.4.2 => 1.28.4.2.30.1 ===
--- Products/PageTemplates/PageTemplateFile.py:1.28.4.2	Tue Dec 16 09:50:13 2003
+++ Products/PageTemplates/PageTemplateFile.py	Sat May 28 20:41:32 2005
@@ -30,6 +30,7 @@
 from Acquisition import aq_parent, aq_inner
 from App.config import getConfiguration
 from OFS.SimpleItem import Item_w__name__
+from ZODB.utils import safe_hasattr
 
 class PageTemplateFile(Item_w__name__, Script, PageTemplate, Traversable):
     "Zope wrapper for filesystem Page Template using TAL, TALES, and METAL"
@@ -161,7 +162,7 @@
     def _get__roles__(self):
         imp = getattr(aq_parent(aq_inner(self)),
                       '%s__roles__' % self.__name__)
-        if hasattr(imp, '__of__'):
+        if safe_hasattr(imp, '__of__'):
             return imp.__of__(self)
         return imp
 



More information about the Zope-Checkins mailing list