Message207900
I think calling iterencode() with an empty iterator is a side issue. Even with a non-empty iterator, it tries to encode an empty _text_ string to finalise the encoder:
>>> bytes().join(codecs.iterencode(iter((b"data",)), "base64-codec"))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.3/codecs.py", line 1014, in iterencode
output = encoder.encode("", True)
File "/usr/lib/python3.3/encodings/base64_codec.py", line 31, in encode
return base64.encodebytes(input)
File "/usr/lib/python3.3/base64.py", line 343, in encodebytes
raise TypeError("expected bytes, not %s" % s.__class__.__name__)
TypeError: expected bytes, not str
Similarly, iterdecode(encoding="rot-13") doesn’t work. I agree it would be good to document that iterencode() is limited to text encoders and iterdecode() is limited to byte decoders. |
|
Date |
User |
Action |
Args |
2014-01-11 07:30:21 | martin.panter | set | recipients:
+ martin.panter, lemburg, loewis, doerwalter, ncoghlan, vstinner |
2014-01-11 07:30:21 | martin.panter | set | messageid: <1389425421.54.0.776848019246.issue20132@psf.upfronthosting.co.za> |
2014-01-11 07:30:21 | martin.panter | link | issue20132 messages |
2014-01-11 07:30:20 | martin.panter | create | |
|