summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2012-12-02 16:26:10 (GMT)
committerBenjamin Peterson <benjamin@python.org>2012-12-02 16:26:10 (GMT)
commit196035595f6002868e0a760d78b7bd9fd630fcbd (patch)
treedea3f534e050b3d079b383c84b4157d90f30d78a /Doc
parent47a00f3d1a1fe3774d92e5d9263ef3bff79dd4ac (diff)
downloadcpython-196035595f6002868e0a760d78b7bd9fd630fcbd.zip
cpython-196035595f6002868e0a760d78b7bd9fd630fcbd.tar.gz
cpython-196035595f6002868e0a760d78b7bd9fd630fcbd.tar.bz2
document that encoding error handlers may return bytes (#16585)
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/codecs.rst17
1 files changed, 10 insertions, 7 deletions
diff --git a/Doc/library/codecs.rst b/Doc/library/codecs.rst
index 071fc23..28ea89d 100644
--- a/Doc/library/codecs.rst
+++ b/Doc/library/codecs.rst
@@ -155,13 +155,16 @@ functions which use :func:`lookup` for the codec lookup:
when *name* is specified as the errors parameter.
For encoding *error_handler* will be called with a :exc:`UnicodeEncodeError`
- instance, which contains information about the location of the error. The error
- handler must either raise this or a different exception or return a tuple with a
- replacement for the unencodable part of the input and a position where encoding
- should continue. The encoder will encode the replacement and continue encoding
- the original input at the specified position. Negative position values will be
- treated as being relative to the end of the input string. If the resulting
- position is out of bound an :exc:`IndexError` will be raised.
+ instance, which contains information about the location of the error. The
+ error handler must either raise this or a different exception or return a
+ tuple with a replacement for the unencodable part of the input and a position
+ where encoding should continue. The replacement may be either :class:`str` or
+ :class:`bytes`. If the replacement is bytes, the encoder will simply copy
+ them into the output buffer. If the replacement is a string, the encoder will
+ encode the replacement. Encoding continues on original input at the
+ specified position. Negative position values will be treated as being
+ relative to the end of the input string. If the resulting position is out of
+ bound an :exc:`IndexError` will be raised.
Decoding and translating works similar, except :exc:`UnicodeDecodeError` or
:exc:`UnicodeTranslateError` will be passed to the handler and that the