comparison mercurial/templater.py @ 3638: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
comparison
equal deleted inserted replaced
3637:6a46c9ccc2ed 3638:7af1f54c044c
254 '''turn (timestamp, tzoff) tuple into iso 8631 date.''' 254 '''turn (timestamp, tzoff) tuple into iso 8631 date.'''
255 return util.datestr(date, format='%Y-%m-%d', timezone=False) 255 return util.datestr(date, format='%Y-%m-%d', timezone=False)
256 256
257 def indent(text, prefix): 257 def indent(text, prefix):
258 '''indent each non-empty line of text after first with prefix.''' 258 '''indent each non-empty line of text after first with prefix.'''
259 fp = cStringIO.StringIO()
260 lines = text.splitlines() 259 lines = text.splitlines()
261 num_lines = len(lines) 260 num_lines = len(lines)
262 for i in xrange(num_lines): 261 def indenter():
263 l = lines[i] 262 for i in xrange(num_lines):
264 if i and l.strip(): fp.write(prefix) 263 l = lines[i]
265 fp.write(l) 264 if i and l.strip():
266 if i < num_lines - 1 or text.endswith('\n'): 265 yield prefix
267 fp.write('\n') 266 yield l
268 return fp.getvalue() 267 if i < num_lines - 1 or text.endswith('\n'):
268 yield '\n'
269 return "".join(indenter())
269 270
270 common_filters = { 271 common_filters = {
271 "addbreaks": nl2br, 272 "addbreaks": nl2br,
272 "basename": os.path.basename, 273 "basename": os.path.basename,
273 "age": age, 274 "age": age,