Commit beaa3ada authored by Serhiy Storchaka's avatar Serhiy Storchaka

Issue #10355: SpooledTemporaryFile properties and xreadline method now work for unrolled files.

parent 62e709c5
......@@ -546,10 +546,6 @@ class SpooledTemporaryFile:
def closed(self):
return self._file.closed
@property
def encoding(self):
return self._file.encoding
def fileno(self):
self.rollover()
return self._file.fileno()
......@@ -562,15 +558,17 @@ class SpooledTemporaryFile:
@property
def mode(self):
return self._file.mode
try:
return self._file.mode
except AttributeError:
return self._TemporaryFileArgs[0]
@property
def name(self):
return self._file.name
@property
def newlines(self):
return self._file.newlines
try:
return self._file.name
except AttributeError:
return None
def next(self):
return self._file.next
......@@ -610,4 +608,7 @@ class SpooledTemporaryFile:
return rv
def xreadlines(self, *args):
return self._file.xreadlines(*args)
try:
return self._file.xreadlines(*args)
except AttributeError:
return iter(self._file.readlines(*args))
......@@ -738,6 +738,17 @@ class test_SpooledTemporaryFile(TC):
f.write(b'x')
self.assertTrue(f._rolled)
def test_xreadlines(self):
f = self.do_create(max_size=20)
f.write(b'abc\n' * 5)
f.seek(0)
self.assertFalse(f._rolled)
self.assertEqual(list(f.xreadlines()), [b'abc\n'] * 5)
f.write(b'x\ny')
self.assertTrue(f._rolled)
f.seek(0)
self.assertEqual(list(f.xreadlines()), [b'abc\n'] * 5 + [b'x\n', b'y'])
def test_sparse(self):
# A SpooledTemporaryFile that is written late in the file will extend
# when that occurs
......@@ -793,6 +804,26 @@ class test_SpooledTemporaryFile(TC):
seek(0, 0)
self.assertTrue(read(70) == 'a'*35 + 'b'*35)
def test_properties(self):
f = tempfile.SpooledTemporaryFile(max_size=10)
f.write(b'x' * 10)
self.assertFalse(f._rolled)
self.assertEqual(f.mode, 'w+b')
self.assertIsNone(f.name)
with self.assertRaises(AttributeError):
f.newlines
with self.assertRaises(AttributeError):
f.encoding
f.write(b'x')
self.assertTrue(f._rolled)
self.assertEqual(f.mode, 'w+b')
self.assertIsNotNone(f.name)
with self.assertRaises(AttributeError):
f.newlines
with self.assertRaises(AttributeError):
f.encoding
def test_context_manager_before_rollover(self):
# A SpooledTemporaryFile can be used as a context manager
with tempfile.SpooledTemporaryFile(max_size=1) as f:
......
......@@ -202,6 +202,11 @@ Core and Builtins
Library
-------
- Issue #10355: In SpooledTemporaryFile class mode and name properties and
xreadlines method now work for unrolled files. encoding and newlines
properties now removed as they have no sense and always produced
AttributeError.
- Issue #16686: Fixed a lot of bugs in audioop module. Fixed crashes in
avgpp(), maxpp() and ratecv(). Fixed an integer overflow in add(), bias(),
and ratecv(). reverse(), lin2lin() and ratecv() no more lose precision for
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment