mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-25455: Fixed crashes in repr of recursive buffered file-like objects. (#514)
This commit is contained in:
parent
77ed11552d
commit
a5af6e1af7
6 changed files with 74 additions and 9 deletions
|
@ -1014,6 +1014,16 @@ class CommonBufferedTests:
|
|||
raw.name = b"dummy"
|
||||
self.assertEqual(repr(b), "<%s name=b'dummy'>" % clsname)
|
||||
|
||||
def test_recursive_repr(self):
|
||||
# Issue #25455
|
||||
raw = self.MockRawIO()
|
||||
b = self.tp(raw)
|
||||
with support.swap_attr(raw, 'name', b):
|
||||
try:
|
||||
repr(b) # Should not crash
|
||||
except RuntimeError:
|
||||
pass
|
||||
|
||||
def test_flush_error_on_close(self):
|
||||
# Test that buffered file is closed despite failed flush
|
||||
# and that flush() is called before file closed.
|
||||
|
@ -2435,6 +2445,16 @@ class TextIOWrapperTest(unittest.TestCase):
|
|||
t.buffer.detach()
|
||||
repr(t) # Should not raise an exception
|
||||
|
||||
def test_recursive_repr(self):
|
||||
# Issue #25455
|
||||
raw = self.BytesIO()
|
||||
t = self.TextIOWrapper(raw)
|
||||
with support.swap_attr(raw, 'name', t):
|
||||
try:
|
||||
repr(t) # Should not crash
|
||||
except RuntimeError:
|
||||
pass
|
||||
|
||||
def test_line_buffering(self):
|
||||
r = self.BytesIO()
|
||||
b = self.BufferedWriter(r, 1000)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue