Don't force utf8 encoding for unicode strings

This commit is contained in:
Jason Paryani
2013-12-18 21:57:57 -08:00
parent 1568c1d4f8
commit 540ed4cdba
2 changed files with 4 additions and 4 deletions

View File

@@ -258,7 +258,7 @@ cdef public object wrap_kj_exception_for_reraise(capnp.Exception & exception):
cdef public object get_exception_info(object exc_type, object exc_obj, object exc_tb): cdef public object get_exception_info(object exc_type, object exc_obj, object exc_tb):
try: try:
return (exc_tb.tb_frame.f_code.co_filename.encode('utf-8'), exc_tb.tb_lineno, (repr(exc_type) + ':' + str(exc_obj)).encode('utf-8')) return (exc_tb.tb_frame.f_code.co_filename.encode(), exc_tb.tb_lineno, (repr(exc_type) + ':' + str(exc_obj)).encode())
except: except:
return (b'', 0, b"Couldn't determine python exception") return (b'', 0, b"Couldn't determine python exception")
@@ -664,7 +664,7 @@ cdef _setDynamicField(_DynamicSetterClasses thisptr, field, value, parent):
thisptr.set(field, temp) thisptr.set(field, temp)
del temp2 del temp2
elif isinstance(value, basestring): elif isinstance(value, basestring):
encoded_value = value.encode('utf-8') encoded_value = value.encode()
temp2 = new capnp.StringPtr(<char*>encoded_value, len(encoded_value)) temp2 = new capnp.StringPtr(<char*>encoded_value, len(encoded_value))
temp = C_DynamicValue.Reader(deref(temp2)) temp = C_DynamicValue.Reader(deref(temp2))
thisptr.set(field, temp) thisptr.set(field, temp)
@@ -709,7 +709,7 @@ cdef _setDynamicFieldPtr(_DynamicSetterClasses * thisptr, field, value, parent):
thisptr.set(field, temp) thisptr.set(field, temp)
del temp2 del temp2
elif isinstance(value, basestring): elif isinstance(value, basestring):
encoded_value = value.encode('utf-8') encoded_value = value.encode()
temp2 = new capnp.StringPtr(<char*>encoded_value, len(encoded_value)) temp2 = new capnp.StringPtr(<char*>encoded_value, len(encoded_value))
temp = C_DynamicValue.Reader(deref(temp2)) temp = C_DynamicValue.Reader(deref(temp2))
thisptr.set(field, temp) thisptr.set(field, temp)

View File

@@ -99,7 +99,7 @@ def test_unicode_str(all_types):
msg = all_types.TestAllTypes.new_message() msg = all_types.TestAllTypes.new_message()
if sys.version_info[0] == 2: if sys.version_info[0] == 2:
msg.textField = u"f\u00e6oo" msg.textField = u"f\u00e6oo".encode('utf-8')
assert msg.textField.decode('utf-8') == u"f\u00e6oo" assert msg.textField.decode('utf-8') == u"f\u00e6oo"
else: else: