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
0926ad1f
Commit
0926ad1f
authored
Jun 06, 2009
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
give the C implementation of TextIOWrapper the errors property #6217
parent
3bbbf18a
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
50 additions
and
26 deletions
+50
-26
Doc/library/io.rst
Doc/library/io.rst
+5
-5
Lib/_pyio.py
Lib/_pyio.py
+11
-0
Lib/test/test_io.py
Lib/test/test_io.py
+6
-0
Lib/test/test_memoryio.py
Lib/test/test_memoryio.py
+3
-3
Misc/NEWS
Misc/NEWS
+4
-0
Modules/_io/stringio.c
Modules/_io/stringio.c
+0
-18
Modules/_io/textio.c
Modules/_io/textio.c
+21
-0
No files found.
Doc/library/io.rst
View file @
0926ad1f
...
...
@@ -600,6 +600,10 @@ Text I/O
The name of the encoding used to decode the stream's bytes into
strings, and to encode strings into bytes.
.. attribute:: errors
The error setting of the decoder or encoder.
.. attribute:: newlines
A string, a tuple of strings, or ``None``, indicating the newlines
...
...
@@ -665,13 +669,9 @@ Text I/O
If *line_buffering* is ``True``, :meth:`flush` is implied when a call to
write contains a newline character.
:class:`TextIOWrapper` provides
these data attributes
in addition to those of
:class:`TextIOWrapper` provides
one attribute
in addition to those of
:class:`TextIOBase` and its parents:
.. attribute:: errors
The encoding and decoding error setting.
.. attribute:: line_buffering
Whether line buffering is enabled.
...
...
Lib/_pyio.py
View file @
0926ad1f
...
...
@@ -1286,6 +1286,13 @@ class TextIOBase(IOBase):
"""
return
None
@
property
def
errors
(
self
):
"""Error setting of the decoder or encoder.
Subclasses should override."""
return
None
io
.
TextIOBase
.
register
(
TextIOBase
)
...
...
@@ -1932,6 +1939,10 @@ class StringIO(TextIOWrapper):
# that's a implementation detail.
return
object
.
__repr__
(
self
)
@
property
def
errors
(
self
):
return
None
@
property
def
encoding
(
self
):
return
None
...
...
Lib/test/test_io.py
View file @
0926ad1f
...
...
@@ -2024,6 +2024,12 @@ class TextIOWrapperTest(unittest.TestCase):
with
self
.
open
(
filename
,
'rb'
)
as
f
:
self
.
assertEquals
(
f
.
read
(),
'bbbzzz'
.
encode
(
charset
))
def
test_errors_property
(
self
):
with
self
.
open
(
support
.
TESTFN
,
"w"
)
as
f
:
self
.
assertEqual
(
f
.
errors
,
"strict"
)
with
self
.
open
(
support
.
TESTFN
,
"w"
,
errors
=
"replace"
)
as
f
:
self
.
assertEqual
(
f
.
errors
,
"replace"
)
class
CTextIOWrapperTest
(
TextIOWrapperTest
):
...
...
Lib/test/test_memoryio.py
View file @
0926ad1f
...
...
@@ -459,9 +459,9 @@ class PyStringIOTest(MemoryTestMixin, MemorySeekTestMixin, unittest.TestCase):
# These are just dummy values but we nevertheless check them for fear
# of unexpected breakage.
self
.
assert
True
(
memio
.
encoding
is
None
)
self
.
assert
Equal
(
memio
.
errors
,
"strict"
)
self
.
assert
Equal
(
memio
.
line_buffering
,
False
)
self
.
assert
IsNone
(
memio
.
encoding
)
self
.
assert
IsNone
(
memio
.
errors
)
self
.
assert
False
(
memio
.
line_buffering
)
def
test_newline_none
(
self
):
# newline=None
...
...
Misc/NEWS
View file @
0926ad1f
...
...
@@ -21,6 +21,10 @@ Core and Builtins
Library
-------
- Issue #6217: The C implementation of io.TextIOWrapper didn't include the
errors property. Additionally, the errors and encoding properties of StringIO
are always None now.
- Issue #6137: The pickle module now translates module names when loading
or dumping pickles with a 2.x-compatible protocol, in order to make data
sharing and migration easier. This behaviour can be disabled using the
...
...
Modules/_io/stringio.c
View file @
0926ad1f
...
...
@@ -660,22 +660,6 @@ stringio_closed(StringIOObject *self, void *context)
return
PyBool_FromLong
(
self
->
closed
);
}
static
PyObject
*
stringio_encoding
(
StringIOObject
*
self
,
void
*
context
)
{
CHECK_INITIALIZED
(
self
);
CHECK_CLOSED
(
self
);
Py_RETURN_NONE
;
}
static
PyObject
*
stringio_errors
(
StringIOObject
*
self
,
void
*
context
)
{
CHECK_INITIALIZED
(
self
);
CHECK_CLOSED
(
self
);
return
PyUnicode_FromString
(
"strict"
);
}
static
PyObject
*
stringio_line_buffering
(
StringIOObject
*
self
,
void
*
context
)
{
...
...
@@ -720,8 +704,6 @@ static PyGetSetDef stringio_getset[] = {
will be found.
*/
{
"buffer"
,
(
getter
)
stringio_buffer
,
NULL
,
NULL
},
{
"encoding"
,
(
getter
)
stringio_encoding
,
NULL
,
NULL
},
{
"errors"
,
(
getter
)
stringio_errors
,
NULL
,
NULL
},
{
"line_buffering"
,
(
getter
)
stringio_line_buffering
,
NULL
,
NULL
},
{
NULL
}
};
...
...
Modules/_io/textio.c
View file @
0926ad1f
...
...
@@ -104,6 +104,18 @@ TextIOBase_newlines_get(PyObject *self, void *context)
Py_RETURN_NONE
;
}
PyDoc_STRVAR
(
TextIOBase_errors_doc
,
"The error setting of the decoder or encoder.
\n
"
"
\n
"
"Subclasses should override.
\n
"
);
static
PyObject
*
TextIOBase_errors_get
(
PyObject
*
self
,
void
*
context
)
{
Py_RETURN_NONE
;
}
static
PyMethodDef
TextIOBase_methods
[]
=
{
{
"detach"
,
(
PyCFunction
)
TextIOBase_detach
,
METH_NOARGS
,
TextIOBase_detach_doc
},
...
...
@@ -116,6 +128,7 @@ static PyMethodDef TextIOBase_methods[] = {
static
PyGetSetDef
TextIOBase_getset
[]
=
{
{
"encoding"
,
(
getter
)
TextIOBase_encoding_get
,
NULL
,
TextIOBase_encoding_doc
},
{
"newlines"
,
(
getter
)
TextIOBase_newlines_get
,
NULL
,
TextIOBase_newlines_doc
},
{
"errors"
,
(
getter
)
TextIOBase_errors_get
,
NULL
,
TextIOBase_errors_doc
},
{
NULL
}
};
...
...
@@ -2461,6 +2474,13 @@ TextIOWrapper_newlines_get(PyTextIOWrapperObject *self, void *context)
return
res
;
}
static
PyObject
*
TextIOWrapper_errors_get
(
PyTextIOWrapperObject
*
self
,
void
*
context
)
{
CHECK_INITIALIZED
(
self
);
return
PyUnicode_FromString
(
PyBytes_AS_STRING
(
self
->
errors
));
}
static
PyObject
*
TextIOWrapper_chunk_size_get
(
PyTextIOWrapperObject
*
self
,
void
*
context
)
{
...
...
@@ -2519,6 +2539,7 @@ static PyGetSetDef TextIOWrapper_getset[] = {
/* {"mode", (getter)TextIOWrapper_mode_get, NULL, NULL},
*/
{
"newlines"
,
(
getter
)
TextIOWrapper_newlines_get
,
NULL
,
NULL
},
{
"errors"
,
(
getter
)
TextIOWrapper_errors_get
,
NULL
,
NULL
},
{
"_CHUNK_SIZE"
,
(
getter
)
TextIOWrapper_chunk_size_get
,
(
setter
)
TextIOWrapper_chunk_size_set
,
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