equal
deleted
inserted
replaced
297 filter. |
297 filter. |
298 """ |
298 """ |
299 return dateutil.datestr(text, b'%Y-%m-%d %H:%M:%S %1%2') |
299 return dateutil.datestr(text, b'%Y-%m-%d %H:%M:%S %1%2') |
300 |
300 |
301 |
301 |
302 def indent(text, prefix): |
302 def indent(text, prefix, firstline=b''): |
303 '''indent each non-empty line of text after first with prefix.''' |
303 '''indent each non-empty line of text after first with prefix.''' |
304 lines = text.splitlines() |
304 lines = text.splitlines() |
305 num_lines = len(lines) |
305 num_lines = len(lines) |
306 endswithnewline = text[-1:] == b'\n' |
306 endswithnewline = text[-1:] == b'\n' |
307 |
307 |
308 def indenter(): |
308 def indenter(): |
309 for i in pycompat.xrange(num_lines): |
309 for i in pycompat.xrange(num_lines): |
310 l = lines[i] |
310 l = lines[i] |
311 if i and l.strip(): |
311 if l.strip(): |
312 yield prefix |
312 yield prefix if i else firstline |
313 yield l |
313 yield l |
314 if i < num_lines - 1 or endswithnewline: |
314 if i < num_lines - 1 or endswithnewline: |
315 yield b'\n' |
315 yield b'\n' |
316 |
316 |
317 return b"".join(indenter()) |
317 return b"".join(indenter()) |