Make sure to encode to utf-8, not the default encoding

This allows text fields to take unicode strings under python 2.
This commit is contained in:
Mike Lundy
2016-03-03 14:29:32 -08:00
parent c625981eb6
commit 8c3c57aa32
6 changed files with 24 additions and 7 deletions

View File

@@ -90,7 +90,7 @@ cpdef _set_{{field.name}}(self, value):
if type(value) is bytes:
temp_string = StringPtr(<char*>value, len(value))
else:
encoded_value = value.encode()
encoded_value = value.encode('utf-8')
temp_string = StringPtr(<char*>encoded_value, len(encoded_value))
self.thisptr_child.set{{field.c_name}}(temp_string)
{% elif 'data' == field['type'] -%}
@@ -99,7 +99,7 @@ cpdef _set_{{field.name}}(self, value):
if type(value) is bytes:
temp_string = StringPtr(<char*>value, len(value))
else:
encoded_value = value.encode()
encoded_value = value.encode('utf-8')
temp_string = StringPtr(<char*>encoded_value, len(encoded_value))
self.thisptr_child.set{{field.c_name}}(ArrayPtr[byte](<byte *>temp_string.begin(), temp_string.size()))
{% else -%}