-
Notifications
You must be signed in to change notification settings - Fork 26
Closed
Description
I have an str input stream that I would like to decode. base64.b64decode() handles str just fine, so I would like to avoid ASCII encoding the input, which would consume the entire stream unless I'm very clever. I tried this:
>>> from base64 import b64decode
>>> from io import StringIO
>>> b64decode('SGVsbG8gZnJvbSB1bmljb2RlIMOmw7jDpQ==')
b'Hello from unicode \xc3\xa6\xc3\xb8\xc3\xa5'
>>> Base64IO(StringIO('SGVsbG8gZnJvbSB1bmljb2RlIMOmw7jDpQ==')).read()
File "/usr/lib/python3.5/site-packages/base64io/__init__.py", line 276, in read
if any([char.encode("utf-8") in data for char in string.whitespace]):
File "/usr/lib/python3.5/site-packages/base64io/__init__.py", line 276, in <listcomp>
if any([char.encode("utf-8") in data for char in string.whitespace]):
TypeError: 'in <string>' requires string as left operand, not byteswhich fails in https://github.com/aws/base64io-python/blob/master/src/base64io/__init__.py#L276 because the code assumes data is a bytes instance.
- It strikes me as a quite heavy operation to pass over each piece of data 5 times (the length of string.whitespace) just to test for possible whitespace. Maybe handling whitespace should be configurable?
- If I change the line to
if any([char in data for char in string.whitespace]):then the example code works fine. So we could test the type ofdataand then run the version that applies. - A similar, small patch is required in
_read_additional_data_removing_whitespace()
Any comments?
Metadata
Metadata
Assignees
Labels
No labels