From 8afc8f61f944f61cca24e7e7f439c731e26d0a05 Mon Sep 17 00:00:00 2001 From: Nick Coghlan Date: Fri, 22 Nov 2013 23:00:22 +1000 Subject: [PATCH] Issue #19619: Update What's New for codec blacklist --- Doc/whatsnew/3.4.rst | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/Doc/whatsnew/3.4.rst b/Doc/whatsnew/3.4.rst index 42a6fef67ee..22d168e7e32 100644 --- a/Doc/whatsnew/3.4.rst +++ b/Doc/whatsnew/3.4.rst @@ -194,37 +194,37 @@ in both Python 2 and Python 3, rather than being limited to Unicode text encodings (in Python 3) or ``basestring`` <-> ``basestring`` conversions (in Python 2). -In Python 3.4, the errors raised by the convenience methods when a codec -produces the incorrect output type have also been updated to direct users -towards these general purpose convenience functions:: +In Python 3.4, the interpreter is able to identify the known non-text +encodings provided in the standard library and direct users towards these +general purpose convenience functions when appropriate:: >>> import codecs - >>> codecs.encode(b"hello", "bz2_codec").decode("bz2_codec") + >>> b"abcdef".decode("hex_codec") Traceback (most recent call last): File "", line 1, in - TypeError: 'bz2_codec' decoder returned 'bytes' instead of 'str'; use codecs.decode() to decode to arbitrary types + LookupError: 'hex_codec' is not a text encoding; use codecs.decode() to handle arbitrary codecs >>> "hello".encode("rot_13") Traceback (most recent call last): File "", line 1, in - TypeError: 'rot_13' encoder returned 'str' instead of 'bytes'; use codecs.encode() to encode to arbitrary types + LookupError: 'rot_13' is not a text encoding; use codecs.encode() to handle arbitrary codecs In a related change, whenever it is feasible without breaking backwards compatibility, exceptions raised during encoding and decoding operations will be wrapped in a chained exception of the same type that mentions the name of the codec responsible for producing the error:: - >>> b"hello".decode("uu_codec") - ValueError: Missing "begin" line in input data + >>> codecs.decode(b"abcdefgh", "hex_codec") + binascii.Error: Non-hexadecimal digit found The above exception was the direct cause of the following exception: Traceback (most recent call last): File "", line 1, in - ValueError: decoding with 'uu_codec' codec failed (ValueError: Missing "begin" line in input data) + binascii.Error: decoding with 'hex_codec' codec failed (Error: Non-hexadecimal digit found) - >>> "hello".encode("bz2_codec") + >>> codecs.encode("hello", "bz2_codec") TypeError: 'str' does not support the buffer interface The above exception was the direct cause of the following exception: @@ -233,7 +233,8 @@ name of the codec responsible for producing the error:: File "", line 1, in TypeError: encoding with 'bz2_codec' codec failed (TypeError: 'str' does not support the buffer interface) -(Contributed by Nick Coghlan in :issue:`17827` and :issue:`17828`) +(Contributed by Nick Coghlan in :issue:`17827`, :issue:`17828` and +:issue:`19619`) Other Language Changes