|
21 | 21 |
|
22 | 22 | # cStringIO doesn't support unicode in 2.5 |
23 | 23 | try: |
24 | | - from StringIO import StringIO |
| 24 | + from StringIO import StringIO |
25 | 25 | except ImportError: |
26 | | - from io import BytesIO as StringIO # python 3 |
| 26 | + from io import BytesIO as StringIO # python 3 |
27 | 27 | try: |
28 | | - import urllib2 as urllib_request |
| 28 | + import urllib2 as urllib_request |
29 | 29 | except ImportError: |
30 | | - import urllib.request as urllib_request |
| 30 | + import urllib.request as urllib_request |
31 | 31 |
|
32 | 32 | from os.path import exists, isfile, abspath |
33 | 33 | import os |
|
44 | 44 | else: |
45 | 45 | compat_next = lambda gen: gen.__next__() |
46 | 46 |
|
| 47 | +def tostr(b): |
| 48 | + """ Python 3 bytes encoder. Used to print filename in |
| 49 | + diffstat output. Assumes that filenames are in utf-8. |
| 50 | + """ |
| 51 | + if not PY3K: |
| 52 | + return b |
| 53 | + |
| 54 | + # [ ] figure out how to print non-utf-8 filenames without |
| 55 | + # information loss |
| 56 | + return b.decode('utf-8') |
| 57 | + |
47 | 58 |
|
48 | 59 | #------------------------------------------------ |
49 | 60 | # Logging is controlled by logger named after the |
@@ -783,7 +794,7 @@ def diffstat(self): |
783 | 794 | #print(iratio, dratio, iwidth, dwidth, histwidth) |
784 | 795 | hist = "+"*int(iwidth) + "-"*int(dwidth) |
785 | 796 | # -- /calculating +- histogram -- |
786 | | - output += (format % (names[i].decode('utf-8'), str(insert[i] + delete[i]), hist)) |
| 797 | + output += (format % (tostr(names[i]), str(insert[i] + delete[i]), hist)) |
787 | 798 |
|
788 | 799 | output += (" %d files changed, %d insertions(+), %d deletions(-), %+d bytes" |
789 | 800 | % (len(names), sum(insert), sum(delete), delta)) |
|
0 commit comments