5 class Myexception(Exception):
6 def __init__(self, faultCode, faultString):
7 self.faultCode = faultCode
8 self.faultString = faultString
9 self.args = (faultCode, faultString)
12 def __init__(self, sock=None):
14 self.sock = socket.socket(
15 socket.AF_INET, socket.SOCK_STREAM)
18 self.sock.settimeout(120)
19 def connect(self, host, port=False):
21 protocol, buf = host.split('//')
22 host, port = buf.split(':')
23 self.sock.connect((host, int(port)))
25 self.sock.shutdown(socket.SHUT_RDWR)
27 def mysend(self, msg, exception=False, traceback=None):
28 msg = cPickle.dumps([msg,traceback])
30 self.sock.send('%8d' % size)
31 self.sock.send(exception and "1" or "0")
33 while totalsent < size:
34 sent = self.sock.send(msg[totalsent:])
36 raise RuntimeError, "socket connection broken"
37 totalsent = totalsent + sent
41 chunk = self.sock.recv(8 - len(buf))
43 raise RuntimeError, "socket connection broken"
46 buf = self.sock.recv(1)
52 while len(msg) < size:
53 chunk = self.sock.recv(size-len(msg))
55 raise RuntimeError, "socket connection broken"
57 res = cPickle.loads(msg)
58 if isinstance(res[0],Exception):
60 raise Myexception(str(res[0]), str(res[1]))