コード例 #1
0
ファイル: messageBusServerPP.py プロジェクト: pwuertz/qao
 def _recvPacketPickled(self):
     try:
         dataRaw = self._recvPacket()
         print dataRaw
         try:
             data = jsonEncoder.loads(dataRaw)
         except Exception, e:
             print("no valid json data received: falling back to old pickle decoding")
             data = cPickle.loads(dataRaw)
         
         if len(data) < 2:
             raise Exception("packet with insufficient number of args")
         
         # add the second arg to the list of subscriptions
         if data[0] == messageBus.TYPE_SUBSCRIBE:
             self.subscriptions.add(data[1])
             return
         
         # remove the second arg to the list of subscriptions
         if data[0] == messageBus.TYPE_UNSUBSCRIBE:
             self.subscriptions.remove(data[1])
             return
         
         # publish packet to the server
         if data[0] == messageBus.TYPE_PUBLISH:
             if len(data) < 3:
                 raise Exception("packet with insufficient number of args")
             self.server._handlePublish(data[1], data[2])
             return
         
         # packet not recognized
         raise Exception("unrecognized instruction in packet")
コード例 #2
0
ファイル: messageBusPP.py プロジェクト: pwuertz/qao
    def _handleNewPacket(self, dataRaw):
        try:
            data = jsonEncoder.loads(dataRaw)

            #print "Depickle took %.2f s"%(time.time()-picklestarttime)
            if len(data) < 2:
                raise Exception("packet with insufficient number of args")

            if data[0] == TYPE_PUBLISH:
                if len(data) < 3: raise Exception("packet with insufficient number of args")
                self._handlePublish(data[1], data[2])

            if data[0] == TYPE_NAK:
                raise Exception("server reported: %s" % data[1])

        except Exception, e:
            errorstr = type(e).__name__ + ", " + str(e)
            sys.stderr.write(errorstr + "\n")