Exemple #1
0
    def dataReceived(self, data):
        self.buffer += data
        packets, self.buffer = parse_packets(self.buffer)

        for header, payload in packets:
            if header in packet_handlers:
                packet_handlers[header](self, payload)
            else:
                self.dummy_handler(header, payload)
Exemple #2
0
    def filter(self, data):
        if self._enabled:
            self.buffer += data
            packets, self.buffer = parse_packets(self.buffer)

            for header, payload in packets:
                [ p.packet(header, payload) for p in self.plugins ]

        return data
Exemple #3
0
    def dataReceived(self, data):
        self.buf += data

        packets, self.buf = parse_packets(self.buf)

        for header, payload in packets:
            if header in self.handlers:
                self.handlers[header](payload)
            else:
                log.err("Didn't handle parseable packet %d!" % header)
                log.err(payload)
Exemple #4
0
    def dataReceived(self, data):
        self.buf += data

        packets, self.buf = parse_packets(self.buf)

        for header, payload in packets:
            if header in self.handlers:
                self.handlers[header](payload)
            else:
                log.err("Didn't handle parseable packet %d!" % header)
                log.err(payload)
Exemple #5
0
def full_chunk_test():
    # compare two full chunks
    chunk1 = Chunk(0, 0)
    chunk2 = Chunk(0, 0)
    randomize_chunk(chunk1)
    packet1 = chunk1.save_to_packet()
    p, l = parse_packets(packet1)
    header, payload = p[0]
    chunk2.load_from_packet(payload)
    packet2 = chunk2.save_to_packet()
    compare_chunks(chunk1, chunk2)
    def publish(self, data):
        self.buffer += data
        packets, self.buffer = parse_packets(self.buffer)

        l = []
        for header, payload in packets:
            # send the packet to listeners of "packet-X"...they can choose what to listen for
            r = plugin_manager.publish("packet-%s" % packets_by_id[header], header, payload)
            l.append(r)

        def breakdown(the_list):
            data = ""
            for i in the_list:
                if isinstance(i, StringType):
                    data += i
                elif i == [None]:
                    continue
                elif isinstance(i, ListType):
                    data = breakdown(i)
                else:
                    data += chr(i[0]) + packet_def[i[0]].build(i[1])
            return data

        return breakdown(l)
Exemple #7
0
    # compare two full chunks
    chunk1 = Chunk(0, 0)
    chunk2 = Chunk(0, 0)
    randomize_chunk(chunk1)
    packet1 = chunk1.save_to_packet()
    p, l = parse_packets(packet1)
    header, payload = p[0]
    chunk2.load_from_packet(payload)
    packet2 = chunk2.save_to_packet()
    compare_chunks(chunk1, chunk2)


if __name__ == "__main__":
    import cProfile
    import sys


    speed_test = False

    full_chunk_test()

    if speed_test:
        # fastest: 1.107
        # python2.5
        test_packet = parse_packets(randomize_chunk(Chunk(0,0)).save_to_packet())[0][0][1]
        def load_test():
            for i in range(0, 10):
                c = Chunk(0,0).load_from_packet(test_packet) 
        cProfile.run("load_test()", "chunk.prof")