changeset 349:07c5978ad95f experimental-inline

inline branch: adapted to the immutble `Attrs` change, and various other fixes.
author cmlenz
date Fri, 10 Nov 2006 18:20:43 +0000
parents 72937f87d519
children 5dd729a14108
files genshi/template/core.py
diffstat 1 files changed, 14 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/genshi/template/core.py
+++ b/genshi/template/core.py
@@ -178,6 +178,11 @@
             expr = ' "%s"' % self.expr.source
         return '<%s%s>' % (self.__class__.__name__, expr)
 
+    def optimize(self, stream, directives):
+        if not directives:
+            return stream
+        return directives[0].optimize(stream, directives[1:])
+
     def tagname(self):
         """Return the local tag name of the directive as it is used in
         templates.
@@ -231,7 +236,7 @@
 
         self.filters = [self._flatten, self._eval]
 
-        self.stream = self._parse(encoding)
+        self.stream = self._optimize(self._parse(encoding))
 
     def __repr__(self):
         return '<%s "%s">' % (self.__class__.__name__, self.filename)
@@ -289,6 +294,14 @@
         return _interpolate(text, [cls._FULL_EXPR_RE, cls._SHORT_EXPR_RE])
     _interpolate = classmethod(_interpolate)
 
+    def _optimize(self, stream):
+        for kind, data, pos in stream:
+            if kind is SUB:
+                directives, substream = data
+                directives[0].optimize(substream, directives[1:])
+            else:
+                yield kind, data pos
+
     def compile(self):
         """Compile the template to a Python module, and return the module
         object.
Copyright (C) 2012-2017 Edgewall Software