subscribe doesn't eat up unicode errors any longer
authorArmin Ronacher <armin.ronacher@active-4.com>
Fri, 16 May 2008 22:34:11 +0000 (00:34 +0200)
committerArmin Ronacher <armin.ronacher@active-4.com>
Fri, 16 May 2008 22:34:11 +0000 (00:34 +0200)
--HG--
branch : trunk

jinja2/compiler.py
jinja2/environment.py
jinja2/sandbox.py

index 114ca2d4e2977a8daff36ea70793b5bd4dc6c2b1..e27ecc31baef5a6729a66e99bf73229b9ac349f7 100644 (file)
@@ -1297,18 +1297,10 @@ class CodeGenerator(NodeVisitor):
             self.visit(node.arg, frame)
             self.write(']')
             return
-        try:
-            const = node.arg.as_const()
-            have_const = True
-        except nodes.Impossible:
-            have_const = False
         self.write('environment.subscribe(')
         self.visit(node.node, frame)
         self.write(', ')
-        if have_const:
-            self.write(repr(const))
-        else:
-            self.visit(node.arg, frame)
+        self.visit(node.arg, frame)
         self.write(')')
 
     def visit_Slice(self, node, frame):
index 41b0ce7116dbff5ad7b226cc69d31b1c3d0c8279..e10510cb1dae85fef52bd7521c1512217a7fe77b 100644 (file)
@@ -280,9 +280,14 @@ class Environment(object):
         """Get an item or attribute of an object."""
         if isinstance(argument, basestring):
             try:
-                return getattr(obj, str(argument))
-            except (AttributeError, UnicodeError):
+                attr = str(argument)
+            except:
                 pass
+            else:
+                try:
+                    return getattr(obj, attr)
+                except AttributeError:
+                    pass
         try:
             return obj[argument]
         except (TypeError, LookupError):
index c041a06d89edeb42d278dfdd0c54d7281ed5e6e7..714a0e1a11364f6230f3badcc4b548ad6604c956 100644 (file)
@@ -120,13 +120,18 @@ class SandboxedEnvironment(Environment):
         is_unsafe = False
         if isinstance(argument, basestring):
             try:
-                value = getattr(obj, str(argument))
-            except (AttributeError, UnicodeError):
+                attr = str(argument)
+            except:
                 pass
             else:
-                if self.is_safe_attribute(obj, argument, value):
-                    return value
-                is_unsafe = True
+                try:
+                    value = getattr(obj, attr)
+                except AttributeError:
+                    pass
+                else:
+                    if self.is_safe_attribute(obj, argument, value):
+                        return value
+                    is_unsafe = True
         try:
             return obj[argument]
         except (TypeError, LookupError):