Improved attribute and item lookup by allowing template designers to express the priority.  foo.bar checks foo.bar first and then foo['bar'] and the other way round.

--HG--
branch : trunk
diff --git a/jinja2/nodes.py b/jinja2/nodes.py
index f4b1f32..5950920 100644
--- a/jinja2/nodes.py
+++ b/jinja2/nodes.py
@@ -582,7 +582,7 @@
             raise Impossible()
 
 
-class Subscript(Expr):
+class Getitem(Expr):
     """Subscribe an expression by an argument.  This node performs a dict
     and an attribute lookup on the object whatever succeeds.
     """
@@ -592,8 +592,24 @@
         if self.ctx != 'load':
             raise Impossible()
         try:
-            return self.environment.subscribe(self.node.as_const(),
-                                              self.arg.as_const())
+            return self.environment.getitem(self.node.as_const(),
+                                            self.arg.as_const())
+        except:
+            raise Impossible()
+
+    def can_assign(self):
+        return False
+
+
+class Getattr(Expr):
+    """Subscribe an attribute."""
+    fields = ('node', 'attr', 'ctx')
+
+    def as_const(self):
+        if self.ctx != 'load':
+            raise Impossible()
+        try:
+            return self.environment.getattr(self.node.as_const(), arg)
         except:
             raise Impossible()