Permalink
Browse files

only split multiline strings in output code at repr generated breaks

Signed-off-by: R. Tyler Ballance <tyler@monkeypox.org>
  • Loading branch information...
karmix authored and rtyler committed Dec 15, 2009
1 parent 0cc9f78 commit 70c9bd4737cd446c76b5c0be520b4a2a67044407
Showing with 26 additions and 24 deletions.
  1. +25 −23 cheetah/Compiler.py
  2. +1 −1 cheetah/Parser.py
View
@@ -432,29 +432,31 @@ def commitStrConst(self):
"""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.
View
@@ -144,7 +144,7 @@ def makeTripleQuoteRe(start, end):
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

0 comments on commit 70c9bd4

Please sign in to comment.