Example #1
0
 def put(self, index, value):
     if type(value) == int or type(value) == long:
         self.items[index] = bincalc.numberToBytes(value)
         
     elif type(value) == bytearray or type(value) == str:
         self.items[index] = bytearray(value)
         
     elif type(value) == unicode:
         self.items[index] = bincalc.unicodeToByteArray(value)
         
     else:
         raise NotImplementedError("%s not supported" % type(value))
Example #2
0
    def test_02_numberToByteArray(self):
        # bincalc.py
        print
        print "  number |                    encoded | restored"
        print "---------+----------------------------+----------"

        tests = [0, 1, 127, 128, 255, 256, 1024, 65535, 65536, 1<<62, 1<<63]
        for orig in tests:
            b = bincalc.numberToBytes(orig)
            restored = bincalc.bytesToNumber(b)
            print "   %5i | %26s | %s" % (orig, repr(b), repr(restored))
            self.assertEqual(orig, restored)