THRIFT-3375 Python TJSONProtocol encodes utf8 string values in an incompatible way
This closes #642
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 @@
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):
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 @@
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')