From tseaver at palladion.com Sat May 28 20:42:17 2005 From: tseaver at palladion.com (Tres Seaver) Date: Sun Aug 10 17:05:20 2008 Subject: [ZPT-CVS] 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 Message-ID: <20050529004217.BA0E3203343@mail.zope.org> 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 From tseaver at palladion.com Sat May 28 20:42:23 2005 From: tseaver at palladion.com (Tres Seaver) Date: Sun Aug 10 17:05:20 2008 Subject: [ZPT-CVS] CVS: Packages/ZTUtils - Tree.py:1.15.2.5.22.1 Zope.py:1.11.42.6.26.1 Message-ID: <20050529004223.E4F9520330F@mail.zope.org> Update of /cvs-repository/Packages/ZTUtils In directory cvs.zope.org:/tmp/cvs-serv32028/lib/python/ZTUtils Modified Files: Tag: tseaver-hasattr_geddon-branch Tree.py Zope.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/ZTUtils/Tree.py 1.15.2.5 => 1.15.2.5.22.1 === --- Packages/ZTUtils/Tree.py:1.15.2.5 Tue May 4 15:31:09 2004 +++ Packages/ZTUtils/Tree.py Sat May 28 20:41:38 2005 @@ -17,6 +17,7 @@ from Acquisition import Explicit from ComputedAttribute import ComputedAttribute +from ZODB.utils import safe_hasattr from types import ListType, TupleType class TreeNode(Explicit): @@ -177,11 +178,13 @@ def getId(self, object): id_attr = self._id - if hasattr(object, id_attr): + if safe_hasattr(object, id_attr): obid = getattr(object, id_attr) - if not simple_type(obid): obid = obid() + if not simple_type(obid): + obid = obid() return obid - if hasattr(object, '_p_oid'): return str(object._p_oid) + if safe_hasattr(object, '_p_oid'): + return str(object._p_oid) return id(object) def hasChildren(self, object): === Packages/ZTUtils/Zope.py 1.11.42.6 => 1.11.42.6.26.1 === --- Packages/ZTUtils/Zope.py:1.11.42.6 Tue Jan 27 10:45:35 2004 +++ Packages/ZTUtils/Zope.py Sat May 28 20:41:38 2005 @@ -22,6 +22,7 @@ from Products.ZCatalog.Lazy import Lazy from AccessControl import getSecurityManager from DateTime import DateTime +from ZODB.utils import safe_hasattr try: from AccessControl.ZopeGuards import guarded_getitem @@ -233,7 +234,7 @@ sublist = None if isinstance(v, str): pass - elif hasattr(v, 'items'): + elif safe_hasattr(v, 'items'): sublist = [] for sk, sv in v.items(): sm = simple_marshal(sv)