コード例 #1
0
ファイル: CompatTest.py プロジェクト: morristech/TACKpy
    def test_Compat(self):
        assert (isinstance(a2b_hex("00"), bytearray))
        assert (a2b_hex("0102cdef") == bytearray([0x01, 0x02, 0xcd, 0xef]))
        assert (a2b_hex("0102CDEF") == bytearray([0x01, 0x02, 0xcd, 0xef]))
        try:
            assert (a2b_hex("c0102cdef") == bytearray([0x01, 0x02, 0xcd,
                                                       0xef]))
            assert False
        except SyntaxError:
            pass
        try:
            assert (a2b_hex("xx0102cdef") == bytearray(
                [0x01, 0x02, 0xcd, 0xef]))
            assert False
        except SyntaxError:
            pass

        assert (isinstance(a2b_base64("0000"), bytearray))
        assert (a2b_base64("Zm9vYg==") == bytearray(b"foob"))

        assert (b2a_hex(bytearray([0x01, 0x02, 0xcd, 0xef])) == "0102cdef")
        assert (b2a_hex(bytearray([0x00])) == "00")
        assert (b2a_hex(bytearray([0xFF])) == "ff")

        assert (b2a_base64(bytearray(b"foob")) == "Zm9vYg==\n")
        assert (b2a_base64(bytearray(b"fooba")) == "Zm9vYmE=\n")
        assert (b2a_base64(bytearray(b"foobar")) == "Zm9vYmFy\n")

        assert (bytesToStrAscii(bytearray(b"abcd123")) == "abcd123")
コード例 #2
0
ファイル: CompatTest.py プロジェクト: kilink/TACKpy
    def test_Compat(self):
        assert(isinstance(a2b_hex("00"), bytearray))
        assert(a2b_hex("0102cdef") == bytearray([0x01,0x02,0xcd,0xef]))
        assert(a2b_hex("0102CDEF") == bytearray([0x01,0x02,0xcd,0xef]))
        try:
            assert(a2b_hex("c0102cdef") == bytearray([0x01,0x02,0xcd,0xef]))
            assert False
        except SyntaxError:
            pass
        try:
            assert(a2b_hex("xx0102cdef") == bytearray([0x01,0x02,0xcd,0xef]))
            assert False
        except SyntaxError:
            pass

        assert(isinstance(a2b_base64("0000"), bytearray))
        assert(a2b_base64("Zm9vYg==") == bytearray(b"foob"))

        assert(b2a_hex(bytearray([0x01,0x02,0xcd,0xef])) == "0102cdef")
        assert(b2a_hex(bytearray([0x00])) == "00")
        assert(b2a_hex(bytearray([0xFF])) == "ff")

        assert(b2a_base64(bytearray(b"foob")) == "Zm9vYg==\n")
        assert(b2a_base64(bytearray(b"fooba")) == "Zm9vYmE=\n")
        assert(b2a_base64(bytearray(b"foobar")) == "Zm9vYmFy\n")

        assert(bytesToStrAscii(bytearray(b"abcd123")) == "abcd123")
コード例 #3
0
ファイル: Util.py プロジェクト: kilink/TACKpy
 def writeBytes(b):
     """Write hex-encoded byte array with 16 bytes (32 chars) per line"""
     s = b2a_hex(b)
     retVal = ""
     while s:
         retVal += s[:32]
         s = s[32:]
         if len(s):
             retVal += "\n                 "
     return retVal
コード例 #4
0
 def writeBytes(b):
     """Write hex-encoded byte array with 16 bytes (32 chars) per line"""
     s = b2a_hex(b)
     retVal = ""
     while s:
         retVal += s[:32]
         s = s[32:]
         if len(s):
             retVal += "\n                  "
     return retVal