예제 #1
0
    def process_item(self, item):
        
        if item.type == PacketTypes.Ping:
            reply, recvd = self.send(item.message, True)
        else:
            reply, recvd = self.send(item.message)
            
        if recvd > 0:
            try:
                packets = Message.parse_xml(reply)
            
                for packet in packets:
                   
                    if packet.type in (PacketTypes.UserData, PacketTypes.UnknownUser):
                        item.queue.put(packet)
                    elif packet.type == PacketTypes.PingReply:
                        self.got_ping_reply(packet, recvd)
                    elif packet.type in (PacketTypes.ProductData, PacketTypes.UnknownProduct):
                        item.queue.put(packet)
                    elif packet.type in (PacketTypes.RandomProduct):
                        item.queue.put(packet)
                    elif packet.type == PacketTypes.Result:
                        if packet.data['action'] == PacketTypes.Transaction:
                            item.queue.put(packet)
                        if packet.data['action'] == PacketTypes.AddProduct:
                            item.queue.put(packet)
                        if packet.data['action'] == PacketTypes.AddCredit:
                            item.queue.put(packet)

            except InputException:
                pass ## Let the ping task deal with finding the server has gone
        else:
            if (item.type == PacketTypes.Ping):
                self.got_ping_reply(None, 0)
예제 #2
0
    def handle_message(self, message):
        """ Pass message to database layer and get reply """
        packets = Message.parse_xml(message)

        reply = self.dbase.process_packets(packets)

        return reply
예제 #3
0
    def process_item(self, item):

        if item.type == PacketTypes.Ping:
            reply, recvd = self.send(item.message, True)
        else:
            reply, recvd = self.send(item.message)

        if recvd > 0:
            try:
                packets = Message.parse_xml(reply)

                for packet in packets:

                    if packet.type in (PacketTypes.UserData,
                                       PacketTypes.UnknownUser):
                        item.queue.put(packet)
                    elif packet.type == PacketTypes.PingReply:
                        self.got_ping_reply(packet, recvd)
                    elif packet.type in (PacketTypes.ProductData,
                                         PacketTypes.UnknownProduct):
                        item.queue.put(packet)
                    elif packet.type in (PacketTypes.RandomProduct):
                        item.queue.put(packet)
                    elif packet.type == PacketTypes.Result:
                        if packet.data['action'] == PacketTypes.Transaction:
                            item.queue.put(packet)
                        if packet.data['action'] == PacketTypes.AddProduct:
                            item.queue.put(packet)
                        if packet.data['action'] == PacketTypes.AddCredit:
                            item.queue.put(packet)

            except InputException:
                pass  ## Let the ping task deal with finding the server has gone
        else:
            if (item.type == PacketTypes.Ping):
                self.got_ping_reply(None, 0)