Skip to content
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

Fix dynamodb.types.Binary non-ASCII handling #2492

Merged
merged 1 commit into from Aug 4, 2014

Conversation

akonradi
Copy link
Contributor

@akonradi akonradi commented Aug 2, 2014

Make dynamodb.types.Binary use a raw string as the internal representation, instead of trying to UTF-8 encode and decode binary data. Fixes #2491

if isinstance(value, six.text_type): # Support only PY2 for backward compatibility.
value = value.encode('utf-8')
elif not isinstance(value, bytes):
if not isinstance(value, (bytes, six.text_type)):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that unicode should still be encoded to UTF-8. The internal representation (value) of the Binary class should always be bytes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, that makes sense. I'll fix and post an update, then.

@danielgtaylor
Copy link
Member

Thanks for the pull request! Overall this looks great, but I have one concern above. I definitely agree that encoding to UTF-8 for display may not make sense for arbitrary binary data, but we always want the internal representation to by bytes.

Python 2.6/7 strings are used for both text and non-ASCII byte strings. Since
the boto.dynamodb.types.Binary type is used for representing binary (and likely
non-ASCII) data, encoding and decoding the internal string representation as
UTF-8 doesn't make sense. This commit fixes the Python 2 version of Binary.
@danielgtaylor
Copy link
Member

This looks great, thanks! 👍

danielgtaylor added a commit that referenced this pull request Aug 4, 2014
Fix dynamodb.types.Binary non-ASCII handling. Fixes #2492, #2491.
@danielgtaylor danielgtaylor merged commit 16284ea into boto:develop Aug 4, 2014
@akonradi akonradi deleted the bugfix-binary-non-ascii branch August 4, 2014 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dynamodb.types.Binary can't handle non-ASCII strings on Python 2.7
2 participants