Skip to content

Commit e659ebd

Browse files
committed
Style cleanup
1 parent c017664 commit e659ebd

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

patch.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121

2222
# cStringIO doesn't support unicode in 2.5
2323
try:
24-
from StringIO import StringIO
24+
from StringIO import StringIO
2525
except ImportError:
26-
from io import BytesIO as StringIO # python 3
26+
from io import BytesIO as StringIO # python 3
2727
try:
28-
import urllib2 as urllib_request
28+
import urllib2 as urllib_request
2929
except ImportError:
30-
import urllib.request as urllib_request
30+
import urllib.request as urllib_request
3131

3232
from os.path import exists, isfile, abspath
3333
import os
@@ -44,6 +44,17 @@
4444
else:
4545
compat_next = lambda gen: gen.__next__()
4646

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+
4758

4859
#------------------------------------------------
4960
# Logging is controlled by logger named after the
@@ -783,7 +794,7 @@ def diffstat(self):
783794
#print(iratio, dratio, iwidth, dwidth, histwidth)
784795
hist = "+"*int(iwidth) + "-"*int(dwidth)
785796
# -- /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))
787798

788799
output += (" %d files changed, %d insertions(+), %d deletions(-), %+d bytes"
789800
% (len(names), sum(insert), sum(delete), delta))

tests/run_tests.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env python
2-
from __future__ import print_function
32
"""
43
python-patch test suite
54
@@ -30,6 +29,7 @@
3029
On Windows it may be more convenient instead of `coverage` call
3130
`python -m coverage.__main__`
3231
"""
32+
from __future__ import print_function
3333

3434
import os
3535
import sys
@@ -383,9 +383,7 @@ def test_apply_returns_true_on_success(self):
383383
def test_revert(self):
384384
def get_file_content(filename):
385385
with open(filename, 'rb') as f:
386-
content = f.read()
387-
388-
return content
386+
return f.read()
389387

390388
self.tmpcopy(['03trail_fname.patch',
391389
'03trail_fname.from'])

0 commit comments

Comments
 (0)