Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
a7ba6fc5
Commit
a7ba6fc5
authored
Dec 27, 2006
by
Lars Gustäbel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Patch #1504073: Fix tarfile.open() for mode "r" with a fileobj argument.
Will backport to 2.5.
parent
71662323
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
0 deletions
+17
-0
Lib/tarfile.py
Lib/tarfile.py
+4
-0
Lib/test/test_tarfile.py
Lib/test/test_tarfile.py
+11
-0
Misc/NEWS
Misc/NEWS
+2
-0
No files found.
Lib/tarfile.py
View file @
a7ba6fc5
...
...
@@ -1141,9 +1141,13 @@ class TarFile(object):
# Find out which *open() is appropriate for opening the file.
for
comptype
in
cls
.
OPEN_METH
:
func
=
getattr
(
cls
,
cls
.
OPEN_METH
[
comptype
])
if
fileobj
is
not
None
:
saved_pos
=
fileobj
.
tell
()
try
:
return
func
(
name
,
"r"
,
fileobj
)
except
(
ReadError
,
CompressionError
):
if
fileobj
is
not
None
:
fileobj
.
seek
(
saved_pos
)
continue
raise
ReadError
(
"file could not be opened successfully"
)
...
...
Lib/test/test_tarfile.py
View file @
a7ba6fc5
...
...
@@ -648,6 +648,16 @@ class HeaderErrorTest(unittest.TestCase):
b
=
"a"
+
buf
[
1
:]
# manipulate the buffer, so checksum won't match.
self
.
assertRaises
(
tarfile
.
HeaderError
,
tarfile
.
TarInfo
.
frombuf
,
b
)
class
OpenFileobjTest
(
BaseTest
):
# Test for SF bug #1496501.
def
test_opener
(
self
):
fobj
=
StringIO
.
StringIO
(
"foo
\
n
"
)
try
:
tarfile
.
open
(
""
,
"r"
,
fileobj
=
fobj
)
except
tarfile
.
ReadError
:
self
.
assertEqual
(
fobj
.
tell
(),
0
,
"fileobj's position has moved"
)
if
bz2
:
# Bzip2 TestCases
class
ReadTestBzip2
(
ReadTestGzip
):
...
...
@@ -693,6 +703,7 @@ def test_main():
tests
=
[
FileModeTest
,
HeaderErrorTest
,
OpenFileobjTest
,
ReadTest
,
ReadStreamTest
,
ReadDetectTest
,
...
...
Misc/NEWS
View file @
a7ba6fc5
...
...
@@ -103,6 +103,8 @@ Core and builtins
Library
-------
-
Patch
#
1504073
:
Fix
tarfile
.
open
()
for
mode
"r"
with
a
fileobj
argument
.
-
Patch
#
1182394
from
Shane
Holloway
:
speed
up
HMAC
.
hexdigest
.
-
Patch
#
1262036
:
Prevent
TarFiles
from
being
added
to
themselves
under
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment