summaryrefslogtreecommitdiff
path: root/bin/tiny_socket.py
diff options
context:
space:
mode:
authorced <>2007-03-13 15:11:29 +0000
committerced <>2007-03-13 15:11:29 +0000
commit82eeab710a53e7984a2a70ed02414c275b208eee (patch)
tree6e2ed9156fae361ebb2de962c16f9cf055c5d91c /bin/tiny_socket.py
parentbfff615b9b4b24d7f2786ac12ad93ea3671bcfff (diff)
CLIENT/SERVER: improve tiny_socket for exception and remove some bad print
bzr revid: ced-5911d9548ae7c671f8c41718d1ca4459fb9c1f52
Diffstat (limited to 'bin/tiny_socket.py')
-rw-r--r--bin/tiny_socket.py20
1 files changed, 18 insertions, 2 deletions
diff --git a/bin/tiny_socket.py b/bin/tiny_socket.py
index 52690d09c1b..545462d5c06 100644
--- a/bin/tiny_socket.py
+++ b/bin/tiny_socket.py
@@ -2,6 +2,11 @@ import socket
import cPickle
import marshal
+class Myexception(Exception):
+ def __init__(self, faultCode, faultString):
+ self.faultCode = faultCode
+ self.faultString = faultString
+
class mysocket:
def __init__(self, sock=None):
if sock is None:
@@ -10,8 +15,11 @@ class mysocket:
else:
self.sock = sock
self.sock.settimeout(60)
- def connect(self, host, port):
- self.sock.connect((host, port))
+ def connect(self, host, port=False):
+ if not port:
+ protocol, buf = host.split('//')
+ host, port = buf.split(':')
+ self.sock.connect((host, int(port)))
def disconnect(self):
self.sock.shutdown(socket.SHUT_RDWR)
self.sock.close()
@@ -19,6 +27,7 @@ class mysocket:
msg = cPickle.dumps(msg)
size = len(msg)
self.sock.send('%8d' % size)
+ self.sock.send(exception and "1" or "0")
totalsent = 0
while totalsent < size:
sent = self.sock.send(msg[totalsent:])
@@ -33,6 +42,11 @@ class mysocket:
raise RuntimeError, "socket connection broken"
buf += chunk
size = int(buf)
+ buf = self.sock.recv(1)
+ if buf != "0":
+ exception = buf
+ else:
+ exception = False
msg = ''
while len(msg) < size:
chunk = self.sock.recv(size-len(msg))
@@ -41,6 +55,8 @@ class mysocket:
msg = msg + chunk
res = cPickle.loads(msg)
if isinstance(res,Exception):
+ if exception:
+ raise Myexception(exception, str(res))
raise res
else:
return res