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):
...
@@ -676,7 +676,7 @@ class _BufferedIOMixin(BufferedIOBase):
"""
"""
def
__init__
(
self
,
raw
):
def
__init__
(
self
,
raw
):
self
.
raw
=
raw
self
.
_
raw
=
raw
### Positioning ###
### Positioning ###
...
@@ -720,8 +720,8 @@ class _BufferedIOMixin(BufferedIOBase):
...
@@ -720,8 +720,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 ###
...
@@ -735,6 +735,10 @@ class _BufferedIOMixin(BufferedIOBase):
...
@@ -735,6 +735,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
...
@@ -1465,7 +1469,7 @@ class TextIOWrapper(TextIOBase):
...
@@ -1465,7 +1469,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
...
@@ -1520,6 +1524,10 @@ class TextIOWrapper(TextIOBase):
...
@@ -1520,6 +1524,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
...
@@ -1734,8 +1742,8 @@ class TextIOWrapper(TextIOBase):
...
@@ -1734,8 +1742,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
):
...
...
Lib/test/test_io.py
View file @
7f8f4180
...
@@ -730,6 +730,13 @@ class CommonBufferedTests:
...
@@ -730,6 +730,13 @@ class CommonBufferedTests:
self
.
assertRaises
(
self
.
UnsupportedOperation
,
bufio
.
tell
)
self
.
assertRaises
(
self
.
UnsupportedOperation
,
bufio
.
tell
)
self
.
assertRaises
(
self
.
UnsupportedOperation
,
bufio
.
seek
,
0
)
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
):
class
BufferedReaderTest
(
unittest
.
TestCase
,
CommonBufferedTests
):
read_mode
=
"rb"
read_mode
=
"rb"
...
@@ -2245,6 +2252,12 @@ class TextIOWrapperTest(unittest.TestCase):
...
@@ -2245,6 +2252,12 @@ class TextIOWrapperTest(unittest.TestCase):
self
.
assertRaises
(
self
.
UnsupportedOperation
,
txt
.
tell
)
self
.
assertRaises
(
self
.
UnsupportedOperation
,
txt
.
tell
)
self
.
assertRaises
(
self
.
UnsupportedOperation
,
txt
.
seek
,
0
)
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
):
class
CTextIOWrapperTest
(
TextIOWrapperTest
):
def
test_initialization
(
self
):
def
test_initialization
(
self
):
...
...
Misc/NEWS
View file @
7f8f4180
...
@@ -11,6 +11,8 @@ Core and Builtins
...
@@ -11,6 +11,8 @@ Core and Builtins
Library
Library
-------
-------
- Issue #10750: The ``raw`` attribute of buffered IO objects is now read-only.
- Deprecated assertDictContainsSubclass() in the unittest module.
- Deprecated assertDictContainsSubclass() in the unittest module.
...
...
Modules/_io/bufferedio.c
View file @
7f8f4180
...
@@ -1541,7 +1541,7 @@ static PyMethodDef bufferedreader_methods[] = {
...
@@ -1541,7 +1541,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
}
};
};
...
@@ -1926,7 +1926,7 @@ static PyMethodDef bufferedwriter_methods[] = {
...
@@ -1926,7 +1926,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
}
};
};
...
@@ -2320,7 +2320,7 @@ static PyMethodDef bufferedrandom_methods[] = {
...
@@ -2320,7 +2320,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
}
};
};
...
...
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