Mercurial > hg
comparison mercurial/util.py @ 9567:02c43e8e0835
Merge with hg-i18n-stable
author | Martin Geisler <mg@lazybytes.net> |
---|---|
date | Wed, 30 Sep 2009 21:14:24 +0200 |
parents | 4c3fb45123e5 b2d65ee49a72 |
children | ceb0f59e1327 |
comparison
equal
deleted
inserted
replaced
9565:08914fd0fddb | 9567:02c43e8e0835 |
---|---|
12 This contains helper routines that are independent of the SCM core and | 12 This contains helper routines that are independent of the SCM core and |
13 hide platform-specific details from the core. | 13 hide platform-specific details from the core. |
14 """ | 14 """ |
15 | 15 |
16 from i18n import _ | 16 from i18n import _ |
17 import error, osutil | 17 import error, osutil, encoding |
18 import cStringIO, errno, re, shutil, sys, tempfile, traceback | 18 import cStringIO, errno, re, shutil, sys, tempfile, traceback |
19 import os, stat, time, calendar, random, textwrap | 19 import os, stat, time, calendar, random, textwrap |
20 import imp | 20 import imp |
21 | 21 |
22 # Python compatibility | 22 # Python compatibility |
1276 width = termwidth() - 2 | 1276 width = termwidth() - 2 |
1277 if width <= hangindent: | 1277 if width <= hangindent: |
1278 # adjust for weird terminal size | 1278 # adjust for weird terminal size |
1279 width = max(78, hangindent + 1) | 1279 width = max(78, hangindent + 1) |
1280 padding = '\n' + ' ' * hangindent | 1280 padding = '\n' + ' ' * hangindent |
1281 return padding.join(textwrap.wrap(line, width=width - hangindent)) | 1281 # To avoid corrupting multi-byte characters in line, we must wrap |
1282 # a Unicode string instead of a bytestring. | |
1283 try: | |
1284 u = line.decode(encoding.encoding) | |
1285 w = padding.join(textwrap.wrap(u, width=width - hangindent)) | |
1286 return w.encode(encoding.encoding) | |
1287 except UnicodeDecodeError: | |
1288 return padding.join(textwrap.wrap(line, width=width - hangindent)) | |
1282 | 1289 |
1283 def iterlines(iterator): | 1290 def iterlines(iterator): |
1284 for chunk in iterator: | 1291 for chunk in iterator: |
1285 for line in chunk.splitlines(): | 1292 for line in chunk.splitlines(): |
1286 yield line | 1293 yield line |