diff genshi/template/markup.py @ 601:59fbd7586454 trunk

Simplify implementation of `py:with` directive by compiling to a `Suite`, instead of manually breaking up the statement and compiling each part to an `Expression`. Also, the first line of code in a `Suite` is now stored as the "function name" of the bytecode, so that it shows up in tracebacks.
author cmlenz
date Wed, 22 Aug 2007 21:50:46 +0000
parents 36b5a03534a0
children d7b957e92ea9
line wrap: on
line diff
--- a/genshi/template/markup.py
+++ b/genshi/template/markup.py
@@ -15,7 +15,6 @@
 
 from itertools import chain
 import sys
-from textwrap import dedent
 
 from genshi.core import Attrs, Namespace, Stream, StreamEventKind
 from genshi.core import START, END, START_NS, END_NS, TEXT, PI, COMMENT
@@ -197,19 +196,7 @@
                     raise TemplateSyntaxError('Python code blocks not allowed',
                                               self.filepath, *pos[1:])
                 try:
-                    # As Expat doesn't report whitespace between the PI target
-                    # and the data, we have to jump through some hoops here to
-                    # get correctly indented Python code
-                    # Unfortunately, we'll still probably not get the line
-                    # number quite right
-                    lines = [line.expandtabs() for line in data[1].splitlines()]
-                    first = lines[0]
-                    rest = dedent('\n'.join(lines[1:])).rstrip()
-                    if first.rstrip().endswith(':') and not rest[0].isspace():
-                        rest = '\n'.join(['    ' + line for line
-                                          in rest.splitlines()])
-                    source = '\n'.join([first, rest])
-                    suite = Suite(source, self.filepath, pos[1],
+                    suite = Suite(data[1], self.filepath, pos[1],
                                   lookup=self.lookup)
                 except SyntaxError, err:
                     raise TemplateSyntaxError(err, self.filepath,
Copyright (C) 2012-2017 Edgewall Software