[Zope-Checkins] CVS: Packages/TreeDisplay - TreeTag.py:1.53.68.3
Evan Simpson
evan at 4-am.com
Thu Dec 11 17:51:08 EST 2003
Update of /cvs-repository/Packages/TreeDisplay
In directory cvs.zope.org:/tmp/cvs-serv21427/lib/python/TreeDisplay
Modified Files:
Tag: Zope-2_7-branch
TreeTag.py
Log Message:
Collector #1133: TreeTag choked on Ids of type long.
=== Packages/TreeDisplay/TreeTag.py 1.53.68.2 => 1.53.68.3 ===
--- Packages/TreeDisplay/TreeTag.py:1.53.68.2 Mon Nov 17 17:34:17 2003
+++ Packages/TreeDisplay/TreeTag.py Thu Dec 11 17:51:08 2003
@@ -92,8 +92,20 @@
pyid=id # Copy builtin
+simple_types = {str: 1, unicode: 1, int: 1, float: 1, long: 1,
+ tuple: 1, list: 1, dict: 1}
+
+def try_call_attr(ob, attrname, simple_types=simple_types):
+ attr = getattr(ob, attrname)
+ if type(attr) in simple_types:
+ return attr
+ try:
+ return attr()
+ except TypeError:
+ return attr
+
def tpRender(self, md, section, args,
- simple_type={type(''):0, type(1):0, type(1.0):0}.has_key):
+ try_call_attr=try_call_attr):
"""Render data organized as a tree.
We keep track of open nodes using a cookie. The cookie stored the
@@ -118,8 +130,7 @@
idattr=args['id']
if hasattr(self, idattr):
- id=getattr(self, idattr)
- if not simple_type(type(id)): id=id()
+ id = try_call_attr(self, idattr)
elif hasattr(self, '_p_oid'): id=oid(self)
else: id=pyid(self)
@@ -206,7 +217,7 @@
def tpRenderTABLE(self, id, root_url, url, state, substate, diff, data,
colspan, section, md, treeData, level=0, args=None,
- simple_type={type(''):0, type(1):0, type(1.0):0}.has_key,
+ try_call_attr=try_call_attr,
):
"Render a tree as a table"
@@ -216,8 +227,7 @@
if level >= 0:
urlattr=args['url']
if urlattr and hasattr(self, urlattr):
- tpUrl=getattr(self, urlattr)
- if not simple_type(type(tpUrl)): tpUrl=tpUrl()
+ tpUrl = try_call_attr(self, urlattr)
url = (url and ('%s/%s' % (url, tpUrl))) or tpUrl
root_url = root_url or tpUrl
@@ -438,8 +448,7 @@
ids={}
for item in items:
if hasattr(item, idattr):
- id=getattr(item, idattr)
- if not simple_type(type(id)): id=id()
+ id = try_call_attr(item, idattr)
elif hasattr(item, '_p_oid'): id=oid(item)
else: id=pyid(item)
if len(sub)==1: sub.append([])
@@ -586,7 +595,7 @@
return level
def tpValuesIds(self, get_items, args,
- simple_type={type(''):0, type(1):0, type(1.0):0}.has_key,
+ try_call_attr=try_call_attr,
):
# get_item(node) is a function that returns the subitems of node
@@ -603,8 +612,7 @@
if get_items(item):
if hasattr(item, idattr):
- id=getattr(item, idattr)
- if not simple_type(type(id)): id=id()
+ id = try_call_attr(item, idattr)
elif hasattr(item, '_p_oid'): id=oid(item)
else: id=pyid(item)
More information about the Zope-Checkins
mailing list