THRIFT-3527 -gen py:dynamic,utf8strings ignores utf8strings option This closes #777
Project: http://git-wip-us.apache.org/repos/asf/thrift/repo Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/397bd51a Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/397bd51a Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/397bd51a Branch: refs/heads/master Commit: 397bd51af7cfad17a93324f0c43f8d3424627b36 Parents: 03565bf Author: Nobuaki Sukegawa <[email protected]> Authored: Wed Jan 6 14:43:15 2016 +0900 Committer: Nobuaki Sukegawa <[email protected]> Committed: Mon Jan 11 11:35:10 2016 +0900 ---------------------------------------------------------------------- lib/py/src/protocol/TProtocol.py | 11 +++++++++++ 1 file changed, 11 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/thrift/blob/397bd51a/lib/py/src/protocol/TProtocol.py ---------------------------------------------------------------------- diff --git a/lib/py/src/protocol/TProtocol.py b/lib/py/src/protocol/TProtocol.py index 9679ba0..450e0fa 100644 --- a/lib/py/src/protocol/TProtocol.py +++ b/lib/py/src/protocol/TProtocol.py @@ -111,6 +111,9 @@ class TProtocolBase(object): def writeBinary(self, str_val): pass + def writeUtf8(self, str_val): + self.writeString(str_val.encode('utf8')) + def readMessageBegin(self): pass @@ -171,6 +174,9 @@ class TProtocolBase(object): def readBinary(self): pass + def readUtf8(self): + return self.readString().decode('utf8') + def skip(self, ttype): if ttype == TType.STOP: return @@ -242,6 +248,11 @@ class TProtocolBase(object): raise TProtocolException(type=TProtocolException.INVALID_DATA, message='Invalid binary field type %d' % ttype) return ('readBinary', 'writeBinary', False) + if sys.version_info[0] == 2 and spec == 'UTF8': + if ttype != TType.STRING: + raise TProtocolException(type=TProtocolException.INVALID_DATA, + message='Invalid string field type %d' % ttype) + return ('readUtf8', 'writeUtf8', False) return self._TTYPE_HANDLERS[ttype] if ttype < len(self._TTYPE_HANDLERS) else (None, None, False) def _read_by_ttype(self, ttype, spec, espec):
