THRIFT-586. python: TSocket incorrectly sets the exception type when an end of file error occurs
TTransportException's type was set to "Transport not open" in some cases, which should
be its message.
Use named arguments and set the type for TTransportException to END_OF_FILE in TSocket#read
and TSocket#write.
reviewer: dreiss
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@818429 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/py/src/protocol/TBinaryProtocol.py b/lib/py/src/protocol/TBinaryProtocol.py
index db1a7a4..50c6aa8 100644
--- a/lib/py/src/protocol/TBinaryProtocol.py
+++ b/lib/py/src/protocol/TBinaryProtocol.py
@@ -127,13 +127,13 @@
if sz < 0:
version = sz & TBinaryProtocol.VERSION_MASK
if version != TBinaryProtocol.VERSION_1:
- raise TProtocolException(TProtocolException.BAD_VERSION, 'Bad version in readMessageBegin: %d' % (sz))
+ raise TProtocolException(type=TProtocolException.BAD_VERSION, message='Bad version in readMessageBegin: %d' % (sz))
type = sz & TBinaryProtocol.TYPE_MASK
name = self.readString()
seqid = self.readI32()
else:
if self.strictRead:
- raise TProtocolException(TProtocolException.BAD_VERSION, 'No protocol version header')
+ raise TProtocolException(type=TProtocolException.BAD_VERSION, message='No protocol version header')
name = self.trans.readAll(sz)
type = self.readByte()
seqid = self.readI32()
diff --git a/lib/py/src/transport/TSocket.py b/lib/py/src/transport/TSocket.py
index 5e58825..8711961 100644
--- a/lib/py/src/transport/TSocket.py
+++ b/lib/py/src/transport/TSocket.py
@@ -86,23 +86,23 @@
message = 'Could not connect to socket %s' % self._unix_socket
else:
message = 'Could not connect to %s:%d' % (self.host, self.port)
- raise TTransportException(TTransportException.NOT_OPEN, message)
+ raise TTransportException(type=TTransportException.NOT_OPEN, message=message)
def read(self, sz):
buff = self.handle.recv(sz)
if len(buff) == 0:
- raise TTransportException('TSocket read 0 bytes')
+ raise TTransportException(type=TTransportException.END_OF_FILE, message='TSocket read 0 bytes')
return buff
def write(self, buff):
if not self.handle:
- raise TTransportException(TTransportException.NOT_OPEN, 'Transport not open')
+ raise TTransportException(type=TTransportException.NOT_OPEN, message='Transport not open')
sent = 0
have = len(buff)
while sent < have:
plus = self.handle.send(buff)
if plus == 0:
- raise TTransportException('TSocket sent 0 bytes')
+ raise TTransportException(type=TTransportException.END_OF_FILE, message='TSocket sent 0 bytes')
sent += plus
buff = buff[plus:]