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.
pull/23427/head
Karl Bergström 8 years ago committed by Toshio Kuratomi
parent 1963e506ec
commit c7860d4d4b

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

Loading…
Cancel
Save