From: Armin Ronacher Date: Fri, 16 May 2008 22:34:11 +0000 (+0200) Subject: subscribe doesn't eat up unicode errors any longer X-Git-Tag: 2.0rc1~49 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=ab5ad8ca248b5ebbcb82209ab31e2f387d2b9e92;p=jinja2.git subscribe doesn't eat up unicode errors any longer --HG-- branch : trunk --- 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):