-
Notifications
You must be signed in to change notification settings - Fork 145
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 String encoding #235
fix String encoding #235
Conversation
if self.encoding: | ||
result = text_type(appstruct).encode(self.encoding) | ||
else: | ||
result = text_type(appstruct) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer that the result = text_type(appstruct)
to be outside the if
, with no else
. E.g.:
result = text_type(appstruct)
if self.encoding:
result = result.encode(self.encoding)
return result
@tseaver - updated as requested... |
@@ -1557,6 +1557,13 @@ def test_serialize_string_with_high_unresolveable_high_order_chars(self): | |||
e = invalid_exc(typ.serialize, node, not_utf8) | |||
self.assertTrue('cannot be serialized' in e.msg) | |||
|
|||
def test_serialize_encoding_with_non_string_type(self): | |||
utf8 = '123'.encode('utf-8') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, this one should start as text and then encode to bytes (Python2 lets us get away with being sloppy, but that doesn't mean we shouldn't be explicit).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I develop everything in Python 3 and then deal with Python 2 only when I need backwards compatibility. I know this is already doing what your describing in Py3, but I don't understand how it's not doing this in Py2. In Py2, should this be u'123'.encode('utf-8')
to be explicit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you saying this should be utf8 = text_type('123').encode('utf-8')
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be the better spelling, yes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or just b'123', in fact (ASCII and UTF-8 are identical encodings for 7-bit values).
@tseaver - I went with using |
@tseaver - should I add a note in the CHANGES.rst? Is there anything else I need to change to complete this? |
A note in |
done |
Thanks! |
fixes #233