Merging EOFException changes from Ben Maurer
Summary: Throw a proper EOFError in this case. Long term we want to change this to properly fit into the Thrift TException heirarchy with a good way to handle the original exception as well. For now, Ben is the primary user of this so we'll go ahead with his patch.
Reviewed By: mcslee
Test Plan: Included in test/py/TestEof.py
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665365 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/py/src/protocol/fastbinary.c b/lib/py/src/protocol/fastbinary.c
index 61ccd8f..3b7b5c0 100644
--- a/lib/py/src/protocol/fastbinary.c
+++ b/lib/py/src/protocol/fastbinary.c
@@ -684,6 +684,9 @@
static bool
checkTypeByte(DecodeBuffer* input, TType expected) {
TType got = readByte(input);
+ if (INT_CONV_ERROR_OCCURRED(got)) {
+ return false;
+ }
if (expected != got) {
PyErr_SetString(PyExc_TypeError, "got wrong ttype while reading field");
@@ -829,11 +832,16 @@
StructItemSpec parsedspec;
type = readByte(input);
+ if (type == -1) {
+ return false;
+ }
if (type == T_STOP) {
break;
}
tag = readI16(input);
-
+ if (INT_CONV_ERROR_OCCURRED(tag)) {
+ return false;
+ }
if (tag >= 0 && tag < spec_seq_len) {
item_spec = PyTuple_GET_ITEM(spec_seq, tag);
} else {
diff --git a/lib/py/src/transport/TTransport.py b/lib/py/src/transport/TTransport.py
index 60f4233..3968a71 100644
--- a/lib/py/src/transport/TTransport.py
+++ b/lib/py/src/transport/TTransport.py
@@ -47,6 +47,10 @@
chunk = self.read(sz-have)
have += len(chunk)
buff += chunk
+
+ if len(chunk) == 0:
+ raise EOFError()
+
return buff
def write(self, buf):
@@ -213,7 +217,7 @@
def cstringio_refill(self, partialread, reqlen):
# only one shot at reading...
- raise EOFException()
+ raise EOFError()
class TFramedTransportFactory: