diff --git a/src/libs/python/bongo/store/CommandStream.py b/src/libs/python/bongo/store/CommandStream.py index 5d86edd..c1f9e26 100644 --- a/src/libs/python/bongo/store/CommandStream.py +++ b/src/libs/python/bongo/store/CommandStream.py @@ -92,7 +92,10 @@ class CommandStream: def __init__(self, socket): self.stream = socket.makefile() - + + def setEventCallback(self, callback): + self.eventCallback = callback + def close(self): self.stream.close() @@ -113,10 +116,23 @@ class CommandStream: self.stream.flush() def GetResponse(self, nolog=False): - s = self.readline() - if not nolog: - self.log.debug("READ: %s", s) - return Response(s[0:4], s[5:]) + rCode = 0 + s = '' + + while rCode == 0: + s = self.readline() + if not nolog: + self.log.debug("READ: %s", s) + rCode = int(s[0:4]) + if rCode > 5999: + # this is a store 'event': send the response to the + # callback if we have one; otherwise it essentially + # gets eaten. + rCode = 0 + if self.eventCallback: + self.eventCallback(Response(rCode, s[5:]) + + return Response(rCode, s[5:]) def readline(self): s = self.stream.readline() diff --git a/src/libs/python/bongo/store/StoreClient.py b/src/libs/python/bongo/store/StoreClient.py index 43e2fe4..11a0caa 100644 --- a/src/libs/python/bongo/store/StoreClient.py +++ b/src/libs/python/bongo/store/StoreClient.py @@ -359,7 +359,7 @@ class CalendarACL : class StoreClient: def __init__(self, user, owner, authToken=None, authCookie=None, - authPassword=None, host="localhost", port=689): + authPassword=None, host="localhost", port=689, eventCallback=None): #from libbongo.libs import msgapi self.owner = self.user = None @@ -380,6 +380,8 @@ class StoreClient: self.connection = StoreConnection(host, port) self.stream = self.connection.stream + if eventCallback: + self.stream.setEventCallback(callback) # if we authed with a cookie or password, we don't need to USER if not authCookie and not authPassword and user is not None: @@ -665,7 +667,15 @@ class StoreClient: r = self.stream.GetResponse() if r.code != 1000: raise CommandError(r) - + + def NoOp(self): + command = "NOOP" + + self.stream.Write(command) + r = self.stream.GetResponse() + if r.code != 1000: + raise CommandError(r) + # this function is here to coerce strings in unknown encodings # into something approaching utf-8. This is obviously lossy, # and we really don't want to have to do this - need to get the