Repository: thrift Updated Branches: refs/heads/master 8cd519f7a -> 64b8f6ca1
THRIFT-3375 Python TJSONProtocol encodes utf8 string values in an incompatible way This closes #642 Project: http://git-wip-us.apache.org/repos/asf/thrift/repo Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/64b8f6ca Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/64b8f6ca Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/64b8f6ca Branch: refs/heads/master Commit: 64b8f6ca15fcb88145c447562258ebfab992dd10 Parents: 8cd519f Author: Nobuaki Sukegawa <[email protected]> Authored: Sat Oct 10 02:12:48 2015 +0900 Committer: Roger Meier <[email protected]> Committed: Sun Oct 11 00:23:31 2015 +0200 ---------------------------------------------------------------------- lib/py/src/protocol/TJSONProtocol.py | 4 ++-- test/py/TestClient.py | 29 ++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/thrift/blob/64b8f6ca/lib/py/src/protocol/TJSONProtocol.py ---------------------------------------------------------------------- diff --git a/lib/py/src/protocol/TJSONProtocol.py b/lib/py/src/protocol/TJSONProtocol.py index d270ce8..9e25f67 100644 --- a/lib/py/src/protocol/TJSONProtocol.py +++ b/lib/py/src/protocol/TJSONProtocol.py @@ -174,13 +174,13 @@ class TJSONProtocolBase(TProtocolBase): def writeJSONString(self, string): self.context.write() - self.trans.write(json.dumps(string)) + self.trans.write(json.dumps(string, ensure_ascii=False)) def writeJSONNumber(self, number): self.context.write() jsNumber = str(number) if self.context.escapeNum(): - jsNumber = "%s%s%s" % (QUOTE, jsNumber, QUOTE) + jsNumber = "%s%s%s" % (QUOTE, jsNumber, QUOTE) self.trans.write(jsNumber) def writeJSONBase64(self, binary): http://git-wip-us.apache.org/repos/asf/thrift/blob/64b8f6ca/test/py/TestClient.py ---------------------------------------------------------------------- diff --git a/test/py/TestClient.py b/test/py/TestClient.py index 7fe48f6..7e3daf2 100755 --- a/test/py/TestClient.py +++ b/test/py/TestClient.py @@ -1,5 +1,5 @@ #!/usr/bin/env python - +# -*- coding: utf-8 -*- # # Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file @@ -105,6 +105,33 @@ class AbstractTest(unittest.TestCase): print('testString') self.assertEqual(self.client.testString('Python' * 20), 'Python' * 20) self.assertEqual(self.client.testString(''), '') + self.assertEqual(self.client.testString(u'ãã¤ã½ã³'.encode('utf8')), u'ãã¤ã½ã³'.encode('utf8')) + s = u"""Afrikaans, Alemannisch, Aragonés, Ø§ÙØ¹Ø±Ø¨ÙØ©, ٠صرÙ, + Asturianu, Aymar aru, AzÉrbaycan, ÐаÑҡоÑÑ, Boarisch, ŽemaitÄÅ¡ka, + ÐелаÑÑÑкаÑ, ÐелаÑÑÑÐºÐ°Ñ (ÑаÑаÑкевÑÑа), ÐÑлгаÑÑки, Bamanankan, + বাà¦à¦²à¦¾, Brezhoneg, Bosanski, Català , Mìng-dÄ̤ng-ngá¹³Ì, ÐÐ¾Ñ Ñийн, + Cebuano, á£á³á©, Äesky, СловѣÌнÑÑÐºÑ / â°â°â°â°â°¡â°â° â°â°â°, ЧÓваÑла, Cymraeg, + Dansk, Zazaki, ÞÞ¨ÞÞ¬ÞÞ¨ÞÞ¦ÞÞ°, Îλληνικά, Emilià n e rumagnòl, English, + Esperanto, Español, Eesti, Euskara, ÙØ§Ø±Ø³Û, Suomi, Võro, Føroyskt, + Français, Arpetan, Furlan, Frysk, Gaeilge, è´èª, Gà idhlig, Galego, + Avañe'ẽ, àªà«àªàª°àª¾àª¤à«, Gaelg, ×¢×ר×ת, हिनà¥à¤¦à¥, Fiji Hindi, Hrvatski, + Kreyòl ayisyen, Magyar, ÕÕ¡ÕµÕ¥ÖÕ¥Õ¶, Interlingua, Bahasa Indonesia, + Ilokano, Ido, Ãslenska, Italiano, æ¥æ¬èª, Lojban, Basa Jawa, + á¥áá áá£áá, Kongo, Kalaallisut, à²à²¨à³à²¨à²¡, íêµì´, ÐÑаÑаÑай-ÐалкÑаÑ, + Ripoarisch, Kurdî, Ðоми, Kernewek, ÐÑÑгÑзÑа, Latina, Ladino, + Lëtzebuergesch, Limburgs, Lingála, ລາວ, Lietuvių, LatvieÅ¡u, Basa + Banyumasan, Malagasy, ÐакедонÑки, മലയാളà´, मराठà¥, Ù Ø§Ø²ÙØ±ÙÙÛ, Bahasa + Melayu, Nnapulitano, Nedersaksisch, नà¥à¤ªà¤¾à¤² à¤à¤¾à¤·à¤¾, Nederlands, ⪠+ Norsk (nynorsk)â¬, âªNorsk (bokmÃ¥l)â¬, Nouormand, Diné bizaad, + Occitan, ÐÑонаÑ, Papiamentu, Deitsch, Polski, Ù¾ÙØ¬Ø§Ø¨Û, Ù¾ÚØªÙ, + Norfuk / Pitkern, Português, Runa Simi, Rumantsch, Romani, RomânÄ, + Ð ÑÑÑкий, Ð¡Ð°Ñ Ð° ÑÑла, Sardu, Sicilianu, Scots, Sámegiella, Simple + English, SlovenÄina, SlovenÅ¡Äina, СÑпÑки / Srpski, Seeltersk, + Svenska, Kiswahili, தமிழà¯, à°¤à±à°²à±à°à±, Тоҷикӣ, à¹à¸à¸¢, Türkmençe, Tagalog, + Türkçe, ТаÑаÑÑа/Tatarça, УкÑаÑнÑÑка, اردÙ, Tiếng Viá»t, Volapük, + Walon, Winaray, å´è¯, isiXhosa, ××Ö´××ש, Yorùbá, Zeêuws, 䏿, + Bân-lâm-gú, ç²µèª""" + self.assertEqual(self.client.testString(s.encode('utf8')), s.encode('utf8')) def testBool(self): print('testBool')
