New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Port util/process_handler.py and util/tarutil.py #6082
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,77 +6,77 @@ | |
unicode_literals, with_statement) | ||
|
||
import tarfile | ||
from builtins import str | ||
|
||
import six | ||
from future.utils import implements_iterator | ||
|
||
|
||
if six.PY2: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now creating the same class for both Py2 and Py3. I'm not sure why the original author only patched the Py2 behavior - Py3 still needs the patch (see new line 64). |
||
class TarFile(tarfile.TarFile): | ||
def next(self): | ||
"""A copy and modification of the next() method in tarfile module. | ||
@implements_iterator | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Py2 expects the function |
||
class TarFile(tarfile.TarFile): | ||
|
||
The copy is from tarfile.py of CPython @102457:95df96aa2f5a | ||
def __next__(self): | ||
"""A copy and modification of the next() method in tarfile module. | ||
|
||
# Copyright (C) 2002 Lars Gustäbel <lars@gustaebel.de> | ||
# All rights reserved. | ||
# | ||
# Permission is hereby granted, free of charge, to any person | ||
# obtaining a copy of this software and associated documentation | ||
# files (the "Software"), to deal in the Software without | ||
# restriction, including without limitation the rights to use, | ||
# copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the | ||
# Software is furnished to do so, subject to the following | ||
# conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be | ||
# included in all copies or substantial portions of the Software. | ||
""" | ||
self._check("ra") | ||
if self.firstmember is not None: | ||
m = self.firstmember | ||
self.firstmember = None | ||
return m | ||
The copy is from tarfile.py of CPython @102457:95df96aa2f5a | ||
|
||
# Advance the file pointer. | ||
if self.offset != self.fileobj.tell(): | ||
self.fileobj.seek(self.offset - 1) | ||
if not self.fileobj.read(1): | ||
raise tarfile.ReadError("unexpected end of data") | ||
# Copyright (C) 2002 Lars Gustäbel <lars@gustaebel.de> | ||
# All rights reserved. | ||
# | ||
# Permission is hereby granted, free of charge, to any person | ||
# obtaining a copy of this software and associated documentation | ||
# files (the "Software"), to deal in the Software without | ||
# restriction, including without limitation the rights to use, | ||
# copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the | ||
# Software is furnished to do so, subject to the following | ||
# conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be | ||
# included in all copies or substantial portions of the Software. | ||
""" | ||
self._check("ra") | ||
if self.firstmember is not None: | ||
m = self.firstmember | ||
self.firstmember = None | ||
return m | ||
|
||
# Read the next block. | ||
tarinfo = None | ||
while True: | ||
try: | ||
tarinfo = self.tarinfo.fromtarfile(self) | ||
except tarfile.EOFHeaderError as e: | ||
if self.ignore_zeros: | ||
self._dbg(2, "0x%X: %s" % (self.offset, e)) | ||
self.offset += tarfile.BLOCKSIZE | ||
continue | ||
except tarfile.InvalidHeaderError as e: | ||
if self.ignore_zeros: | ||
self._dbg(2, "0x%X: %s" % (self.offset, e)) | ||
self.offset += tarfile.BLOCKSIZE | ||
continue | ||
# Modify here, to raise exceptions if errorlevel is bigger than 0. | ||
elif self.errorlevel > 0: | ||
raise tarfile.ReadError(str(e)) | ||
except tarfile.EmptyHeaderError: | ||
if self.offset == 0: | ||
raise tarfile.ReadError("empty file") | ||
except tarfile.TruncatedHeaderError as e: | ||
if self.offset == 0: | ||
raise tarfile.ReadError(str(e)) | ||
except tarfile.SubsequentHeaderError as e: | ||
# Advance the file pointer. | ||
if self.offset != self.fileobj.tell(): | ||
self.fileobj.seek(self.offset - 1) | ||
if not self.fileobj.read(1): | ||
raise tarfile.ReadError("unexpected end of data") | ||
|
||
# Read the next block. | ||
tarinfo = None | ||
while True: | ||
try: | ||
tarinfo = self.tarinfo.fromtarfile(self) | ||
except tarfile.EOFHeaderError as e: | ||
if self.ignore_zeros: | ||
self._dbg(2, "0x%X: %s" % (self.offset, e)) | ||
self.offset += tarfile.BLOCKSIZE | ||
continue | ||
except tarfile.InvalidHeaderError as e: | ||
if self.ignore_zeros: | ||
self._dbg(2, "0x%X: %s" % (self.offset, e)) | ||
self.offset += tarfile.BLOCKSIZE | ||
continue | ||
# Modify here, to raise exceptions if errorlevel is bigger than 0. | ||
elif self.errorlevel > 0: | ||
raise tarfile.ReadError(str(e)) | ||
except tarfile.EmptyHeaderError: | ||
if self.offset == 0: | ||
raise tarfile.ReadError("empty file") | ||
except tarfile.TruncatedHeaderError as e: | ||
if self.offset == 0: | ||
raise tarfile.ReadError(str(e)) | ||
break | ||
except tarfile.SubsequentHeaderError as e: | ||
raise tarfile.ReadError(str(e)) | ||
break | ||
|
||
if tarinfo is not None: | ||
self.members.append(tarinfo) | ||
else: | ||
self._loaded = True | ||
if tarinfo is not None: | ||
self.members.append(tarinfo) | ||
else: | ||
self._loaded = True | ||
|
||
return tarinfo | ||
else: | ||
TarFile = tarfile.TarFile | ||
return tarinfo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
StringIO.StringIO()
allows for both bytes and unicode. The library was removed in Python3.Instead, we're using
io.BytesIO()
, which allows for only bytes. This is what we want -io.StringIO()
fails the tests whereas this passes.