Message188807
The attached patch changes the error message of str.encode/bytes.decode when the codec returns the wrong type:
>>> import codecs
>>> 'example'.encode('rot_13')
TypeError: encoder returned 'str' instead of 'bytes', use codecs.decode for str->str conversions
>>> codecs.encode('example', 'rot_13')
'rknzcyr'
>>>
>>> b'000102'.decode('hex_codec')
TypeError: decoder returned 'bytes' instead of 'str', use codecs.encode for bytes->bytes conversions
>>> codecs.decode(b'000102', 'hex_codec')
b'\x00\x01\x02'
This only solves part of the problem though, because individual codecs might raise other errors if the input type is wrong:
>>> 'example'.encode('hex_codec')
Traceback (most recent call last):
File "/home/wolf/dev/py/py3k/Lib/encodings/hex_codec.py", line 16, in hex_encode
return (binascii.b2a_hex(input), len(input))
TypeError: 'str' does not support the buffer interface |
|
Date |
User |
Action |
Args |
2013-05-10 03:22:37 | ezio.melotti | set | recipients:
+ ezio.melotti, barry, ncoghlan, flox |
2013-05-10 03:22:37 | ezio.melotti | set | messageid: <1368156157.04.0.266620918345.issue17828@psf.upfronthosting.co.za> |
2013-05-10 03:22:37 | ezio.melotti | link | issue17828 messages |
2013-05-10 03:22:36 | ezio.melotti | create | |
|