changeset 3635:7af1f54c044c

templater: take cStringIO out of indent
author Matt Mackall <mpm@selenic.com>
date Mon, 13 Nov 2006 13:26:57 -0600
parents 6a46c9ccc2ed
children dfbbb33f3fa3
files mercurial/templater.py
diffstat 1 files changed, 9 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/templater.py	Mon Nov 13 13:26:57 2006 -0600
+++ b/mercurial/templater.py	Mon Nov 13 13:26:57 2006 -0600
@@ -256,16 +256,17 @@
 
 def indent(text, prefix):
     '''indent each non-empty line of text after first with prefix.'''
-    fp = cStringIO.StringIO()
     lines = text.splitlines()
     num_lines = len(lines)
-    for i in xrange(num_lines):
-        l = lines[i]
-        if i and l.strip(): fp.write(prefix)
-        fp.write(l)
-        if i < num_lines - 1 or text.endswith('\n'):
-            fp.write('\n')
-    return fp.getvalue()
+    def indenter():
+        for i in xrange(num_lines):
+            l = lines[i]
+            if i and l.strip():
+                yield prefix
+            yield l
+            if i < num_lines - 1 or text.endswith('\n'):
+                yield '\n'
+    return "".join(indenter())
 
 common_filters = {
     "addbreaks": nl2br,