Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
7f8f4180
Commit
7f8f4180
authored
Dec 21, 2010
by
Antoine Pitrou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #10750: The `raw` attribute of buffered IO objects is now read-only.
parent
cfee0e83
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
9 deletions
+32
-9
Lib/_pyio.py
Lib/_pyio.py
+14
-6
Lib/test/test_io.py
Lib/test/test_io.py
+13
-0
Misc/NEWS
Misc/NEWS
+2
-0
Modules/_io/bufferedio.c
Modules/_io/bufferedio.c
+3
-3
No files found.
Lib/_pyio.py
View file @
7f8f4180
...
...
@@ -676,7 +676,7 @@ class _BufferedIOMixin(BufferedIOBase):
"""
def
__init__
(
self
,
raw
):
self
.
raw
=
raw
self
.
_
raw
=
raw
### Positioning ###
...
...
@@ -720,8 +720,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 ###
...
...
@@ -735,6 +735,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
...
...
@@ -1465,7 +1469,7 @@ class TextIOWrapper(TextIOBase):
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
...
...
@@ -1520,6 +1524,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
...
...
@@ -1734,8 +1742,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
):
...
...
Lib/test/test_io.py
View file @
7f8f4180
...
...
@@ -730,6 +730,13 @@ class CommonBufferedTests:
self
.
assertRaises
(
self
.
UnsupportedOperation
,
bufio
.
tell
)
self
.
assertRaises
(
self
.
UnsupportedOperation
,
bufio
.
seek
,
0
)
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"
...
...
@@ -2245,6 +2252,12 @@ class TextIOWrapperTest(unittest.TestCase):
self
.
assertRaises
(
self
.
UnsupportedOperation
,
txt
.
tell
)
self
.
assertRaises
(
self
.
UnsupportedOperation
,
txt
.
seek
,
0
)
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
):
...
...
Misc/NEWS
View file @
7f8f4180
...
...
@@ -11,6 +11,8 @@ Core and Builtins
Library
-------
- Issue #10750: The ``raw`` attribute of buffered IO objects is now read-only.
- Deprecated assertDictContainsSubclass() in the unittest module.
...
...
Modules/_io/bufferedio.c
View file @
7f8f4180
...
...
@@ -1541,7 +1541,7 @@ static PyMethodDef bufferedreader_methods[] = {
};
static
PyMemberDef
bufferedreader_members
[]
=
{
{
"raw"
,
T_OBJECT
,
offsetof
(
buffered
,
raw
),
0
},
{
"raw"
,
T_OBJECT
,
offsetof
(
buffered
,
raw
),
READONLY
},
{
NULL
}
};
...
...
@@ -1926,7 +1926,7 @@ static PyMethodDef bufferedwriter_methods[] = {
};
static
PyMemberDef
bufferedwriter_members
[]
=
{
{
"raw"
,
T_OBJECT
,
offsetof
(
buffered
,
raw
),
0
},
{
"raw"
,
T_OBJECT
,
offsetof
(
buffered
,
raw
),
READONLY
},
{
NULL
}
};
...
...
@@ -2320,7 +2320,7 @@ static PyMethodDef bufferedrandom_methods[] = {
};
static
PyMemberDef
bufferedrandom_members
[]
=
{
{
"raw"
,
T_OBJECT
,
offsetof
(
buffered
,
raw
),
0
},
{
"raw"
,
T_OBJECT
,
offsetof
(
buffered
,
raw
),
READONLY
},
{
NULL
}
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment