-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure that mulitpart bodies are always bytes. #1779
Ensure that mulitpart bodies are always bytes. #1779
Conversation
Note that opening the file passed to |
def _email_chunk_parser(): | ||
import six | ||
if six.PY3: # pragma: NO COVER Python3 | ||
from email.parser import BytesParser # pylint: disable=E0611 |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
RE: Always failing tables, couldn't we just convert to bytes? Then instead of documenting "this will fail", we'd document "if you don't give us bytes, we're going to guess your encoding and we might get it wrong" |
Do we want to be in the business of reading potentially huge files in memory and guessing their encoding? If we want to try checking for 'stream.mode != 'rb'` (assuming they opened it, rather than passing us some other file-like object) we could raise an exception right away, rather than failing with a much uglier traceback later. |
As discovered in googleapis/google-cloud-python#1760, we were mangling bytes when encoding them as part of a multipart upload request. The fix is to switch from using `six.StringIO` to `six.BytesIO` in `transfer.py`. The patch here is closely based on googleapis/google-cloud-python#1779.
I agree that guessing the format is probably a bad idea (because while it might make some people happy, it might make some other people really really mad). Can we have a super clear exception saying ... "You gave us a file opened in text mode, which means we don't know the encoding... Can you open in binary mode with the right encoding?" |
Sorry for the delay. @tseaver I agree with you, sniffing the entire file was ill-conceived. |
if six.PY3: # pragma: NO COVER Python3 | ||
# pylint: disable=no-name-in-module | ||
from email.parser import BytesParser | ||
# pylint: enable=no-name-in-module |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Addresses: #1779 (comment)
On 'master', it is now disabled globally.
IFF the user gives us an actual file object (created via |
@dhermes And in that case, we just do our best here, right? |
LGTM |
…#1779) * Fixed name of model * update model ids
…#1779) * Fixed name of model * update model ids
…#1779) * Fixed name of model * update model ids
Loosely based on @joar's gist
Fixes #1760.