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

ASF GitHub Bot commented on THRIFT-2413:
----------------------------------------

Github user nsuke commented on a diff in the pull request:

    https://github.com/apache/thrift/pull/673#discussion_r44134486
  
    --- Diff: lib/py/test/thrift_json.py ---
    @@ -0,0 +1,28 @@
    +from thrift import Thrift
    +from thrift.protocol.TJSONProtocol import TJSONProtocol
    +from thrift.transport import TTransport
    +
    +import unittest
    +
    +#
    +# In order to run the test under Windows. We need to create symbolic link
    +# name 'thrift' to '../src' folder by using:
    +#
    +# mklink /D thrift ..\src
    +#
    +
    +class TestJSONString(unittest.TestCase):
    +
    +  def test_escaped_unicode_string(self):
    +    unicode_json = '"hello \\u0e01\\u0e02\\u0e03\\ud835\\udcab unicode"'
    +    unicode_text = u'hello \u0e01\u0e02\u0e03\U0001D4AB unicode'
    +
    +    buf = TTransport.TMemoryBuffer(unicode_json)
    +    transport = TTransport.TBufferedTransportFactory().getTransport(buf)
    +    protocol = TJSONProtocol(transport)
    +
    +    self.assertEqual(protocol.readString(), unicode_text)
    --- End diff --
    
    Since the other protocols' `readString` returned string, we cannot make 
TJSONProtocol alone return unicode.
    (FYI unicode in Thrift python2 is handled by "utf8string" generator option.)
    
    Now that we have Python3, it is valid as is for Python3 (since unicode and 
string is equivalent in py3) but still needs the modification for Python2.
    To do this you may want to look at `testString` in test/py/TestClient.py 
for Python2/3 switch.


> Python: UTF-8 sent by PHP as JSON is not understood by TJsonProtocol
> --------------------------------------------------------------------
>
>                 Key: THRIFT-2413
>                 URL: https://issues.apache.org/jira/browse/THRIFT-2413
>             Project: Thrift
>          Issue Type: Sub-task
>          Components: Python - Library
>            Reporter: Jens Geyer
>




--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to