def nextMsg(self, *args, **kw): """Convenience function that handles any buffering required to read the next full message. This is overloaded so we can always unpack the pickled message.""" # get the next message delimited by the delim character msg = ServerClientSocket.nextMsg(self, self.delimiter, *args, **kw) try: data = pickle.loads(msg) #if random.randint(1,100) == 1: # raise pickle.BadPickleGet, 'test bad pickle!' return data except EOFError, e: return {}
def __init__(self, sock, address, **kw): """Same init. Just grab delimiter.""" ServerClientSocket.__init__(self, sock, address, **kw)
def send(self, msg, *args, **kw): """All messages are first packed by pickle and then delimited.""" pickmsg = pickle.dumps(msg) + self.delimiter #print 'sending %d bytes' % len(pickmsg) ServerClientSocket.send(self, pickmsg, *args, **kw)