mirror of https://github.com/python/cpython
Merged revisions 87427 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r87427 | antoine.pitrou | 2010-12-21 22:20:59 +0100 (mar., 21 déc. 2010) | 3 lines Issue #10750: The `raw` attribute of buffered IO objects is now read-only. ........
This commit is contained in:
parent
5cf3672999
commit
fc9ead69e5
20
Lib/_pyio.py
20
Lib/_pyio.py
|
@ -678,7 +678,7 @@ class _BufferedIOMixin(BufferedIOBase):
|
|||
"""
|
||||
|
||||
def __init__(self, raw):
|
||||
self.raw = raw
|
||||
self._raw = raw
|
||||
|
||||
### Positioning ###
|
||||
|
||||
|
@ -722,8 +722,8 @@ class _BufferedIOMixin(BufferedIOBase):
|
|||
if self.raw is None:
|
||||
raise ValueError("raw stream already detached")
|
||||
self.flush()
|
||||
raw = self.raw
|
||||
self.raw = None
|
||||
raw = self._raw
|
||||
self._raw = None
|
||||
return raw
|
||||
|
||||
### Inquiries ###
|
||||
|
@ -737,6 +737,10 @@ class _BufferedIOMixin(BufferedIOBase):
|
|||
def writable(self):
|
||||
return self.raw.writable()
|
||||
|
||||
@property
|
||||
def raw(self):
|
||||
return self._raw
|
||||
|
||||
@property
|
||||
def closed(self):
|
||||
return self.raw.closed
|
||||
|
@ -1456,7 +1460,7 @@ class TextIOWrapper(TextIOBase):
|
|||
if not isinstance(errors, basestring):
|
||||
raise ValueError("invalid errors: %r" % errors)
|
||||
|
||||
self.buffer = buffer
|
||||
self._buffer = buffer
|
||||
self._line_buffering = line_buffering
|
||||
self._encoding = encoding
|
||||
self._errors = errors
|
||||
|
@ -1511,6 +1515,10 @@ class TextIOWrapper(TextIOBase):
|
|||
def line_buffering(self):
|
||||
return self._line_buffering
|
||||
|
||||
@property
|
||||
def buffer(self):
|
||||
return self._buffer
|
||||
|
||||
def seekable(self):
|
||||
return self._seekable
|
||||
|
||||
|
@ -1724,8 +1732,8 @@ class TextIOWrapper(TextIOBase):
|
|||
if self.buffer is None:
|
||||
raise ValueError("buffer is already detached")
|
||||
self.flush()
|
||||
buffer = self.buffer
|
||||
self.buffer = None
|
||||
buffer = self._buffer
|
||||
self._buffer = None
|
||||
return buffer
|
||||
|
||||
def seek(self, cookie, whence=0):
|
||||
|
|
|
@ -701,6 +701,13 @@ class CommonBufferedTests:
|
|||
b.close()
|
||||
self.assertRaises(ValueError, b.flush)
|
||||
|
||||
def test_readonly_attributes(self):
|
||||
raw = self.MockRawIO()
|
||||
buf = self.tp(raw)
|
||||
x = self.MockRawIO()
|
||||
with self.assertRaises((AttributeError, TypeError)):
|
||||
buf.raw = x
|
||||
|
||||
|
||||
class BufferedReaderTest(unittest.TestCase, CommonBufferedTests):
|
||||
read_mode = "rb"
|
||||
|
@ -2211,6 +2218,12 @@ class TextIOWrapperTest(unittest.TestCase):
|
|||
txt.close()
|
||||
self.assertRaises(ValueError, txt.flush)
|
||||
|
||||
def test_readonly_attributes(self):
|
||||
txt = self.TextIOWrapper(self.BytesIO(self.testdata), encoding="ascii")
|
||||
buf = self.BytesIO(self.testdata)
|
||||
with self.assertRaises((AttributeError, TypeError)):
|
||||
txt.buffer = buf
|
||||
|
||||
class CTextIOWrapperTest(TextIOWrapperTest):
|
||||
|
||||
def test_initialization(self):
|
||||
|
|
|
@ -22,6 +22,8 @@ Core and Builtins
|
|||
Library
|
||||
-------
|
||||
|
||||
- Issue #10750: The ``raw`` attribute of buffered IO objects is now read-only.
|
||||
|
||||
- Issue #10242: unittest.TestCase.assertItemsEqual makes too many assumgptions
|
||||
about input.
|
||||
|
||||
|
|
|
@ -1513,7 +1513,7 @@ static PyMethodDef bufferedreader_methods[] = {
|
|||
};
|
||||
|
||||
static PyMemberDef bufferedreader_members[] = {
|
||||
{"raw", T_OBJECT, offsetof(buffered, raw), 0},
|
||||
{"raw", T_OBJECT, offsetof(buffered, raw), READONLY},
|
||||
{NULL}
|
||||
};
|
||||
|
||||
|
@ -1896,7 +1896,7 @@ static PyMethodDef bufferedwriter_methods[] = {
|
|||
};
|
||||
|
||||
static PyMemberDef bufferedwriter_members[] = {
|
||||
{"raw", T_OBJECT, offsetof(buffered, raw), 0},
|
||||
{"raw", T_OBJECT, offsetof(buffered, raw), READONLY},
|
||||
{NULL}
|
||||
};
|
||||
|
||||
|
@ -2286,7 +2286,7 @@ static PyMethodDef bufferedrandom_methods[] = {
|
|||
};
|
||||
|
||||
static PyMemberDef bufferedrandom_members[] = {
|
||||
{"raw", T_OBJECT, offsetof(buffered, raw), 0},
|
||||
{"raw", T_OBJECT, offsetof(buffered, raw), READONLY},
|
||||
{NULL}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue