Пример #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
Пример #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
Пример #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'
Пример #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'
Пример #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)
Пример #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])
Пример #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)
Пример #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])