Skip to content

Commit

Permalink
Style cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
techtonik committed Feb 13, 2016
1 parent c017664 commit e659ebd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
21 changes: 16 additions & 5 deletions patch.py
Expand Up @@ -21,13 +21,13 @@

# cStringIO doesn't support unicode in 2.5
try:
from StringIO import StringIO
from StringIO import StringIO
except ImportError:
from io import BytesIO as StringIO # python 3
from io import BytesIO as StringIO # python 3
try:
import urllib2 as urllib_request
import urllib2 as urllib_request
except ImportError:
import urllib.request as urllib_request
import urllib.request as urllib_request

from os.path import exists, isfile, abspath
import os
Expand All @@ -44,6 +44,17 @@
else:
compat_next = lambda gen: gen.__next__()

def tostr(b):
""" Python 3 bytes encoder. Used to print filename in
diffstat output. Assumes that filenames are in utf-8.
"""
if not PY3K:
return b

# [ ] figure out how to print non-utf-8 filenames without
# information loss
return b.decode('utf-8')


#------------------------------------------------
# Logging is controlled by logger named after the
Expand Down Expand Up @@ -783,7 +794,7 @@ def diffstat(self):
#print(iratio, dratio, iwidth, dwidth, histwidth)
hist = "+"*int(iwidth) + "-"*int(dwidth)
# -- /calculating +- histogram --
output += (format % (names[i].decode('utf-8'), str(insert[i] + delete[i]), hist))
output += (format % (tostr(names[i]), str(insert[i] + delete[i]), hist))

output += (" %d files changed, %d insertions(+), %d deletions(-), %+d bytes"
% (len(names), sum(insert), sum(delete), delta))
Expand Down
6 changes: 2 additions & 4 deletions tests/run_tests.py
@@ -1,5 +1,4 @@
#!/usr/bin/env python
from __future__ import print_function
"""
python-patch test suite
Expand Down Expand Up @@ -30,6 +29,7 @@
On Windows it may be more convenient instead of `coverage` call
`python -m coverage.__main__`
"""
from __future__ import print_function

import os
import sys
Expand Down Expand Up @@ -383,9 +383,7 @@ def test_apply_returns_true_on_success(self):
def test_revert(self):
def get_file_content(filename):
with open(filename, 'rb') as f:
content = f.read()

return content
return f.read()

self.tmpcopy(['03trail_fname.patch',
'03trail_fname.from'])
Expand Down

0 comments on commit e659ebd

Please sign in to comment.