replace "utf8" alias by canonical "utf-8" locale code + remove the second Python2 vs Py3 compat.py
Client: py
Patch: Alexandre Detiste
This closes #3105
diff --git a/lib/py/src/protocol/TBinaryProtocol.py b/lib/py/src/protocol/TBinaryProtocol.py
index e59e0dc..af64ec1 100644
--- a/lib/py/src/protocol/TBinaryProtocol.py
+++ b/lib/py/src/protocol/TBinaryProtocol.py
@@ -17,10 +17,10 @@
# under the License.
#
-from .TProtocol import TType, TProtocolBase, TProtocolException, TProtocolFactory
-from ..compat import binary_to_str
from struct import pack, unpack
+from .TProtocol import TType, TProtocolBase, TProtocolException, TProtocolFactory
+
class TBinaryProtocol(TProtocolBase):
"""Binary implementation of the Thrift protocol driver."""
@@ -146,7 +146,7 @@
if self.strictRead:
raise TProtocolException(type=TProtocolException.BAD_VERSION,
message='No protocol version header')
- name = binary_to_str(self.trans.readAll(sz))
+ name = self.trans.readAll(sz).decode('utf-8')
type = self.readByte()
seqid = self.readI32()
return (name, type, seqid)
diff --git a/lib/py/src/protocol/TCompactProtocol.py b/lib/py/src/protocol/TCompactProtocol.py
index 700e792..a3527cd 100644
--- a/lib/py/src/protocol/TCompactProtocol.py
+++ b/lib/py/src/protocol/TCompactProtocol.py
@@ -20,8 +20,6 @@
from .TProtocol import TType, TProtocolBase, TProtocolException, TProtocolFactory, checkIntegerLimits
from struct import pack, unpack
-from ..compat import binary_to_str, str_to_binary
-
__all__ = ['TCompactProtocol', 'TCompactProtocolFactory']
CLEAR = 0
@@ -165,7 +163,7 @@
if tseqid < 0:
tseqid = 2147483648 + (2147483648 + tseqid)
self.__writeVarint(tseqid)
- self.__writeBinary(str_to_binary(name))
+ self.__writeBinary(bytes(name, 'utf-8'))
self.state = VALUE_WRITE
def writeMessageEnd(self):
@@ -346,7 +344,7 @@
# however the sequence is actually signed...
if seqid > 2147483647:
seqid = -2147483648 - (2147483648 - seqid)
- name = binary_to_str(self.__readBinary())
+ name = self.__readBinary().decode('utf-8')
return (name, type, seqid)
def readMessageEnd(self):
diff --git a/lib/py/src/protocol/TJSONProtocol.py b/lib/py/src/protocol/TJSONProtocol.py
index fef0cc9..a42aaa6 100644
--- a/lib/py/src/protocol/TJSONProtocol.py
+++ b/lib/py/src/protocol/TJSONProtocol.py
@@ -23,8 +23,6 @@
import math
import sys
-from ..compat import str_to_binary
-
__all__ = ['TJSONProtocol',
'TJSONProtocolFactory',
@@ -213,7 +211,7 @@
escaped = ESCAPE_CHAR_VALS.get(s, s)
json_str.append(escaped)
json_str.append('"')
- self.trans.write(str_to_binary(''.join(json_str)))
+ self.trans.write(bytes(''.join(json_str), 'utf-8'))
def writeJSONNumber(self, number, formatter='{0}'):
self.context.write()
@@ -313,7 +311,7 @@
utf8_bytes = bytearray([ord(character)])
while ord(self.reader.peek()) >= 0x80:
utf8_bytes.append(ord(self.reader.read()))
- character = utf8_bytes.decode('utf8')
+ character = utf8_bytes.decode('utf-8')
string.append(character)
if highSurrogate:
diff --git a/lib/py/src/protocol/TProtocol.py b/lib/py/src/protocol/TProtocol.py
index ec71ab3..a7336c5 100644
--- a/lib/py/src/protocol/TProtocol.py
+++ b/lib/py/src/protocol/TProtocol.py
@@ -19,7 +19,6 @@
from thrift.Thrift import TException, TType, TFrozenDict
from thrift.transport.TTransport import TTransportException
-from ..compat import binary_to_str, str_to_binary
import sys
from itertools import islice
@@ -117,13 +116,13 @@
pass
def writeString(self, str_val):
- self.writeBinary(str_to_binary(str_val))
+ self.writeBinary(bytes(str_val, 'utf-8'))
def writeBinary(self, str_val):
pass
def writeUtf8(self, str_val):
- self.writeString(str_val.encode('utf8'))
+ self.writeString(str_val.encode('utf-8'))
def readMessageBegin(self):
pass
@@ -180,13 +179,13 @@
pass
def readString(self):
- return binary_to_str(self.readBinary())
+ return self.readBinary().decode('utf-8')
def readBinary(self):
pass
def readUtf8(self):
- return self.readString().decode('utf8')
+ return self.readString().decode('utf-8')
def skip(self, ttype):
if ttype == TType.BOOL: