Show More
@@ -105,13 +105,14 b' def indent(text, prefix):' | |||||
105 | '''indent each non-empty line of text after first with prefix.''' |
|
105 | '''indent each non-empty line of text after first with prefix.''' | |
106 | lines = text.splitlines() |
|
106 | lines = text.splitlines() | |
107 | num_lines = len(lines) |
|
107 | num_lines = len(lines) | |
|
108 | endswithnewline = text[-1:] == '\n' | |||
108 | def indenter(): |
|
109 | def indenter(): | |
109 | for i in xrange(num_lines): |
|
110 | for i in xrange(num_lines): | |
110 | l = lines[i] |
|
111 | l = lines[i] | |
111 | if i and l.strip(): |
|
112 | if i and l.strip(): | |
112 | yield prefix |
|
113 | yield prefix | |
113 | yield l |
|
114 | yield l | |
114 |
if i < num_lines - 1 or |
|
115 | if i < num_lines - 1 or endswithnewline: | |
115 | yield '\n' |
|
116 | yield '\n' | |
116 | return "".join(indenter()) |
|
117 | return "".join(indenter()) | |
117 |
|
118 |
General Comments 0
You need to be logged in to leave comments.
Login now