From ab5ad8ca248b5ebbcb82209ab31e2f387d2b9e92 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Sat, 17 May 2008 00:34:11 +0200 Subject: [PATCH] subscribe doesn't eat up unicode errors any longer --HG-- branch : trunk --- jinja2/compiler.py | 10 +--------- jinja2/environment.py | 9 +++++++-- jinja2/sandbox.py | 15 ++++++++++----- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/jinja2/compiler.py b/jinja2/compiler.py index 114ca2d..e27ecc3 100644 --- a/jinja2/compiler.py +++ b/jinja2/compiler.py @@ -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): diff --git a/jinja2/environment.py b/jinja2/environment.py index 41b0ce7..e10510c 100644 --- a/jinja2/environment.py +++ b/jinja2/environment.py @@ -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): diff --git a/jinja2/sandbox.py b/jinja2/sandbox.py index c041a06..714a0e1 100644 --- a/jinja2/sandbox.py +++ b/jinja2/sandbox.py @@ -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): -- 2.26.2