templater: take cStringIO out of indent
authorMatt Mackall <mpm@selenic.com>
Mon, 13 Nov 2006 13:26:57 -0600
changeset 3635 7af1f54c044c
parent 3634 6a46c9ccc2ed
child 3636 dfbbb33f3fa3
templater: take cStringIO out of indent
mercurial/templater.py
--- 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,