mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Issue #19676: Added the "namereplace" error handler.
This commit is contained in:
parent
6cecf68c7b
commit
166ebc4e5d
11 changed files with 255 additions and 7 deletions
|
@ -98,6 +98,8 @@ It defines the following functions:
|
|||
reference (for encoding only)
|
||||
* ``'backslashreplace'``: replace with backslashed escape sequences (for
|
||||
encoding only)
|
||||
* ``'namereplace'``: replace with ``\N{...}`` escape sequences (for
|
||||
encoding only)
|
||||
* ``'surrogateescape'``: on decoding, replace with code points in the Unicode
|
||||
Private Use Area ranging from U+DC80 to U+DCFF. These private code
|
||||
points will then be turned back into the same bytes when the
|
||||
|
@ -232,6 +234,11 @@ functions which use :func:`lookup` for the codec lookup:
|
|||
Implements the ``backslashreplace`` error handling (for encoding only): the
|
||||
unencodable character is replaced by a backslashed escape sequence.
|
||||
|
||||
.. function:: namereplace_errors(exception)
|
||||
|
||||
Implements the ``namereplace`` error handling (for encoding only): the
|
||||
unencodable character is replaced by a ``\N{...}`` escape sequence.
|
||||
|
||||
To simplify working with encoded files or stream, the module also defines these
|
||||
utility functions:
|
||||
|
||||
|
@ -363,6 +370,9 @@ and implemented by all standard Python codecs:
|
|||
| ``'backslashreplace'`` | Replace with backslashed escape sequences |
|
||||
| | (only for encoding). |
|
||||
+-------------------------+-----------------------------------------------+
|
||||
| ``'namereplace'`` | Replace with ``\N{...}`` escape sequences |
|
||||
| | (only for encoding). |
|
||||
+-------------------------+-----------------------------------------------+
|
||||
| ``'surrogateescape'`` | Replace byte with surrogate U+DCxx, as defined|
|
||||
| | in :pep:`383`. |
|
||||
+-------------------------+-----------------------------------------------+
|
||||
|
@ -384,6 +394,9 @@ schemes:
|
|||
.. versionchanged:: 3.4
|
||||
The ``'surrogatepass'`` error handlers now works with utf-16\* and utf-32\* codecs.
|
||||
|
||||
.. versionadded:: 3.4
|
||||
The ``'namereplace'`` error handler.
|
||||
|
||||
The set of allowed values can be extended via :meth:`register_error`.
|
||||
|
||||
|
||||
|
@ -477,6 +490,8 @@ define in order to be compatible with the Python codec registry.
|
|||
|
||||
* ``'backslashreplace'`` Replace with backslashed escape sequences.
|
||||
|
||||
* ``'namereplace'`` Replace with ``\N{...}`` escape sequences.
|
||||
|
||||
The *errors* argument will be assigned to an attribute of the same name.
|
||||
Assigning to this attribute makes it possible to switch between different error
|
||||
handling strategies during the lifetime of the :class:`IncrementalEncoder`
|
||||
|
@ -625,6 +640,8 @@ compatible with the Python codec registry.
|
|||
|
||||
* ``'backslashreplace'`` Replace with backslashed escape sequences.
|
||||
|
||||
* ``'namereplace'`` Replace with ``\N{...}`` escape sequences.
|
||||
|
||||
The *errors* argument will be assigned to an attribute of the same name.
|
||||
Assigning to this attribute makes it possible to switch between different error
|
||||
handling strategies during the lifetime of the :class:`StreamWriter` object.
|
||||
|
|
|
@ -975,6 +975,9 @@ are always available. They are listed here in alphabetical order.
|
|||
replaces unsupported characters with Python's backslashed escape
|
||||
sequences.
|
||||
|
||||
* ``'namereplace'`` (also only supported when writing)
|
||||
replaces unsupported characters with ``\N{...}`` escape sequences.
|
||||
|
||||
.. index::
|
||||
single: universal newlines; open() built-in function
|
||||
|
||||
|
|
|
@ -827,9 +827,10 @@ Text I/O
|
|||
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) or ``'backslashreplace'`` (replace with backslashed escape
|
||||
sequences) can be used. Any other error handling name that has been
|
||||
registered with :func:`codecs.register_error` is also valid.
|
||||
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
|
||||
:func:`codecs.register_error` is also valid.
|
||||
|
||||
.. index::
|
||||
single: universal newlines; io.TextIOWrapper class
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue