Open unarchive file in binary mode

Recent Python3 versions require open() to specify binary mode if the data is anything other than text.

Python3: Use int() instead of long() in unarchive

Changes long() to int() for CRC values in the unarchive module. Affects unarchiving of zip files. Since CRC values in zipfile are 32 bits the behaviour should be unchanged even in Python 2.
This commit is contained in:
Karl Bergström 2017-03-10 16:16:45 +01:00 committed by Toshio Kuratomi
parent ba977b7cd7
commit 561d424a0e

View file

@ -169,7 +169,7 @@ BUFSIZE = 65536
def crc32(path):
''' Return a CRC32 checksum of a file '''
return binascii.crc32(open(path).read()) & 0xffffffff
return binascii.crc32(open(path, 'rb').read()) & 0xffffffff
def shell_escape(string):
''' Quote meta-characters in the args for the unix shell '''
@ -218,7 +218,7 @@ class ZipArchive(object):
for line in out.splitlines()[3:-2]:
fields = line.split(None, 7)
self._files_in_archive.append(fields[7])
self._infodict[fields[7]] = long(fields[6])
self._infodict[fields[7]] = int(fields[6])
def _crc32(self, path):
if self._infodict:
@ -237,7 +237,7 @@ class ZipArchive(object):
else:
try:
for item in archive.infolist():
self._infodict[item.filename] = long(item.CRC)
self._infodict[item.filename] = int(item.CRC)
except:
archive.close()
raise UnarchiveError('Unable to list files in the archive')
@ -800,6 +800,7 @@ def main():
# If download fails, raise a proper exception
if rsp is None:
raise Exception(info['msg'])
# open in binary mode for python3
f = open(package, 'wb')
# Read 1kb at a time to save on ram