diff options
author | Mark Slee <mcslee@apache.org> | 2006-09-03 21:13:07 +0000 |
---|---|---|
committer | Mark Slee <mcslee@apache.org> | 2006-09-03 21:13:07 +0000 |
commit | cde2b61c5e3a26fd6ad5bc1a6fcdee449696d66c (patch) | |
tree | b238b0f6ce3c18d92e59ec4ca4836fcfa77a95c9 /lib/py/src/transport/TSocket.py | |
parent | dafa3cf710b21049f929500ca57957709f46b941 (diff) | |
download | thrift-cde2b61c5e3a26fd6ad5bc1a6fcdee449696d66c.tar.gz |
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
Diffstat (limited to 'lib/py/src/transport/TSocket.py')
-rw-r--r-- | lib/py/src/transport/TSocket.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/py/src/transport/TSocket.py b/lib/py/src/transport/TSocket.py new file mode 100644 index 000000000..52c6118a8 --- /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 |