Update of /cvs-repository/Packages/TreeDisplay In directory cvs.zope.org:/tmp/cvs-serv32028/lib/python/TreeDisplay
Modified Files: Tag: tseaver-hasattr_geddon-branch TreeTag.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/TreeDisplay/TreeTag.py 1.53.68.5 => 1.53.68.5.22.1 === --- Packages/TreeDisplay/TreeTag.py:1.53.68.5 Thu Apr 29 14:58:56 2004 +++ Packages/TreeDisplay/TreeTag.py Sat May 28 20:41:36 2005 @@ -17,6 +17,7 @@ from DocumentTemplate.DT_Util import * from DocumentTemplate.DT_String import String +from ZODB.utils import safe_hasattr from cPickle import dumps from string import translate @@ -130,9 +131,9 @@ data=[] idattr=args['id'] - if hasattr(self, idattr): + if safe_hasattr(self, idattr): id = try_call_attr(self, idattr) - elif hasattr(self, '_p_oid'): id=oid(self) + elif safe_hasattr(self, '_p_oid'): id=oid(self) else: id=pyid(self) try: @@ -227,7 +228,7 @@ if level >= 0: urlattr=args['url'] - if urlattr and hasattr(self, urlattr): + if urlattr and safe_hasattr(self, urlattr): tpUrl = try_call_attr(self, urlattr) url = (url and ('%s/%s' % (url, tpUrl))) or tpUrl root_url = root_url or tpUrl @@ -257,7 +258,7 @@ get = getattr if items is None: - if have_arg('branches') and hasattr(self, args['branches']): + if have_arg('branches') and safe_hasattr(self, args['branches']): items = get(self, args['branches']) items = items() elif have_arg('branches_expr'): @@ -448,9 +449,9 @@ __traceback_info__=sub, args, state, substate ids={} for item in items: - if hasattr(item, idattr): + if safe_hasattr(item, idattr): id = try_call_attr(item, idattr) - elif hasattr(item, '_p_oid'): id=oid(item) + elif safe_hasattr(item, '_p_oid'): id=oid(item) else: id=pyid(item) if len(sub)==1: sub.append([]) substate=sub[1] @@ -603,8 +604,10 @@ def tpStateLevel(state, level=0): for sub in state: - if len(sub)==2: level = max(level, 1+tpStateLevel(sub[1])) - else: level=max(level,1) + if len(sub)==2: + level = max(level, 1+tpStateLevel(sub[1])) + else: + level=max(level,1) return level def tpValuesIds(self, get_items, args, @@ -618,16 +621,20 @@ r=[] idattr=args['id'] try: - try: items=get_items(self) - except AttributeError: items=() + try: + items=get_items(self) + except AttributeError: + items=() for item in items: try: if get_items(item): - if hasattr(item, idattr): + if safe_hasattr(item, idattr): id = try_call_attr(item, idattr) - elif hasattr(item, '_p_oid'): id=oid(item) - else: id=pyid(item) + elif safe_hasattr(item, '_p_oid'): + id=oid(item) + else: + id=pyid(item) e=tpValuesIds(item, get_items, args) if e: id=[id,e] _______________________________________________ Zope-Checkins maillist - Zope-Checkins@zope.org http://mail.zope.org/mailman/listinfo/zope-checkins