diff options
Diffstat (limited to 'pyload/remote/thriftbackend/Protocol.py')
-rw-r--r-- | pyload/remote/thriftbackend/Protocol.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/pyload/remote/thriftbackend/Protocol.py b/pyload/remote/thriftbackend/Protocol.py new file mode 100644 index 000000000..ecf0680ad --- /dev/null +++ b/pyload/remote/thriftbackend/Protocol.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- + +from thrift.protocol import TBinaryProtocol + + +class Protocol(TBinaryProtocol.TBinaryProtocol): + + def writeString(self, str): + try: + str = str.encode("utf8", "ignore") + except Exception: + pass + + self.writeI32(len(str)) + self.trans.write(str) + + + def readString(self): + len = self.readI32() + str = self.trans.readAll(len) + try: + str = str.decode("utf8", "ignore") + except Exception: + pass + + return str + + +class ProtocolFactory(TBinaryProtocol.TBinaryProtocolFactory): + + def getProtocol(self, trans): + prot = Protocol(trans, self.strictRead, self.strictWrite) + return prot |