diff options
author | Esteve Fernandez <esteve@apache.org> | 2009-09-24 10:22:00 +0000 |
---|---|---|
committer | Esteve Fernandez <esteve@apache.org> | 2009-09-24 10:22:00 +0000 |
commit | bff2a35adf75e5da3483facab647601a73a1f9ee (patch) | |
tree | 88da87c4af3377005227a4387d3e99a86f391150 | |
parent | db40d26f4a61c1c2ae04997a6cc475bfd585d3e4 (diff) | |
download | thrift-bff2a35adf75e5da3483facab647601a73a1f9ee.tar.gz |
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
-rw-r--r-- | lib/py/src/protocol/TBinaryProtocol.py | 4 | ||||
-rw-r--r-- | lib/py/src/transport/TSocket.py | 8 |
2 files changed, 6 insertions, 6 deletions
diff --git a/lib/py/src/protocol/TBinaryProtocol.py b/lib/py/src/protocol/TBinaryProtocol.py index db1a7a407..50c6aa896 100644 --- a/lib/py/src/protocol/TBinaryProtocol.py +++ b/lib/py/src/protocol/TBinaryProtocol.py @@ -127,13 +127,13 @@ class TBinaryProtocol(TProtocolBase): 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 5e58825f2..87119612f 100644 --- a/lib/py/src/transport/TSocket.py +++ b/lib/py/src/transport/TSocket.py @@ -86,23 +86,23 @@ class TSocket(TSocketBase): 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:] |