[Reproducible-commits] [diffoscope] 01/21: Open files in binary mode when we read/write raw bytes
Jérémy Bobbio
lunar at moszumanska.debian.org
Mon Sep 21 17:39:26 UTC 2015
This is an automated email from the git hooks/post-receive script.
lunar pushed a commit to branch master
in repository diffoscope.
commit 22e1ebfe37be8c24e79f293f20997c91bc776633
Author: Jérémy Bobbio <lunar at debian.org>
Date: Fri Sep 18 15:34:11 2015 +0200
Open files in binary mode when we read/write raw bytes
This changes is required for Python 3 as files opened in text mode read and
write unicode strings when files opened in binary mode read and write raw
bytes.
---
diffoscope/comparators/binary.py | 6 +++---
diffoscope/comparators/deb.py | 2 +-
diffoscope/comparators/libarchive.py | 2 +-
diffoscope/comparators/png.py | 2 +-
tests/comparators/test_text.py | 2 +-
5 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/diffoscope/comparators/binary.py b/diffoscope/comparators/binary.py
index 6294620..89ff4d1 100644
--- a/diffoscope/comparators/binary.py
+++ b/diffoscope/comparators/binary.py
@@ -49,7 +49,7 @@ def xxd(path):
def hexdump_fallback(path):
hexdump = ''
- with open(path) as f:
+ with open(path, 'rb') as f:
for buf in iter(lambda: f.read(32), b''):
hexdump += u'%s\n' % hexlify(buf)
return hexdump
@@ -120,7 +120,7 @@ class File(object):
with self.get_content():
# tlsh is not meaningful with files smaller than 512 bytes
if os.stat(self.path).st_size >= 512:
- self._fuzzy_hash = tlsh.hash(open(self.path).read())
+ self._fuzzy_hash = tlsh.hash(open(self.path, 'rb').read())
else:
self._fuzzy_hash = None
return self._fuzzy_hash
@@ -162,7 +162,7 @@ class File(object):
my_size = os.path.getsize(self.path)
other_size = os.path.getsize(other.path)
if my_size == other_size and my_size <= SMALL_FILE_THRESHOLD:
- if open(self.path).read() == open(other.path).read():
+ if open(self.path, 'rb').read() == open(other.path, 'rb').read():
return True
return 0 == subprocess.call(['cmp', '--silent', self.path, other.path],
diff --git a/diffoscope/comparators/deb.py b/diffoscope/comparators/deb.py
index 0d5cffb..157aafb 100644
--- a/diffoscope/comparators/deb.py
+++ b/diffoscope/comparators/deb.py
@@ -47,7 +47,7 @@ class ArContainer(Archive):
member = self.archive.getmember(member_name)
dest_path = os.path.join(dest_dir, os.path.basename(member_name))
member.seek(0)
- with open(dest_path, 'w') as fp:
+ with open(dest_path, 'wb') as fp:
for buf in iter(lambda: member.read(AR_EXTRACTION_BUFFER_SIZE), b''):
fp.write(buf)
return dest_path
diff --git a/diffoscope/comparators/libarchive.py b/diffoscope/comparators/libarchive.py
index 702324a..e0b8960 100644
--- a/diffoscope/comparators/libarchive.py
+++ b/diffoscope/comparators/libarchive.py
@@ -127,7 +127,7 @@ class LibarchiveContainer(Archive):
for entry in archive:
if entry.pathname == member_name:
logger.debug('entry found, writing %s', dest_path)
- with open(dest_path, 'w') as f:
+ with open(dest_path, 'wb') as f:
for buf in entry.get_blocks():
f.write(buf)
return dest_path
diff --git a/diffoscope/comparators/png.py b/diffoscope/comparators/png.py
index 22f81c0..1eceacd 100644
--- a/diffoscope/comparators/png.py
+++ b/diffoscope/comparators/png.py
@@ -32,7 +32,7 @@ class Sng(Command):
def feed_stdin(self, stdin):
try:
- with open(self.path) as f:
+ with open(self.path, 'rb') as f:
for buf in iter(partial(f.read, 32768), b''):
stdin.write(buf)
finally:
diff --git a/tests/comparators/test_text.py b/tests/comparators/test_text.py
index cf71108..2bd222c 100644
--- a/tests/comparators/test_text.py
+++ b/tests/comparators/test_text.py
@@ -69,7 +69,7 @@ def test_difference_between_iso88591_and_unicode(iso8859, unicode1):
def test_difference_between_iso88591_and_unicode_only(iso8859, tmpdir):
utf8_path = str(tmpdir.join('utf8'))
- with open(utf8_path, 'w') as f:
+ with open(utf8_path, 'wb') as f:
f.write(codecs.open(os.path.join(os.path.dirname(__file__), '../data/text_iso8859'), encoding='iso8859-1').read().encode('utf-8'))
utf8 = specialize(FilesystemFile(utf8_path))
difference = iso8859.compare(utf8)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git
More information about the Reproducible-commits
mailing list