You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by es...@apache.org on 2009/09/24 12:22:00 UTC

svn commit: r818429 - in /incubator/thrift/trunk/lib/py/src: protocol/TBinaryProtocol.py transport/TSocket.py

Author: esteve
Date: Thu Sep 24 10:22:00 2009
New Revision: 818429

URL: http://svn.apache.org/viewvc?rev=818429&view=rev
Log:
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


Modified:
    incubator/thrift/trunk/lib/py/src/protocol/TBinaryProtocol.py
    incubator/thrift/trunk/lib/py/src/transport/TSocket.py

Modified: incubator/thrift/trunk/lib/py/src/protocol/TBinaryProtocol.py
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/py/src/protocol/TBinaryProtocol.py?rev=818429&r1=818428&r2=818429&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/py/src/protocol/TBinaryProtocol.py (original)
+++ incubator/thrift/trunk/lib/py/src/protocol/TBinaryProtocol.py Thu Sep 24 10:22:00 2009
@@ -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()

Modified: incubator/thrift/trunk/lib/py/src/transport/TSocket.py
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/py/src/transport/TSocket.py?rev=818429&r1=818428&r2=818429&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/py/src/transport/TSocket.py (original)
+++ incubator/thrift/trunk/lib/py/src/transport/TSocket.py Thu Sep 24 10:22:00 2009
@@ -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:]