Commit 6cfc5124 authored by Antoine Pitrou's avatar Antoine Pitrou

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.
........
parent 9fc6b6c4
...@@ -674,7 +674,7 @@ class _BufferedIOMixin(BufferedIOBase): ...@@ -674,7 +674,7 @@ class _BufferedIOMixin(BufferedIOBase):
""" """
def __init__(self, raw): def __init__(self, raw):
self.raw = raw self._raw = raw
### Positioning ### ### Positioning ###
...@@ -718,8 +718,8 @@ class _BufferedIOMixin(BufferedIOBase): ...@@ -718,8 +718,8 @@ class _BufferedIOMixin(BufferedIOBase):
if self.raw is None: if self.raw is None:
raise ValueError("raw stream already detached") raise ValueError("raw stream already detached")
self.flush() self.flush()
raw = self.raw raw = self._raw
self.raw = None self._raw = None
return raw return raw
### Inquiries ### ### Inquiries ###
...@@ -733,6 +733,10 @@ class _BufferedIOMixin(BufferedIOBase): ...@@ -733,6 +733,10 @@ class _BufferedIOMixin(BufferedIOBase):
def writable(self): def writable(self):
return self.raw.writable() return self.raw.writable()
@property
def raw(self):
return self._raw
@property @property
def closed(self): def closed(self):
return self.raw.closed return self.raw.closed
...@@ -1444,7 +1448,7 @@ class TextIOWrapper(TextIOBase): ...@@ -1444,7 +1448,7 @@ class TextIOWrapper(TextIOBase):
if not isinstance(errors, str): if not isinstance(errors, str):
raise ValueError("invalid errors: %r" % errors) raise ValueError("invalid errors: %r" % errors)
self.buffer = buffer self._buffer = buffer
self._line_buffering = line_buffering self._line_buffering = line_buffering
self._encoding = encoding self._encoding = encoding
self._errors = errors self._errors = errors
...@@ -1499,6 +1503,10 @@ class TextIOWrapper(TextIOBase): ...@@ -1499,6 +1503,10 @@ class TextIOWrapper(TextIOBase):
def line_buffering(self): def line_buffering(self):
return self._line_buffering return self._line_buffering
@property
def buffer(self):
return self._buffer
def seekable(self): def seekable(self):
return self._seekable return self._seekable
...@@ -1713,8 +1721,8 @@ class TextIOWrapper(TextIOBase): ...@@ -1713,8 +1721,8 @@ class TextIOWrapper(TextIOBase):
if self.buffer is None: if self.buffer is None:
raise ValueError("buffer is already detached") raise ValueError("buffer is already detached")
self.flush() self.flush()
buffer = self.buffer buffer = self._buffer
self.buffer = None self._buffer = None
return buffer return buffer
def seek(self, cookie, whence=0): def seek(self, cookie, whence=0):
......
...@@ -693,6 +693,13 @@ class CommonBufferedTests: ...@@ -693,6 +693,13 @@ class CommonBufferedTests:
b.close() b.close()
self.assertRaises(ValueError, b.flush) self.assertRaises(ValueError, b.flush)
def test_readonly_attributes(self):
raw = self.MockRawIO()
buf = self.tp(raw)
x = self.MockRawIO()
with self.assertRaises(AttributeError):
buf.raw = x
class BufferedReaderTest(unittest.TestCase, CommonBufferedTests): class BufferedReaderTest(unittest.TestCase, CommonBufferedTests):
read_mode = "rb" read_mode = "rb"
...@@ -2210,6 +2217,12 @@ class TextIOWrapperTest(unittest.TestCase): ...@@ -2210,6 +2217,12 @@ class TextIOWrapperTest(unittest.TestCase):
txt.close() txt.close()
self.assertRaises(ValueError, txt.flush) 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):
txt.buffer = buf
class CTextIOWrapperTest(TextIOWrapperTest): class CTextIOWrapperTest(TextIOWrapperTest):
def test_initialization(self): def test_initialization(self):
......
...@@ -24,6 +24,8 @@ Core and Builtins ...@@ -24,6 +24,8 @@ Core and Builtins
Library Library
------- -------
- Issue #10750: The ``raw`` attribute of buffered IO objects is now read-only.
- Issue #6791: Limit header line length (to 65535 bytes) in http.client - Issue #6791: Limit header line length (to 65535 bytes) in http.client
and http.server, to avoid denial of services from the other party. and http.server, to avoid denial of services from the other party.
......
...@@ -1500,7 +1500,7 @@ static PyMethodDef bufferedreader_methods[] = { ...@@ -1500,7 +1500,7 @@ static PyMethodDef bufferedreader_methods[] = {
}; };
static PyMemberDef bufferedreader_members[] = { static PyMemberDef bufferedreader_members[] = {
{"raw", T_OBJECT, offsetof(buffered, raw), 0}, {"raw", T_OBJECT, offsetof(buffered, raw), READONLY},
{NULL} {NULL}
}; };
...@@ -1882,7 +1882,7 @@ static PyMethodDef bufferedwriter_methods[] = { ...@@ -1882,7 +1882,7 @@ static PyMethodDef bufferedwriter_methods[] = {
}; };
static PyMemberDef bufferedwriter_members[] = { static PyMemberDef bufferedwriter_members[] = {
{"raw", T_OBJECT, offsetof(buffered, raw), 0}, {"raw", T_OBJECT, offsetof(buffered, raw), READONLY},
{NULL} {NULL}
}; };
...@@ -2272,7 +2272,7 @@ static PyMethodDef bufferedrandom_methods[] = { ...@@ -2272,7 +2272,7 @@ static PyMethodDef bufferedrandom_methods[] = {
}; };
static PyMemberDef bufferedrandom_members[] = { static PyMemberDef bufferedrandom_members[] = {
{"raw", T_OBJECT, offsetof(buffered, raw), 0}, {"raw", T_OBJECT, offsetof(buffered, raw), READONLY},
{NULL} {NULL}
}; };
......
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