diff options
Diffstat (limited to 'pyload/remote/thriftbackend/Socket.py')
-rw-r--r-- | pyload/remote/thriftbackend/Socket.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/pyload/remote/thriftbackend/Socket.py b/pyload/remote/thriftbackend/Socket.py index f6edc8408..7e1268c5c 100644 --- a/pyload/remote/thriftbackend/Socket.py +++ b/pyload/remote/thriftbackend/Socket.py @@ -11,22 +11,28 @@ from thrift.transport.TSocket import TSocket, TServerSocket, TTransportException WantReadError = Exception #overwritten when ssl is used class SecureSocketConnection(object): + def __init__(self, connection): self.__dict__["connection"] = connection + def __getattr__(self, name): return getattr(self.__dict__["connection"], name) + def __setattr__(self, name, value): setattr(self.__dict__["connection"], name, value) + def shutdown(self, how=1): self.__dict__["connection"].shutdown() + def accept(self): connection, address = self.__dict__["connection"].accept() return SecureSocketConnection(connection), address + def send(self, buff): try: return self.__dict__["connection"].send(buff) @@ -34,6 +40,7 @@ class SecureSocketConnection(object): sleep(0.1) return self.send(buff) + def recv(self, buff): try: return self.__dict__["connection"].recv(buff) @@ -42,10 +49,12 @@ class SecureSocketConnection(object): return self.recv(buff) class Socket(TSocket): + def __init__(self, host='localhost', port=7228, ssl=False): TSocket.__init__(self, host, port) self.ssl = ssl + def open(self): if self.ssl: SSL = __import__("OpenSSL", globals(), locals(), "SSL", -1).SSL @@ -62,6 +71,7 @@ class Socket(TSocket): self.handle.settimeout(self._timeout) self.handle.connect((self.host, self.port)) + def read(self, sz): try: buff = self.handle.recv(sz) @@ -93,6 +103,7 @@ class Socket(TSocket): class ServerSocket(TServerSocket, Socket): + def __init__(self, port=7228, host="0.0.0.0", key="", cert=""): self.host = host self.port = port @@ -100,6 +111,7 @@ class ServerSocket(TServerSocket, Socket): self.cert = cert self.handle = None + def listen(self): if self.cert and self.key: SSL = __import__("OpenSSL", globals(), locals(), "SSL", -1).SSL @@ -122,6 +134,7 @@ class ServerSocket(TServerSocket, Socket): self.handle.bind((self.host, self.port)) self.handle.listen(128) + def accept(self): client, addr = self.handle.accept() result = Socket() |