[ZPT] CVS: Zope/lib/python/Products/PageTemplates - Expressions.py:1.32.2.3
Shane Hathaway
shane@cvs.zope.org
Fri, 8 Mar 2002 12:09:41 -0500
Update of /cvs-repository/Zope/lib/python/Products/PageTemplates
In directory cvs.zope.org:/tmp/cvs-serv13864
Modified Files:
Tag: shane-better-tracebacks-branch
Expressions.py
Log Message:
Catch only specific TypeErrors. Added XXX comments--I hope Python 2.2 can
rescue us from this messy exception handling. There's no way to know
whether an object supports the item interface without calling it.
=== Zope/lib/python/Products/PageTemplates/Expressions.py 1.32.2.2 => 1.32.2.3 ===
# Try an item.
try:
+ # XXX maybe in Python 2.2 we can just check whether
+ # the object has the attribute "__getitem__"
+ # instead of blindly catching exceptions.
o = object[name]
except AttributeError, exc:
if str(exc).find('__getitem__') >= 0:
# The object does not support the item interface.
# Try to re-raise the original attribute error.
+ # XXX I think this only happens with
+ # ExtensionClass instances.
get(object, name)
raise
- except TypeError:
- # The object does not support the item interface.
- # Try to re-raise the original attribute error.
- get(object, name)
- # Should not reach here, but just in case...
+ except TypeError, exc:
+ if str(exc).find('unsubscriptable') >= 0:
+ # The object does not support the item interface.
+ # Try to re-raise the original attribute error.
+ # XXX This is sooooo ugly.
+ get(object, name)
raise
else:
# Check access to the item.