Mercurial > public > mercurial-scm > hg
comparison mercurial/util.py @ 9495:b2d65ee49a72
ui: guard against UnicodeDecodeErrors in ui.wrap
author | Martin Geisler <mg@lazybytes.net> |
---|---|
date | Tue, 29 Sep 2009 01:08:18 +0200 |
parents | 44758742ad2e |
children | e2fd9b62349b effa05849027 e61e7b3e46d0 02c43e8e0835 |
comparison
equal
deleted
inserted
replaced
9480:44758742ad2e | 9495:b2d65ee49a72 |
---|---|
1276 | 1276 |
1277 def wrap(line, hangindent, width=78): | 1277 def wrap(line, hangindent, width=78): |
1278 padding = '\n' + ' ' * hangindent | 1278 padding = '\n' + ' ' * hangindent |
1279 # To avoid corrupting multi-byte characters in line, we must wrap | 1279 # To avoid corrupting multi-byte characters in line, we must wrap |
1280 # a Unicode string instead of a bytestring. | 1280 # a Unicode string instead of a bytestring. |
1281 u = line.decode(encoding.encoding) | 1281 try: |
1282 w = padding.join(textwrap.wrap(u, width=width - hangindent)) | 1282 u = line.decode(encoding.encoding) |
1283 return w.encode(encoding.encoding) | 1283 w = padding.join(textwrap.wrap(u, width=width - hangindent)) |
1284 return w.encode(encoding.encoding) | |
1285 except UnicodeDecodeError: | |
1286 return padding.join(textwrap.wrap(line, width=width - hangindent)) | |
1284 | 1287 |
1285 def iterlines(iterator): | 1288 def iterlines(iterator): |
1286 for chunk in iterator: | 1289 for chunk in iterator: |
1287 for line in chunk.splitlines(): | 1290 for line in chunk.splitlines(): |
1288 yield line | 1291 yield line |