summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDoug Knight <karmix0@gmail.com>2009-12-14 16:36:09 -0900
committerR. Tyler Ballance <tyler@monkeypox.org>2009-12-14 23:36:27 -0800
commit70c9bd4737cd446c76b5c0be520b4a2a67044407 (patch)
tree5067164d55e61cb39a9cdea1628f32e3865749f9
parent0cc9f781eeeb98d6c0d2812145a525f5dfe27b40 (diff)
downloadpython-cheetah-70c9bd4737cd446c76b5c0be520b4a2a67044407.tar.gz
only split multiline strings in output code at repr generated breaks
Signed-off-by: R. Tyler Ballance <tyler@monkeypox.org>
-rw-r--r--cheetah/Compiler.py48
-rw-r--r--cheetah/Parser.py2
2 files changed, 26 insertions, 24 deletions
diff --git a/cheetah/Compiler.py b/cheetah/Compiler.py
index 97e69e7..8946710 100644
--- a/cheetah/Compiler.py
+++ b/cheetah/Compiler.py
@@ -432,29 +432,31 @@ class MethodCompiler(GenUtils):
"""Add the code for outputting the pending strConst without chopping off
any whitespace from it.
"""
- if self._pendingStrConstChunks:
- strConst = ''.join(self._pendingStrConstChunks)
- self._pendingStrConstChunks = []
- if not strConst:
- return
- else:
- reprstr = repr(strConst).replace('\\012', '\n')
- i = 0
- out = []
- if reprstr.startswith('u'):
- i = 1
- out = ['u']
- body = escapedNewlineRE.sub('\n', reprstr[i+1:-1])
-
- if reprstr[i]=="'":
- out.append("'''")
- out.append(body)
- out.append("'''")
- else:
- out.append('"""')
- out.append(body)
- out.append('"""')
- self.addWriteChunk(''.join(out))
+ if not self._pendingStrConstChunks:
+ return
+
+ strConst = ''.join(self._pendingStrConstChunks)
+ self._pendingStrConstChunks = []
+ if not strConst:
+ return
+
+ reprstr = repr(strConst)
+ i = 0
+ out = []
+ if reprstr.startswith('u'):
+ i = 1
+ out = ['u']
+ body = escapedNewlineRE.sub('\\1\n', reprstr[i+1:-1])
+
+ if reprstr[i]=="'":
+ out.append("'''")
+ out.append(body)
+ out.append("'''")
+ else:
+ out.append('"""')
+ out.append(body)
+ out.append('"""')
+ self.addWriteChunk(''.join(out))
def handleWSBeforeDirective(self):
"""Truncate the pending strCont to the beginning of the current line.
diff --git a/cheetah/Parser.py b/cheetah/Parser.py
index 67f9fbc..8810ac8 100644
--- a/cheetah/Parser.py
+++ b/cheetah/Parser.py
@@ -144,7 +144,7 @@ unicodeDirectiveRE = re.compile(
encodingDirectiveRE = re.compile(
r'(?:^|\r\n|\r|\n)\s*#\s{0,5}encoding[:\s]*([-\w.]*)\s*(?:\r\n|\r|\n)', re.MULTILINE)
-escapedNewlineRE = re.compile(r'(?<!\\)\\n')
+escapedNewlineRE = re.compile(r'(?<!\\)((\\\\)*)\\(n|012)')
directiveNamesAndParsers = {
# importing and inheritance