summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-01-25 20:56:57 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-01-25 20:56:57 (GMT)
commit07985ef387a87486a0e632844be03a8877e7f889 (patch)
treeb89d636e8ba7b0cd170064698741aebb46951eb5 /Doc
parent58f02019e0a772b5689b69182f4f162666657294 (diff)
downloadcpython-07985ef387a87486a0e632844be03a8877e7f889.zip
cpython-07985ef387a87486a0e632844be03a8877e7f889.tar.gz
cpython-07985ef387a87486a0e632844be03a8877e7f889.tar.bz2
Issue #22286: The "backslashreplace" error handlers now works with
decoding and translating.
Diffstat (limited to 'Doc')
-rw-r--r--Doc/howto/unicode.rst7
-rw-r--r--Doc/library/codecs.rst14
-rw-r--r--Doc/library/functions.rst5
-rw-r--r--Doc/library/io.rst11
-rw-r--r--Doc/whatsnew/3.5.rst4
5 files changed, 25 insertions, 16 deletions
diff --git a/Doc/howto/unicode.rst b/Doc/howto/unicode.rst
index 5ea311e..ee31a9c 100644
--- a/Doc/howto/unicode.rst
+++ b/Doc/howto/unicode.rst
@@ -280,8 +280,9 @@ and optionally an *errors* argument.
The *errors* argument specifies the response when the input string can't be
converted according to the encoding's rules. Legal values for this argument are
``'strict'`` (raise a :exc:`UnicodeDecodeError` exception), ``'replace'`` (use
-``U+FFFD``, ``REPLACEMENT CHARACTER``), or ``'ignore'`` (just leave the
-character out of the Unicode result).
+``U+FFFD``, ``REPLACEMENT CHARACTER``), ``'ignore'`` (just leave the
+character out of the Unicode result), or ``'backslashreplace'`` (inserts a
+``\xNN`` escape sequence).
The following examples show the differences::
>>> b'\x80abc'.decode("utf-8", "strict") #doctest: +NORMALIZE_WHITESPACE
@@ -291,6 +292,8 @@ The following examples show the differences::
invalid start byte
>>> b'\x80abc'.decode("utf-8", "replace")
'\ufffdabc'
+ >>> b'\x80abc'.decode("utf-8", "backslashreplace")
+ '\\x80abc'
>>> b'\x80abc'.decode("utf-8", "ignore")
'abc'
diff --git a/Doc/library/codecs.rst b/Doc/library/codecs.rst
index 3510f69..048f0e9 100644
--- a/Doc/library/codecs.rst
+++ b/Doc/library/codecs.rst
@@ -314,8 +314,8 @@ The following error handlers are only applicable to
| | reference (only for encoding). Implemented |
| | in :func:`xmlcharrefreplace_errors`. |
+-------------------------+-----------------------------------------------+
-| ``'backslashreplace'`` | Replace with backslashed escape sequences |
-| | (only for encoding). Implemented in |
+| ``'backslashreplace'`` | Replace with backslashed escape sequences. |
+| | Implemented in |
| | :func:`backslashreplace_errors`. |
+-------------------------+-----------------------------------------------+
| ``'namereplace'`` | Replace with ``\N{...}`` escape sequences |
@@ -350,6 +350,10 @@ In addition, the following error handler is specific to the given codecs:
.. versionadded:: 3.5
The ``'namereplace'`` error handler.
+.. versionchanged:: 3.5
+ The ``'backslashreplace'`` error handlers now works with decoding and
+ translating.
+
The set of allowed values can be extended by registering a new named error
handler:
@@ -417,9 +421,9 @@ functions:
.. function:: backslashreplace_errors(exception)
- Implements the ``'backslashreplace'`` error handling (for encoding with
- :term:`text encodings <text encoding>` only): the
- unencodable character is replaced by a backslashed escape sequence.
+ Implements the ``'backslashreplace'`` error handling (for
+ :term:`text encodings <text encoding>` only): malformed data is
+ replaced by a backslashed escape sequence.
.. function:: namereplace_errors(exception)
diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst
index c6b66b5..eb28513 100644
--- a/Doc/library/functions.rst
+++ b/Doc/library/functions.rst
@@ -973,9 +973,8 @@ are always available. They are listed here in alphabetical order.
Characters not supported by the encoding are replaced with the
appropriate XML character reference ``&#nnn;``.
- * ``'backslashreplace'`` (also only supported when writing)
- replaces unsupported characters with Python's backslashed escape
- sequences.
+ * ``'backslashreplace'`` replaces malformed data by Python's backslashed
+ escape sequences.
* ``'namereplace'`` (also only supported when writing)
replaces unsupported characters with ``\N{...}`` escape sequences.
diff --git a/Doc/library/io.rst b/Doc/library/io.rst
index c77db90..b0b1af3 100644
--- a/Doc/library/io.rst
+++ b/Doc/library/io.rst
@@ -825,11 +825,12 @@ Text I/O
exception if there is an encoding error (the default of ``None`` has the same
effect), or pass ``'ignore'`` to ignore errors. (Note that ignoring encoding
errors can lead to data loss.) ``'replace'`` causes a replacement marker
- (such as ``'?'``) to be inserted where there is malformed data. When
- writing, ``'xmlcharrefreplace'`` (replace with the appropriate XML character
- reference), ``'backslashreplace'`` (replace with backslashed escape
- sequences) or ``'namereplace'`` (replace with ``\N{...}`` escape sequences)
- can be used. Any other error handling name that has been registered with
+ (such as ``'?'``) to be inserted where there is malformed data.
+ ``'backslashreplace'`` causes malformed data to be replaced by a
+ backslashed escape sequence. When writing, ``'xmlcharrefreplace'``
+ (replace with the appropriate XML character reference) or ``'namereplace'``
+ (replace with ``\N{...}`` escape sequences) can be used. Any other error
+ handling name that has been registered with
:func:`codecs.register_error` is also valid.
.. index::
diff --git a/Doc/whatsnew/3.5.rst b/Doc/whatsnew/3.5.rst
index bea6a8a..ae18276 100644
--- a/Doc/whatsnew/3.5.rst
+++ b/Doc/whatsnew/3.5.rst
@@ -118,7 +118,9 @@ Other Language Changes
Some smaller changes made to the core Python language are:
-* None yet.
+* Added the ``'namereplace'`` error handlers. The ``'backslashreplace'``
+ error handlers now works with decoding and translating.
+ (Contributed by Serhiy Storchaka in :issue:`19676` and :issue:`22286`.)