Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

only split multiline strings in output code at repr generated breaks

Signed-off-by: R. Tyler Ballance <tyler@monkeypox.org>
  • Loading branch information...
commit 70c9bd4737cd446c76b5c0be520b4a2a67044407 1 parent 0cc9f78
karmix authored December 14, 2009 rtyler committed December 14, 2009
48  cheetah/Compiler.py
@@ -432,29 +432,31 @@ def commitStrConst(self):
432 432
         """Add the code for outputting the pending strConst without chopping off
433 433
         any whitespace from it.
434 434
         """
435  
-        if self._pendingStrConstChunks:
436  
-            strConst = ''.join(self._pendingStrConstChunks)
437  
-            self._pendingStrConstChunks = []
438  
-            if not strConst:
439  
-                return
440  
-            else:
441  
-                reprstr = repr(strConst).replace('\\012', '\n')
442  
-                i = 0
443  
-                out = []
444  
-                if reprstr.startswith('u'):
445  
-                    i = 1
446  
-                    out = ['u']
447  
-                body = escapedNewlineRE.sub('\n', reprstr[i+1:-1])
448  
-                
449  
-                if reprstr[i]=="'":
450  
-                    out.append("'''")
451  
-                    out.append(body)
452  
-                    out.append("'''")
453  
-                else:
454  
-                    out.append('"""')
455  
-                    out.append(body)
456  
-                    out.append('"""')
457  
-                self.addWriteChunk(''.join(out))
  435
+        if not self._pendingStrConstChunks:
  436
+            return
  437
+
  438
+        strConst = ''.join(self._pendingStrConstChunks)
  439
+        self._pendingStrConstChunks = []
  440
+        if not strConst:
  441
+            return
  442
+
  443
+        reprstr = repr(strConst)
  444
+        i = 0
  445
+        out = []
  446
+        if reprstr.startswith('u'):
  447
+            i = 1
  448
+            out = ['u']
  449
+        body = escapedNewlineRE.sub('\\1\n', reprstr[i+1:-1])
  450
+        
  451
+        if reprstr[i]=="'":
  452
+            out.append("'''")
  453
+            out.append(body)
  454
+            out.append("'''")
  455
+        else:
  456
+            out.append('"""')
  457
+            out.append(body)
  458
+            out.append('"""')
  459
+        self.addWriteChunk(''.join(out))
458 460
 
459 461
     def handleWSBeforeDirective(self):
460 462
         """Truncate the pending strCont to the beginning of the current line.
2  cheetah/Parser.py
@@ -144,7 +144,7 @@ def makeTripleQuoteRe(start, end):
144 144
 encodingDirectiveRE = re.compile(
145 145
     r'(?:^|\r\n|\r|\n)\s*#\s{0,5}encoding[:\s]*([-\w.]*)\s*(?:\r\n|\r|\n)', re.MULTILINE)
146 146
 
147  
-escapedNewlineRE = re.compile(r'(?<!\\)\\n')
  147
+escapedNewlineRE = re.compile(r'(?<!\\)((\\\\)*)\\(n|012)')
148 148
 
149 149
 directiveNamesAndParsers = {
150 150
     # importing and inheritance

0 notes on commit 70c9bd4

Please sign in to comment.
Something went wrong with that request. Please try again.