"""
def __init__(self, raw):
- self.raw = raw
+ self._raw = raw
### Positioning ###
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 ###
def writable(self):
return self.raw.writable()
+ @property
+ def raw(self):
+ return self._raw
+
@property
def closed(self):
return self.raw.closed
if not isinstance(errors, str):
raise ValueError("invalid errors: %r" % errors)
- self.buffer = buffer
+ self._buffer = buffer
self._line_buffering = line_buffering
self._encoding = encoding
self._errors = errors
def line_buffering(self):
return self._line_buffering
+ @property
+ def buffer(self):
+ return self._buffer
+
def seekable(self):
return self._seekable
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):
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):
+ buf.raw = x
+
class BufferedReaderTest(unittest.TestCase, CommonBufferedTests):
read_mode = "rb"
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):
+ txt.buffer = buf
+
class CTextIOWrapperTest(TextIOWrapperTest):
def test_initialization(self):
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
and http.server, to avoid denial of services from the other party.
};
static PyMemberDef bufferedreader_members[] = {
- {"raw", T_OBJECT, offsetof(buffered, raw), 0},
+ {"raw", T_OBJECT, offsetof(buffered, raw), READONLY},
{NULL}
};
};
static PyMemberDef bufferedwriter_members[] = {
- {"raw", T_OBJECT, offsetof(buffered, raw), 0},
+ {"raw", T_OBJECT, offsetof(buffered, raw), READONLY},
{NULL}
};
};
static PyMemberDef bufferedrandom_members[] = {
- {"raw", T_OBJECT, offsetof(buffered, raw), 0},
+ {"raw", T_OBJECT, offsetof(buffered, raw), READONLY},
{NULL}
};