fixed a bug in extension handling

--HG--
branch : trunk
diff --git a/jinja2/compiler.py b/jinja2/compiler.py
index 6518427..7b8366c 100644
--- a/jinja2/compiler.py
+++ b/jinja2/compiler.py
@@ -719,7 +719,8 @@
         # if this extends statement was in the root level we can take
         # advantage of that information and simplify the generated code
         # in the top level from this point onwards
-        self.has_known_extends = True
+        if frame.rootlevel:
+            self.has_known_extends = True
 
         # and now we have one more
         self.extends_so_far += 1
diff --git a/jinja2/environment.py b/jinja2/environment.py
index 2fbe217..e104090 100644
--- a/jinja2/environment.py
+++ b/jinja2/environment.py
@@ -15,7 +15,6 @@
 from jinja2.optimizer import optimize
 from jinja2.compiler import generate
 from jinja2.runtime import Undefined, Context
-from jinja2.debug import translate_exception, translate_syntax_error
 from jinja2.exceptions import TemplateSyntaxError
 from jinja2.utils import import_string, LRUCache, Markup, missing, concat
 
@@ -299,6 +298,7 @@
         try:
             return Parser(self, source, filename).parse()
         except TemplateSyntaxError, e:
+            from jinja2.debug import translate_syntax_error
             exc_type, exc_value, tb = translate_syntax_error(e)
             raise exc_type, exc_value, tb
 
@@ -486,6 +486,7 @@
         try:
             return concat(self._generate(*args, **kwargs))
         except:
+            from jinja2.debug import translate_exception
             exc_type, exc_value, tb = translate_exception(sys.exc_info())
             raise exc_type, exc_value, tb
 
@@ -507,6 +508,7 @@
             for item in self._generate(*args, **kwargs):
                 yield item
         except:
+            from jinja2.debug import translate_exception
             exc_type, exc_value, tb = translate_exception(sys.exc_info())
             raise exc_type, exc_value, tb
 
diff --git a/jinja2/ext.py b/jinja2/ext.py
index f60b85a..53b4041 100644
--- a/jinja2/ext.py
+++ b/jinja2/ext.py
@@ -73,6 +73,7 @@
         is the name token that matched.  This method has to return one or a
         list of multiple nodes.
         """
+        raise NotImplementedError()
 
     def attr(self, name, lineno=None):
         """Return an attribute node for the current extension.  This is useful
@@ -84,6 +85,16 @@
         """
         return nodes.ExtensionAttribute(self.identifier, name, lineno=lineno)
 
+    def call_method(self, name, args=None, kwargs=None, dyn_args=None,
+                    dyn_kwargs=None, lineno=None):
+        """Call a method of the extension."""
+        if args is None:
+            args = []
+        if kwargs is None:
+            kwargs = []
+        return nodes.Call(self.attr(name, lineno=lineno), args, kwargs,
+                          dyn_args, dyn_kwargs, lineno=lineno)
+
 
 class InternationalizationExtension(Extension):
     """This extension adds gettext support to Jinja2."""