improved subscribe
--HG--
branch : trunk
diff --git a/jinja2/environment.py b/jinja2/environment.py
index 70fd344..d1206ef 100644
--- a/jinja2/environment.py
+++ b/jinja2/environment.py
@@ -278,13 +278,15 @@
def subscribe(self, obj, argument):
"""Get an item or attribute of an object."""
- try:
- return getattr(obj, str(argument))
- except (AttributeError, UnicodeError):
+ if isinstance(argument, basestring):
try:
- return obj[argument]
- except (TypeError, LookupError):
- return self.undefined(obj=obj, name=argument)
+ return getattr(obj, str(argument))
+ except (AttributeError, UnicodeError):
+ pass
+ try:
+ return obj[argument]
+ except (TypeError, LookupError):
+ return self.undefined(obj=obj, name=argument)
def parse(self, source, filename=None):
"""Parse the sourcecode and return the abstract syntax tree. This