You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "James Haggerty (JIRA)" <ji...@apache.org> on 2013/09/30 09:37:24 UTC

[jira] [Comment Edited] (THRIFT-1229) Python fastbinary.c can not handle unicode as generated python code

    [ https://issues.apache.org/jira/browse/THRIFT-1229?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13781650#comment-13781650 ] 

James Haggerty edited comment on THRIFT-1229 at 9/30/13 7:36 AM:
-----------------------------------------------------------------

Just went to use this today, and found that it doesn't check for is_binary (i.e. so binary type things get utf-8ed, which tends to fail...).

I would suggest a better approach is to pass unicode/str as one of the typeargs in the thrift_spec, then utf-8 encode/decode should be done as appropriate (if binary, it would always be str; if a string, it would only be unicode with utf8-strings set).


was (Author: wryun):
Just went to use this today, and found that it doesn't check for is_binary (i.e. so binary type things get utf-8ed, which tends to fail...).

I would suggest a better approach is to pass a bool as one of the typeargs in the thrift_spec, and if that is True then utf-8 encode/decode should be done on the string (if binary, it would never be true; if a string, it would only be true with utf8-strings set).

> Python fastbinary.c can not handle unicode as generated python code
> -------------------------------------------------------------------
>
>                 Key: THRIFT-1229
>                 URL: https://issues.apache.org/jira/browse/THRIFT-1229
>             Project: Thrift
>          Issue Type: Bug
>          Components: Python - Compiler, Python - Library
>    Affects Versions: 0.7
>         Environment: mac osx 10.6
>            Reporter: Favo
>         Attachments: python_fastbinary_utf8.patch
>
>
> #THRIFT-395 ([r959516|http://svn.apache.org/viewvc?view=revision&revision=959516]) fixed python unicode support by adding a parameter to thrift command line for py-generator. However this will not affect fastbinary.c. A normal generated Read/Write function looks like below, notice that the function returned before reach unicode handling logic.
> {code:title=TType.py|borderStyle=solid}
>   def write(self, oprot):
>     if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
>       oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
>       return
>     if self.ip is not None:
>       oprot.writeFieldBegin('ip', TType.STRING, 6)
>       oprot.writeString(self.ip.encode('utf-8'))
>       oprot.writeFieldEnd()
> {code}
> Any suggestion for this?



--
This message was sent by Atlassian JIRA
(v6.1#6144)