[ZPT] CVS: Zope/lib/python/Products/PageTemplates - Expressions.py:1.32.2.2

Shane Hathaway shane@cvs.zope.org
Tue, 5 Mar 2002 17:56:02 -0500


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

Modified Files:
      Tag: shane-better-tracebacks-branch
	Expressions.py 
Log Message:
Try hard to re-raise the original exceptions when restrictedTraverse() fails.

=== Zope/lib/python/Products/PageTemplates/Expressions.py 1.32.2.1 => 1.32.2.2 ===
                 raise Unauthorized, name
         else:
-            o=get(object, name, M)
+            # Try an attribute.
+            o = get(object, name, M)
             if o is not M:
-                # Check security.
+                # Check access to the attribute.
                 if has(object, 'aq_acquire'):
                     object.aq_acquire(
                         name, validate2, validate)
@@ -334,13 +335,25 @@
                     if not validate(object, object, name, o):
                         raise Unauthorized, name
             else:
+                # Try an item.
                 try:
-                    o=object[name]
-                except (AttributeError, TypeError):
-                    # Assume the object does not support the item interface.
-                    raise AttributeError, name
-                if not validate(object, object, name, o):
-                    raise Unauthorized, name
+                    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.
+                        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...
+                    raise
+                else:
+                    # Check access to the item.
+                    if not validate(object, object, name, o):
+                        raise Unauthorized, name
         object = o
 
     return object