Implementation of the basic Thrift stack in Python
Summary: Framework, install script, base classes, TSocket, TBinaryProtocol
Notes: Code-gen is coming around the bend...
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664778 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/py/src/transport/TSocket.py b/lib/py/src/transport/TSocket.py
new file mode 100644
index 0000000..52c6118
--- /dev/null
+++ b/lib/py/src/transport/TSocket.py
@@ -0,0 +1,45 @@
+from TTransport import *
+import socket
+
+class TSocket(TTransportBase):
+
+ """Socket implementation of TTransport base."""
+
+ handle = None
+ host = "localhost"
+ port = 9090
+
+ def __init__(self, host, port):
+ self.host = host
+ self.port = port
+ self.handle = None
+
+ def isOpen(self):
+ return handle != None
+
+ def open(self):
+ self.handle = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ self.handle.connect((self.host, self.port))
+
+ def close(self):
+ self.handle.close()
+ self.handle = None
+
+ def readAll(self, sz):
+ buff = ''
+ have = 0
+ while (have < sz):
+ chunk = self.read(sz-have)
+ have += len(chunk)
+ buff += chunk
+ return buff
+
+ def read(self, sz):
+ buff = self.handle.recv(sz)
+ return buff
+
+ def write(self, buff):
+ self.handle.sendall(buff)
+
+ def flush(self):
+ pass