mirror of
https://github.com/python/cpython.git
synced 2025-08-19 08:11:46 +00:00
Patch #1695229: Fix a regression with tarfile.open() and a missing name
argument.
This commit is contained in:
parent
d220144a84
commit
9319e43c67
3 changed files with 14 additions and 3 deletions
|
@ -1044,6 +1044,8 @@ class TarFile(object):
|
||||||
can be determined, `mode' is overridden by `fileobj's mode.
|
can be determined, `mode' is overridden by `fileobj's mode.
|
||||||
`fileobj' is not closed, when TarFile is closed.
|
`fileobj' is not closed, when TarFile is closed.
|
||||||
"""
|
"""
|
||||||
|
self.name = name
|
||||||
|
if self.name is not None:
|
||||||
self.name = os.path.abspath(name)
|
self.name = os.path.abspath(name)
|
||||||
|
|
||||||
if len(mode) > 1 or mode not in "raw":
|
if len(mode) > 1 or mode not in "raw":
|
||||||
|
|
|
@ -633,15 +633,21 @@ class FileModeTest(unittest.TestCase):
|
||||||
self.assertEqual(tarfile.filemode(07111), '---s--s--t')
|
self.assertEqual(tarfile.filemode(07111), '---s--s--t')
|
||||||
|
|
||||||
class OpenFileobjTest(BaseTest):
|
class OpenFileobjTest(BaseTest):
|
||||||
# Test for SF bug #1496501.
|
|
||||||
|
|
||||||
def test_opener(self):
|
def test_opener(self):
|
||||||
|
# Test for SF bug #1496501.
|
||||||
fobj = StringIO.StringIO("foo\n")
|
fobj = StringIO.StringIO("foo\n")
|
||||||
try:
|
try:
|
||||||
tarfile.open("", "r", fileobj=fobj)
|
tarfile.open("", mode="r", fileobj=fobj)
|
||||||
except tarfile.ReadError:
|
except tarfile.ReadError:
|
||||||
self.assertEqual(fobj.tell(), 0, "fileobj's position has moved")
|
self.assertEqual(fobj.tell(), 0, "fileobj's position has moved")
|
||||||
|
|
||||||
|
def test_fileobj(self):
|
||||||
|
# Test for SF bug #1695229, opening a tarfile without
|
||||||
|
# a name argument.
|
||||||
|
tarfile.open(mode="r", fileobj=open(tarname("")))
|
||||||
|
tarfile.TarFile(mode="r", fileobj=open(tarname("")))
|
||||||
|
|
||||||
if bz2:
|
if bz2:
|
||||||
# Bzip2 TestCases
|
# Bzip2 TestCases
|
||||||
class ReadTestBzip2(ReadTestGzip):
|
class ReadTestBzip2(ReadTestGzip):
|
||||||
|
|
|
@ -12,6 +12,9 @@ What's New in Python 2.5.2c1?
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Patch #1695229: Fix a regression with tarfile.open() and a missing name
|
||||||
|
argument.
|
||||||
|
|
||||||
- tarfile.py: Fix directory names to have only one trailing slash.
|
- tarfile.py: Fix directory names to have only one trailing slash.
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue