Esempio n. 1
0
 def run(self):
     self._setup_sse()
     edr_log = EDRLog()
     try:
         for msg in self.sse:
             if msg.event is "keep-alive":
                 edr_log.log(u"SSE keep-alive received", "DEBUG")
                 continue
             if msg.event is "auth_revoked":
                 edr_log.log(u"SSE auth_revoked received", "DEBUG")
                 self.message_queue.put(msg)
                 self.close()
                 break
             if msg.event is "cancel":
                 edr_log.log(u"SSE cancel received", "DEBUG")
                 self.message_queue.put(msg)
                 self.close()
                 break
             edr_log.log(
                 u"SSE msg received: {} {}".format(msg.event, msg.data),
                 "DEBUG")
             self.message_queue.put(msg)
     except socket.error:
         pass  # this can happen when we close the stream
     except requests.HTTPError:
         pass  # this can happen when the auth is no longer valid
Esempio n. 2
0
 def run(self):
     edr_log = EDRLog()
     while True:
         msg = self.inbound_queue.get()
         if not msg:
             edr_log.log(u"SSE stop signal received.", "DEBUG")
             break
         edr_log.log(
             u"handling msg: {} {} {}".format(msg.event, msg.data,
                                              self.kind), "DEBUG")
         if msg.event in ["put", "patch"] and msg.data:
             data = json.loads(msg.data)
             if data is None or data["data"] is None:
                 continue
             if data["path"] == '/':
                 # initial update
                 keys = sorted(data["data"])
                 for k in keys:
                     self.callback(self.kind, data["data"][k])
             else:
                 self.callback(self.kind, data["data"])
         elif msg.event in ["cancel", "auth_revoked"]:
             self.callback(self.kind, msg.event)