Esempio n. 1
0
    def check_pack_unpack(packet, numeric_type):
        packed = dictpack.pack(packet, numeric_type)
        assert dictpack.pack(packet, numeric_type) == packed

        unpack_packet, unpack_numeric = dictpack.unpack(packed)
        assert unpack_packet == packet
        assert unpack_numeric == numeric_type
Esempio n. 2
0
    def check_pack_unpack(packet, numeric_type):
        packed = dictpack.pack(packet, numeric_type)
        assert dictpack.pack(packet, numeric_type) == packed

        unpack_packet, unpack_numeric = dictpack.unpack(packed)
        assert unpack_packet == packet
        assert unpack_numeric == numeric_type
Esempio n. 3
0
def test_pack_errors():
    # test unknown packet
    class PacketUnknown(packets.Packet): pass

    packet = PacketUnknown()
    packed = dictpack.pack(PacketUnknown(), True)

    unpack_packet, unpack_numeric = dictpack.unpack(packed)
    assert isinstance(unpack_packet, packets.PacketError), 'unpack should return PacketError'
    assert unpack_numeric == True, 'unpack should return numeric type False'
Esempio n. 4
0
def test_pack_errors():
    # test unknown packet
    class PacketUnknown(packets.Packet):
        pass

    packet = PacketUnknown()
    packed = dictpack.pack(PacketUnknown(), True)

    unpack_packet, unpack_numeric = dictpack.unpack(packed)
    assert isinstance(unpack_packet,
                      packets.PacketError), 'unpack should return PacketError'
    assert unpack_numeric == True, 'unpack should return numeric type False'
Esempio n. 5
0
 def sendPacket(self, packet, reset_keepalive=True):
     p_dict = pack(packet, self._numeric_type)
     p_type = p_dict.pop('type')
     self.dataWrite(self._packer.pack([p_type, p_dict]), reset_keepalive)
Esempio n. 6
0
 def _pack_packets(self, packets):
     for packet in packets:
         p_dict = pack(packet, self._numeric_type)
         p_type = p_dict.pop('type')
         yield self._packer.pack([p_type, p_dict])
Esempio n. 7
0
 def sendPacket(self, packet, reset_keepalive=True):
     p_dict = pack(packet, self._numeric_type)
     p_type = p_dict.pop('type')
     self.dataWrite(self._packer.pack([p_type, p_dict]), reset_keepalive)
Esempio n. 8
0
 def _pack_packets(self, packets):
     for packet in packets:
         p_dict = pack(packet, self._numeric_type)
         p_type = p_dict.pop('type')
         yield self._packer.pack([p_type, p_dict])