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
7cc9c8bb
Commit
7cc9c8bb
authored
Dec 01, 2007
by
Lars Gustäbel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #1531: Read fileobj from the current offset, do not seek to
the start. (backport from r59260)
parent
8334a4fc
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
3 deletions
+46
-3
Lib/tarfile.py
Lib/tarfile.py
+2
-1
Lib/test/test_tarfile.py
Lib/test/test_tarfile.py
+41
-2
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/tarfile.py
View file @
7cc9c8bb
...
@@ -1065,7 +1065,8 @@ class TarFile(object):
...
@@ -1065,7 +1065,8 @@ class TarFile(object):
self
.
closed
=
False
self
.
closed
=
False
self
.
members
=
[]
# list of members as TarInfo objects
self
.
members
=
[]
# list of members as TarInfo objects
self
.
_loaded
=
False
# flag if all members have been read
self
.
_loaded
=
False
# flag if all members have been read
self
.
offset
=
0L
# current position in the archive file
self
.
offset
=
self
.
fileobj
.
tell
()
# current position in the archive file
self
.
inodes
=
{}
# dictionary caching the inodes of
self
.
inodes
=
{}
# dictionary caching the inodes of
# archive members already added
# archive members already added
...
...
Lib/test/test_tarfile.py
View file @
7cc9c8bb
...
@@ -260,6 +260,38 @@ class ReadStreamAsteriskTest(ReadStreamTest):
...
@@ -260,6 +260,38 @@ class ReadStreamAsteriskTest(ReadStreamTest):
mode
=
self
.
mode
+
self
.
sep
+
"*"
mode
=
self
.
mode
+
self
.
sep
+
"*"
self
.
tar
=
tarfile
.
open
(
tarname
(
self
.
comp
),
mode
)
self
.
tar
=
tarfile
.
open
(
tarname
(
self
.
comp
),
mode
)
class
ReadFileobjTest
(
BaseTest
):
def
test_fileobj_with_offset
(
self
):
# Skip the first member and store values from the second member
# of the testtar.
self
.
tar
.
next
()
t
=
self
.
tar
.
next
()
name
=
t
.
name
offset
=
t
.
offset
data
=
self
.
tar
.
extractfile
(
t
).
read
()
self
.
tar
.
close
()
# Open the testtar and seek to the offset of the second member.
if
self
.
comp
==
"gz"
:
_open
=
gzip
.
GzipFile
elif
self
.
comp
==
"bz2"
:
_open
=
bz2
.
BZ2File
else
:
_open
=
open
fobj
=
_open
(
tarname
(
self
.
comp
),
"rb"
)
fobj
.
seek
(
offset
)
# Test if the tarfile starts with the second member.
self
.
tar
=
tarfile
.
open
(
tarname
(
self
.
comp
),
"r:"
,
fileobj
=
fobj
)
t
=
self
.
tar
.
next
()
self
.
assertEqual
(
t
.
name
,
name
)
# Read to the end of fileobj and test if seeking back to the
# beginning works.
self
.
tar
.
getmembers
()
self
.
assertEqual
(
self
.
tar
.
extractfile
(
t
).
read
(),
data
,
"seek back did not work"
)
class
WriteTest
(
BaseTest
):
class
WriteTest
(
BaseTest
):
mode
=
'w'
mode
=
'w'
...
@@ -624,6 +656,8 @@ class ReadAsteriskTestGzip(ReadAsteriskTest):
...
@@ -624,6 +656,8 @@ class ReadAsteriskTestGzip(ReadAsteriskTest):
comp
=
"gz"
comp
=
"gz"
class
ReadStreamAsteriskTestGzip
(
ReadStreamAsteriskTest
):
class
ReadStreamAsteriskTestGzip
(
ReadStreamAsteriskTest
):
comp
=
"gz"
comp
=
"gz"
class
ReadFileobjTestGzip
(
ReadFileobjTest
):
comp
=
"gz"
# Filemode test cases
# Filemode test cases
...
@@ -680,6 +714,8 @@ if bz2:
...
@@ -680,6 +714,8 @@ if bz2:
comp
=
"bz2"
comp
=
"bz2"
class
ReadStreamAsteriskTestBzip2
(
ReadStreamAsteriskTest
):
class
ReadStreamAsteriskTestBzip2
(
ReadStreamAsteriskTest
):
comp
=
"bz2"
comp
=
"bz2"
class
ReadFileobjTestBzip2
(
ReadFileobjTest
):
comp
=
"bz2"
# If importing gzip failed, discard the Gzip TestCases.
# If importing gzip failed, discard the Gzip TestCases.
if
not
gzip
:
if
not
gzip
:
...
@@ -713,6 +749,7 @@ def test_main():
...
@@ -713,6 +749,7 @@ def test_main():
ReadDetectFileobjTest
,
ReadDetectFileobjTest
,
ReadAsteriskTest
,
ReadAsteriskTest
,
ReadStreamAsteriskTest
,
ReadStreamAsteriskTest
,
ReadFileobjTest
,
WriteTest
,
WriteTest
,
Write100Test
,
Write100Test
,
WriteSize0Test
,
WriteSize0Test
,
...
@@ -730,7 +767,8 @@ def test_main():
...
@@ -730,7 +767,8 @@ def test_main():
ReadTestGzip
,
ReadStreamTestGzip
,
ReadTestGzip
,
ReadStreamTestGzip
,
WriteTestGzip
,
WriteStreamTestGzip
,
WriteTestGzip
,
WriteStreamTestGzip
,
ReadDetectTestGzip
,
ReadDetectFileobjTestGzip
,
ReadDetectTestGzip
,
ReadDetectFileobjTestGzip
,
ReadAsteriskTestGzip
,
ReadStreamAsteriskTestGzip
ReadAsteriskTestGzip
,
ReadStreamAsteriskTestGzip
,
ReadFileobjTestGzip
])
])
if
bz2
:
if
bz2
:
...
@@ -738,7 +776,8 @@ def test_main():
...
@@ -738,7 +776,8 @@ def test_main():
ReadTestBzip2
,
ReadStreamTestBzip2
,
ReadTestBzip2
,
ReadStreamTestBzip2
,
WriteTestBzip2
,
WriteStreamTestBzip2
,
WriteTestBzip2
,
WriteStreamTestBzip2
,
ReadDetectTestBzip2
,
ReadDetectFileobjTestBzip2
,
ReadDetectTestBzip2
,
ReadDetectFileobjTestBzip2
,
ReadAsteriskTestBzip2
,
ReadStreamAsteriskTestBzip2
ReadAsteriskTestBzip2
,
ReadStreamAsteriskTestBzip2
,
ReadFileobjTestBzip2
])
])
try
:
try
:
test_support
.
run_unittest
(
*
tests
)
test_support
.
run_unittest
(
*
tests
)
...
...
Misc/NEWS
View file @
7cc9c8bb
...
@@ -46,6 +46,9 @@ Core and builtins
...
@@ -46,6 +46,9 @@ Core and builtins
Library
Library
-------
-------
- Issue #1531: tarfile.py: Read fileobj from the current offset, do not
seek to the start.
- Issue 1429818: patch for trace and doctest modules so they play nicely
- Issue 1429818: patch for trace and doctest modules so they play nicely
together.
together.
...
...
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