1# test ustruct and endian specific things 2 3try: 4 import ustruct as struct 5except: 6 try: 7 import struct 8 except ImportError: 9 print("SKIP") 10 raise SystemExit 11 12# unpack/unpack_from with unaligned native type 13buf = b'0123456789' 14print(struct.unpack('h', memoryview(buf)[1:3])) 15print(struct.unpack_from('i', buf, 1)) 16print(struct.unpack_from('@i', buf, 1)) 17print(struct.unpack_from('@ii', buf, 1)) 18 19# pack_into with unaligned native type 20buf = bytearray(b'>----<<<<<<<') 21struct.pack_into('i', buf, 1, 0x30313233) 22print(buf) 23struct.pack_into('@ii', buf, 3, 0x34353637, 0x41424344) 24print(buf) 25