How to use pack method in Pytest

Best Python code snippet using pytest

textool.py

Source:textool.py Github

copy

Full Screen

...8#9# Type conversions10#11def pack_fp16(v):12 scale_to_inf = struct.unpack("=f", struct.pack("=I", 0x77800000))[0]13 scale_to_zero = struct.unpack("=f", struct.pack("=I", 0x08800000))[0]14 base = (abs(v) * scale_to_inf) * scale_to_zero15 w = struct.unpack("=I", struct.pack("=f", v))[0]16 shl1_w = w + w17 sign = w & 0x8000000018 bias = shl1_w & 0xff00000019 if bias < 0x71000000:20 bias = 0x7100000021 base += struct.unpack("=f", struct.pack("=I", (bias >> 1) + 0x07800000))[0]22 bits = struct.unpack("=I", struct.pack("=f", base))[0]23 exp_bits = (bits >> 13) & 0x00007c0024 mantissa_bits = bits & 0x00000fff25 nonsign = exp_bits + mantissa_bits26 return (sign >> 16) | (0x7e00 if shl1_w > 0xff000000 else nonsign)27def pack_r11g11b10f(r, g, b):28 return ((pack_fp16(r) >> 4) & 0x000007ff) | ((pack_fp16(g) << 7) & 0x003ff800) | ((pack_fp16(b) << 17) & 0xffc00000)29def pack_unorm8(v): return int(min(max(v * 255, 0), 255))30def pack_snorm8(v): return int(min(max(v * 127.5 * x - 0.5, -128), 127))31def pack_uint8(v): return int(min(max(v, 0), 255))32def pack_sint8(v): return int(min(max(v, -128), 127))33def pack_unorm16(v): return int(min(max(v * 65535, 0), 65535))34def pack_snorm16(v): return int(min(max(v * 32767.5 * x - 0.5, -32768), 32767))35def pack_uint16(v): return int(min(max(v, 0), 65535))36def pack_sint16(v): return int(min(max(v, -32768), 32767))37def pack_unorm32(v): return int(min(max(v * 4294967295, 0), 4294967295))38def pack_snorm32(v): return int(min(max(v * 2147483647.5 * x - 0.5, -2147483648), 2147483647))39def pack_uint32(v): return int(min(max(v, 0), 4294967295))40def pack_sint32(v): return int(min(max(v, -2147483648), 2147483647))41def pack_unorm64(v): return int(min(max(v * 18446744073709551615, 0), 18446744073709551615))42def pack_snorm64(v): return int(min(max(v * 9223372036854775807.5 * x - 0.5, -9223372036854775808), 9223372036854775807))43def pack_uint64(v): return int(min(max(v, 0), 18446744073709551615))44def pack_sint64(v): return int(min(max(v, -9223372036854775808), 9223372036854775807))45def pack_r10g10b10a2_unorm(r, g, b, a):46 r = (int(min(max(r * 1023, 0), 1023)) << 0) & 0x000003ff47 g = (int(min(max(g * 1023, 0), 1023)) << 10) & 0x000ffc0048 b = (int(min(max(b * 1023, 0), 1023)) << 20) & 0x3ff0000049 a = (int(min(max(a * 3, 0), 3)) << 30) & 0xc000000050 return r | g | b | a51def pack_r10g10b10a2_snorm(r, g, b, a):52 r = (int(min(max(r * 511.5 - 0.5, -512), 511)) << 0) & 0x000003ff53 g = (int(min(max(g * 511.5 - 0.5, -512), 511)) << 10) & 0x000ffc0054 b = (int(min(max(b * 511.5 - 0.5, -512), 511)) << 20) & 0x3ff0000055 a = (int(min(max(a * 1.5 - 0.5, -2), 1)) << 30) & 0xc000000056 return r | g | b | a57def pack_r10g10b10a2_uint(r, g, b, a):58 r = (int(min(max(r, 0), 1023)) << 0) & 0x000003ff59 g = (int(min(max(g, 0), 1023)) << 10) & 0x000ffc0060 b = (int(min(max(b, 0), 1023)) << 20) & 0x3ff0000061 a = (int(min(max(a, 0), 3)) << 30) & 0xc000000062 return r | g | b | a63def pack_r10g10b10a2_sint(r, g, b, a):64 r = (int(min(max(r, -512), 511)) << 0) & 0x000003ff65 g = (int(min(max(g, -512), 511)) << 10) & 0x000ffc0066 b = (int(min(max(b, -512), 511)) << 20) & 0x3ff0000067 a = (int(min(max(a, -2), 1)) << 30) & 0xc000000068 return r | g | b | a69PF_VULKAN = 070PF_DXGI = 171PF_PACKING = 272PF_BPP = 373PF_BLKW = 474PF_BLKH = 575PF_FUNC = 676PIXELFORMATS = {77 'r4g4-unorm': [ 1, 0, 'L', 8, 1, 1 ],78 'r4g4b4a4-unorm': [ 2, 0, 'L', 16, 1, 1 ],79 'b4g4r4a4-unorm': [ 3, 115, 'L', 16, 1, 1 ],80 'r5g6b5-unorm': [ 4, 0, 'L', 16, 1, 1 ],81 'b5g6r5-unorm': [ 5, 85, 'L', 16, 1, 1 ],82 'r5g5b5a1-unorm': [ 6, 0, 'L', 16, 1, 1 ],83 'b5g5r5a1-unorm': [ 7, 86, 'L', 16, 1, 1 ],84 'a1r5g5b5-unorm': [ 8, 0, 'L', 16, 1, 1 ],85 'r8-unorm': [ 9, 61, 'L', 8, 1, 1, lambda x: struct.pack("=B", pack_unorm8(x[0][0][0])) ],86 'r8-snorm': [ 10, 63, 'L', 8, 1, 1, lambda x: struct.pack("=B", pack_snorm8(x[0][0][0])) ],87 'r8-uscaled': [ 11, 0, 'L', 8, 1, 1, lambda x: struct.pack("=B", pack_uint8(x[0][0][0])) ],88 'r8-sscaled': [ 12, 0, 'L', 8, 1, 1, lambda x: struct.pack("=B", pack_sint8(x[0][0][0])) ],89 'r8-uint': [ 13, 62, 'L', 8, 1, 1, lambda x: struct.pack("=B", pack_uint8(x[0][0][0])) ],90 'r8-sint': [ 14, 64, 'L', 8, 1, 1, lambda x: struct.pack("=B", pack_sint8(x[0][0][0])) ],91 'r8-srgb': [ 15, 0, 'L', 8, 1, 1, lambda x: struct.pack("=B", pack_unorm8(x[0][0][0])) ],92 'r8g8-unorm': [ 16, 49, 'L', 16, 1, 1, lambda x: struct.pack("=BB", pack_unorm8(x[0][0][0]), pack_unorm8(x[0][0][1])) ],93 'r8g8-snorm': [ 17, 51, 'L', 16, 1, 1, lambda x: struct.pack("=BB", pack_snorm8(x[0][0][0]), pack_snorm8(x[0][0][1])) ],94 'r8g8-uscaled': [ 16, 0, 'L', 16, 1, 1, lambda x: struct.pack("=BB", pack_uint8(x[0][0][0]), pack_uint8(x[0][0][1])) ],95 'r8g8-sscaled': [ 19, 0, 'L', 16, 1, 1, lambda x: struct.pack("=BB", pack_sint8(x[0][0][0]), pack_sint8(x[0][0][1])) ],96 'r8g8-uint': [ 20, 50, 'L', 16, 1, 1, lambda x: struct.pack("=BB", pack_uint8(x[0][0][0]), pack_sint8(x[0][0][1])) ],97 'r8g8-sint': [ 21, 52, 'L', 16, 1, 1, lambda x: struct.pack("=BB", pack_sint8(x[0][0][0]), pack_sint8(x[0][0][1])) ],98 'r8g8-srgb': [ 22, 0, 'L', 16, 1, 1, lambda x: struct.pack("=BB", pack_unorm8(x[0][0][0]), pack_unorm8(x[0][0][1])) ],99 'r8g8b8-unorm': [ 23, 0, 'L', 24, 1, 1, lambda x: struct.pack("=BBB", pack_unorm8(x[0][0][0]), pack_unorm8(x[0][0][1]), pack_unorm8(x[0][0][2])) ],100 'r8g8b8-snorm': [ 24, 0, 'L', 24, 1, 1, lambda x: struct.pack("=BBB", pack_snorm8(x[0][0][0]), pack_snorm8(x[0][0][1]), pack_snorm8(x[0][0][2])) ],101 'r8g8b8-uscaled': [ 25, 0, 'L', 24, 1, 1, lambda x: struct.pack("=BBB", pack_uint8(x[0][0][0]), pack_uint8(x[0][0][1]), pack_uint8(x[0][0][2])) ],102 'r8g8b8-sscaled': [ 26, 0, 'L', 24, 1, 1, lambda x: struct.pack("=BBB", pack_sint8(x[0][0][0]), pack_sint8(x[0][0][1]), pack_sint8(x[0][0][2])) ],103 'r8g8b8-uint': [ 27, 0, 'L', 24, 1, 1, lambda x: struct.pack("=BBB", pack_uint8(x[0][0][0]), pack_uint8(x[0][0][1]), pack_uint8(x[0][0][2])) ],104 'r8g8b8-sint': [ 28, 0, 'L', 24, 1, 1, lambda x: struct.pack("=BBB", pack_sint8(x[0][0][0]), pack_sint8(x[0][0][1]), pack_sint8(x[0][0][2])) ],105 'r8g8b8-srgb': [ 29, 0, 'L', 24, 1, 1, lambda x: struct.pack("=BBB", pack_unorm8(x[0][0][0]), pack_unorm8(x[0][0][1]), pack_unorm8(x[0][0][2])) ],106 'b8g8r8-unorm': [ 30, 0, 'L', 24, 1, 1, lambda x: struct.pack("=BBB", pack_unorm8(x[0][0][2]), pack_unorm8(x[0][0][1]), pack_unorm8(x[0][0][0])) ],107 'b8g8r8-snorm': [ 31, 0, 'L', 24, 1, 1, lambda x: struct.pack("=BBB", pack_snorm8(x[0][0][2]), pack_snorm8(x[0][0][1]), pack_snorm8(x[0][0][0])) ],108 'b8g8r8-uscaled': [ 32, 0, 'L', 24, 1, 1, lambda x: struct.pack("=BBB", pack_uint8(x[0][0][2]), pack_uint8(x[0][0][1]), pack_uint8(x[0][0][0])) ],109 'b8g8r8-sscaled': [ 33, 0, 'L', 24, 1, 1, lambda x: struct.pack("=BBB", pack_sint8(x[0][0][2]), pack_sint8(x[0][0][1]), pack_sint8(x[0][0][0])) ],110 'b8g8r8-uint': [ 34, 0, 'L', 24, 1, 1, lambda x: struct.pack("=BBB", pack_uint8(x[0][0][2]), pack_uint8(x[0][0][1]), pack_uint8(x[0][0][0])) ],111 'b8g8r8-sint': [ 35, 0, 'L', 24, 1, 1, lambda x: struct.pack("=BBB", pack_sint8(x[0][0][2]), pack_sint8(x[0][0][1]), pack_sint8(x[0][0][0])) ],112 'b8g8r8-srgb': [ 36, 0, 'L', 24, 1, 1, lambda x: struct.pack("=BBB", pack_unorm8(x[0][0][2]), pack_unorm8(x[0][0][1]), pack_unorm8(x[0][0][0])) ],113 'r8g8b8a8-unorm': [ 37, 28, 'L', 32, 1, 1, lambda x: struct.pack("=BBBB", pack_unorm8(x[0][0][0]), pack_unorm8(x[0][0][1]), pack_unorm8(x[0][0][2]), pack_unorm8(x[0][0][3])) ],114 'r8g8b8a8-snorm': [ 38, 31, 'L', 32, 1, 1, lambda x: struct.pack("=BBBB", pack_snorm8(x[0][0][0]), pack_snorm8(x[0][0][1]), pack_snorm8(x[0][0][2]), pack_snorm8(x[0][0][3])) ],115 'r8g8b8a8-uscaled': [ 39, 0, 'L', 32, 1, 1, lambda x: struct.pack("=BBBB", pack_uint8(x[0][0][0]), pack_uint8(x[0][0][1]), pack_uint8(x[0][0][2]), pack_uint8(x[0][0][3])) ],116 'r8g8b8a8-sscaled': [ 40, 0, 'L', 32, 1, 1, lambda x: struct.pack("=BBBB", pack_sint8(x[0][0][0]), pack_sint8(x[0][0][1]), pack_sint8(x[0][0][2]), pack_sint8(x[0][0][3])) ],117 'r8g8b8a8-uint': [ 41, 30, 'L', 32, 1, 1, lambda x: struct.pack("=BBBB", pack_uint8(x[0][0][0]), pack_uint8(x[0][0][1]), pack_uint8(x[0][0][2]), pack_uint8(x[0][0][3])) ],118 'r8g8b8a8-sint': [ 42, 32, 'L', 32, 1, 1, lambda x: struct.pack("=BBBB", pack_sint8(x[0][0][0]), pack_sint8(x[0][0][1]), pack_sint8(x[0][0][2]), pack_sint8(x[0][0][3])) ],119 'r8g8b8a8-srgb': [ 43, 29, 'L', 32, 1, 1, lambda x: struct.pack("=BBBB", pack_unorm8(x[0][0][0]), pack_unorm8(x[0][0][1]), pack_unorm8(x[0][0][2]), pack_unorm8(x[0][0][3])) ],120 'b8g8r8a8-unorm': [ 44, 87, 'L', 32, 1, 1, lambda x: struct.pack("=BBBB", pack_unorm8(x[0][0][2]), pack_unorm8(x[0][0][1]), pack_unorm8(x[0][0][0]), pack_unorm8(x[0][0][3])) ],121 'b8g8r8a8-snorm': [ 45, 0, 'L', 32, 1, 1, lambda x: struct.pack("=BBBB", pack_snorm8(x[0][0][2]), pack_snorm8(x[0][0][1]), pack_snorm8(x[0][0][0]), pack_snorm8(x[0][0][3])) ],122 'b8g8r8a8-uscaled': [ 46, 0, 'L', 32, 1, 1, lambda x: struct.pack("=BBBB", pack_uint8(x[0][0][2]), pack_uint8(x[0][0][1]), pack_uint8(x[0][0][0]), pack_uint8(x[0][0][3])) ],123 'b8g8r8a8-sscaled': [ 47, 0, 'L', 32, 1, 1, lambda x: struct.pack("=BBBB", pack_sint8(x[0][0][2]), pack_sint8(x[0][0][1]), pack_sint8(x[0][0][0]), pack_sint8(x[0][0][3])) ],124 'b8g8r8a8-uint': [ 48, 0, 'L', 32, 1, 1, lambda x: struct.pack("=BBBB", pack_uint8(x[0][0][2]), pack_uint8(x[0][0][1]), pack_uint8(x[0][0][0]), pack_uint8(x[0][0][3])) ],125 'b8g8r8a8-sint': [ 49, 0, 'L', 32, 1, 1, lambda x: struct.pack("=BBBB", pack_sint8(x[0][0][2]), pack_sint8(x[0][0][1]), pack_sint8(x[0][0][0]), pack_sint8(x[0][0][3])) ],126 'b8g8r8a8-srgb': [ 50, 91, 'L', 32, 1, 1, lambda x: struct.pack("=BBBB", pack_unorm8(x[0][0][2]), pack_unorm8(x[0][0][1]), pack_unorm8(x[0][0][0]), pack_unorm8(x[0][0][3])) ],127 'a8b8g8r8-unorm': [ 51, 0, 'L', 32, 1, 1, lambda x: struct.pack("=BBBB", pack_unorm8(x[0][0][3]), pack_unorm8(x[0][0][2]), pack_unorm8(x[0][0][1]), pack_unorm8(x[0][0][0])) ],128 'a8b8g8r8-snorm': [ 52, 0, 'L', 32, 1, 1, lambda x: struct.pack("=BBBB", pack_snorm8(x[0][0][3]), pack_snorm8(x[0][0][2]), pack_snorm8(x[0][0][1]), pack_snorm8(x[0][0][0])) ],129 'a8b8g8r8-uscaled': [ 53, 0, 'L', 32, 1, 1, lambda x: struct.pack("=BBBB", pack_uint8(x[0][0][3]), pack_uint8(x[0][0][2]), pack_uint8(x[0][0][1]), pack_uint8(x[0][0][0])) ],130 'a8b8g8r8-sscaled': [ 54, 0, 'L', 32, 1, 1, lambda x: struct.pack("=BBBB", pack_sint8(x[0][0][3]), pack_sint8(x[0][0][2]), pack_sint8(x[0][0][1]), pack_sint8(x[0][0][0])) ],131 'a8b8g8r8-uint': [ 55, 0, 'L', 32, 1, 1, lambda x: struct.pack("=BBBB", pack_uint8(x[0][0][3]), pack_uint8(x[0][0][2]), pack_uint8(x[0][0][1]), pack_uint8(x[0][0][0])) ],132 'a8b8g8r8-sint': [ 56, 0, 'L', 32, 1, 1, lambda x: struct.pack("=BBBB", pack_sint8(x[0][0][3]), pack_sint8(x[0][0][2]), pack_sint8(x[0][0][1]), pack_sint8(x[0][0][0])) ],133 'a8b8g8r8-srgb': [ 57, 0, 'L', 32, 1, 1, lambda x: struct.pack("=BBBB", pack_unorm8(x[0][0][3]), pack_unorm8(x[0][0][2]), pack_unorm8(x[0][0][1]), pack_unorm8(x[0][0][0])) ],134 'a2r10g10b10-unorm': [ 58, 0, 'L', 32, 1, 1 ],135 'a2r10g10b10-snorm': [ 59, 0, 'L', 32, 1, 1 ],136 'a2r10g10b10-uscaled': [ 60, 0, 'L', 32, 1, 1 ],137 'a2r10g10b10-sscaled': [ 61, 0, 'L', 32, 1, 1 ],138 'a2r10g10b10-uint': [ 62, 0, 'L', 32, 1, 1 ],139 'a2r10g10b10-sint': [ 63, 0, 'L', 32, 1, 1 ],140 'a2b10g10r10-unorm': [ 64, 24, 'L', 32, 1, 1 ],141 'a2b10g10r10-snorm': [ 65, 0, 'L', 32, 1, 1 ],142 'a2b10g10r10-uscaled': [ 66, 0, 'L', 32, 1, 1 ],143 'a2b10g10r10-sscaled': [ 67, 0, 'L', 32, 1, 1 ],144 'a2b10g10r10-uint': [ 68, 25, 'L', 32, 1, 1 ],145 'a2b10g10r10-sint': [ 69, 0, 'L', 32, 1, 1 ],146 'r16-unorm': [ 70, 56, 'L', 16, 1, 1, lambda x: struct.pack("=H", pack_unorm16(x[0][0][0])) ],147 'r16-snorm': [ 71, 58, 'L', 16, 1, 1, lambda x: struct.pack("=H", pack_snorm16(x[0][0][0])) ],148 'r16-uscaled': [ 72, 0, 'L', 16, 1, 1, lambda x: struct.pack("=H", pack_uint16(x[0][0][0])) ],149 'r16-sscaled': [ 73, 0, 'L', 16, 1, 1, lambda x: struct.pack("=H", pack_sint16(x[0][0][0])) ],150 'r16-uint': [ 74, 57, 'L', 16, 1, 1, lambda x: struct.pack("=H", pack_uint16(x[0][0][0])) ],151 'r16-sint': [ 75, 59, 'L', 16, 1, 1, lambda x: struct.pack("=H", pack_sint16(x[0][0][0])) ],152 'r16-sfloat': [ 76, 54, 'L', 16, 1, 1, lambda x: struct.pack("=H", pack_fp16(x[0][0][0])) ],153 'r16g16-unorm': [ 77, 35, 'L', 32, 1, 1, lambda x: struct.pack("=HH", pack_unorm16(x[0][0][0]), pack_unorm16(x[0][0][1])) ],154 'r16g16-snorm': [ 78, 37, 'L', 32, 1, 1, lambda x: struct.pack("=HH", pack_snorm16(x[0][0][0]), pack_snorm16(x[0][0][1])) ],155 'r16g16-uscaled': [ 79, 0, 'L', 32, 1, 1, lambda x: struct.pack("=HH", pack_uint16(x[0][0][0]), pack_uint16(x[0][0][1])) ],156 'r16g16-sscaled': [ 80, 0, 'L', 32, 1, 1, lambda x: struct.pack("=HH", pack_sint16(x[0][0][0]), pack_sint16(x[0][0][1])) ],157 'r16g16-uint': [ 81, 36, 'L', 32, 1, 1, lambda x: struct.pack("=HH", pack_uint16(x[0][0][0]), pack_uint16(x[0][0][1])) ],158 'r16g16-sint': [ 82, 38, 'L', 32, 1, 1, lambda x: struct.pack("=HH", pack_sint16(x[0][0][0]), pack_sint16(x[0][0][1])) ],159 'r16g16-sfloat': [ 83, 34, 'L', 32, 1, 1, lambda x: struct.pack("=HH", pack_fp16(x[0][0][0]), pack_fp16(x[0][0][1])) ],160 'r16g16b16-unorm': [ 84, 0, 'L', 48, 1, 1, lambda x: struct.pack("=HHH", pack_unorm16(x[0][0][0]), pack_unorm16(x[0][0][1]), pack_unorm16(x[0][0][2])) ],161 'r16g16b16-snorm': [ 85, 0, 'L', 48, 1, 1, lambda x: struct.pack("=HHH", pack_snorm16(x[0][0][0]), pack_snorm16(x[0][0][1]), pack_snorm16(x[0][0][2])) ],162 'r16g16b16-uscaled': [ 86, 0, 'L', 48, 1, 1, lambda x: struct.pack("=HHH", pack_uint16(x[0][0][0]), pack_uint16(x[0][0][1]), pack_uint16(x[0][0][2])) ],163 'r16g16b16-sscaled': [ 87, 0, 'L', 48, 1, 1, lambda x: struct.pack("=HHH", pack_sint16(x[0][0][0]), pack_sint16(x[0][0][1]), pack_sint16(x[0][0][2])) ],164 'r16g16b16-uint': [ 88, 0, 'L', 48, 1, 1, lambda x: struct.pack("=HHH", pack_uint16(x[0][0][0]), pack_uint16(x[0][0][1]), pack_uint16(x[0][0][2])) ],165 'r16g16b16-sint': [ 89, 0, 'L', 48, 1, 1, lambda x: struct.pack("=HHH", pack_sint16(x[0][0][0]), pack_sint16(x[0][0][1]), pack_sint16(x[0][0][2])) ],166 'r16g16b16-sfloat': [ 90, 0, 'L', 48, 1, 1, lambda x: struct.pack("=HHH", pack_fp16(x[0][0][0]), pack_fp16(x[0][0][1]), pack_fp16(x[0][0][2])) ],167 'r16g16b16a16-unorm': [ 91, 11, 'L', 64, 1, 1, lambda x: struct.pack("=HHHH", pack_unorm16(x[0][0][0]), pack_unorm16(x[0][0][1]), pack_unorm16(x[0][0][2]), pack_unorm16(x[0][0][3])) ],168 'r16g16b16a16-snorm': [ 92, 13, 'L', 64, 1, 1, lambda x: struct.pack("=HHHH", pack_snorm16(x[0][0][0]), pack_snorm16(x[0][0][1]), pack_snorm16(x[0][0][2]), pack_snorm16(x[0][0][3])) ],169 'r16g16b16a16-uscaled': [ 93, 0, 'L', 64, 1, 1, lambda x: struct.pack("=HHHH", pack_uint16(x[0][0][0]), pack_uint16(x[0][0][1]), pack_uint16(x[0][0][2]), pack_uint16(x[0][0][3])) ],170 'r16g16b16a16-sscaled': [ 94, 0, 'L', 64, 1, 1, lambda x: struct.pack("=HHHH", pack_sint16(x[0][0][0]), pack_sint16(x[0][0][1]), pack_sint16(x[0][0][2]), pack_sint16(x[0][0][3])) ],171 'r16g16b16a16-uint': [ 95, 12, 'L', 64, 1, 1, lambda x: struct.pack("=HHHH", pack_uint16(x[0][0][0]), pack_uint16(x[0][0][1]), pack_uint16(x[0][0][2]), pack_uint16(x[0][0][3])) ],172 'r16g16b16a16-sint': [ 96, 14, 'L', 64, 1, 1, lambda x: struct.pack("=HHHH", pack_sint16(x[0][0][0]), pack_sint16(x[0][0][1]), pack_sint16(x[0][0][2]), pack_sint16(x[0][0][3])) ],173 'r16g16b16a16-sfloat': [ 97, 10, 'L', 64, 1, 1, lambda x: struct.pack("=HHHH", pack_fp16(x[0][0][0]), pack_fp16(x[0][0][1]), pack_fp16(x[0][0][2]), pack_fp16(x[0][0][3])) ],174 'r32-uint': [ 98, 42, 'L', 32, 1, 1, lambda x: struct.pack("=I", pack_uint32(x[0][0][0])) ],175 'r32-sint': [ 99, 43, 'L', 32, 1, 1, lambda x: struct.pack("=I", pack_sint32(x[0][0][0])) ],176 'r32-sfloat': [ 100, 41, 'L', 32, 1, 1, lambda x: struct.pack("=f", x[0][0][0]) ],177 'r32g32-uint': [ 101, 17, 'L', 64, 1, 1, lambda x: struct.pack("=II", pack_uint32(x[0][0][0]), pack_uint32(x[0][0][1])) ],178 'r32g32-sint': [ 102, 18, 'L', 64, 1, 1, lambda x: struct.pack("=II", pack_sint32(x[0][0][0]), pack_sint323(x[0][0][1])) ],179 'r32g32-sfloat': [ 103, 16, 'L', 64, 1, 1, lambda x: struct.pack("=ff", x[0][0][0], x[0][0][1]) ],180 'r32g32b32-uint': [ 104, 7, 'L', 96, 1, 1, lambda x: struct.pack("=III", pack_uint32(x[0][0][0]), pack_uint32(x[0][0][1]), pack_uint32(x[0][0][2])) ],181 'r32g32b32-sint': [ 105, 8, 'L', 96, 1, 1, lambda x: struct.pack("=III", pack_sint32(x[0][0][0]), pack_sint32(x[0][0][1]), pack_sint32(x[0][0][2])) ],182 'r32g32b32-sfloat': [ 106, 6, 'L', 96, 1, 1, lambda x: struct.pack("=fff", x[0][0][0], x[0][0][1], x[0][0][2]) ],183 'r32g32b32a32-uint': [ 106, 3, 'L', 128, 1, 1, lambda x: struct.pack("=IIII", pack_uint32(x[0][0][0]), pack_uint32(x[0][0][1]), pack_uint32(x[0][0][2]), pack_uint32(x[0][0][3])) ],184 'r32g32b32a32-sint': [ 108, 4, 'L', 128, 1, 1, lambda x: struct.pack("=IIII", pack_sint32(x[0][0][0]), pack_sint32(x[0][0][1]), pack_sint32(x[0][0][2]), pack_sint32(x[0][0][3])) ],185 'r32g32b32a32-sfloat': [ 109, 2, 'L', 128, 1, 1, lambda x: struct.pack("=ffff", x[0][0][0], x[0][0][1], x[0][0][2], x[0][0][3]) ],186 'r64-uint': [ 110, 0, 'L', 64, 1, 1, lambda x: struct.pack("=Q", pack_uint64(x[0][0][0])) ],187 'r64-sint': [ 111, 0, 'L', 64, 1, 1, lambda x: struct.pack("=Q", pack_sint64(x[0][0][0])) ],188 'r64-sfloat': [ 112, 0, 'L', 64, 1, 1, lambda x: struct.pack("=d", x[0][0][0]) ],189 'r64g64-uint': [ 113, 0, 'L', 128, 1, 1, lambda x: struct.pack("=QQ", pack_uint64(x[0][0][0]), pack_uint64(x[0][0][1])) ],190 'r64g64-sint': [ 114, 0, 'L', 128, 1, 1, lambda x: struct.pack("=QQ", pack_sint64(x[0][0][0]), pack_sint64(x[0][0][1])) ],191 'r64g64-sfloat': [ 115, 0, 'L', 128, 1, 1, lambda x: struct.pack("=dd", x[0][0][0], x[0][0][1]) ],192 'r64g64b64-uint': [ 116, 0, 'L', 192, 1, 1, lambda x: struct.pack("=QQQ", pack_uint64(x[0][0][0]), pack_uint64(x[0][0][1]), pack_uint64(x[0][0][2])) ],193 'r64g64b64-sint': [ 117, 0, 'L', 192, 1, 1, lambda x: struct.pack("=QQQ", pack_sint64(x[0][0][0]), pack_sint64(x[0][0][1]), pack_sint64(x[0][0][2])) ],194 'r64g64b64-sfloat': [ 118, 0, 'L', 192, 1, 1, lambda x: struct.pack("=ddd", x[0][0][0], x[0][0][1], x[0][0][2]) ],195 'r64g64b64a64-uint': [ 119, 0, 'L', 256, 1, 1, lambda x: struct.pack("=QQQQ", pack_uint64(x[0][0][0]), pack_uint64(x[0][0][1]), pack_uint64(x[0][0][2]), pack_uint64(x[0][0][3])) ],196 'r64g64b64a64-sint': [ 120, 0, 'L', 256, 1, 1, lambda x: struct.pack("=QQQQ", pack_sint64(x[0][0][0]), pack_sint64(x[0][0][1]), pack_sint64(x[0][0][2]), pack_sint64(x[0][0][3])) ],197 'r64g64b64a64-sfloat': [ 121, 0, 'L', 256, 1, 1, lambda x: struct.pack("=dddd", x[0][0][0], x[0][0][1], x[0][0][2], x[0][0][3]) ],198 'b10g11r11-ufloat': [ 122, 26, 'L', 32, 1, 1 ],199# 'e5b9g9r9-ufloat':200# 'bc1-rgb-unorm':201# 'bc1-rgb-srgb':202# 'bc1-rgba-unorm':203# 'bc1-rgba-srgb':204# 'bc2-unorm':205# 'bc2-srgb':206# 'bc3-unorm':207# 'bc3-srgb':208# 'bc4-unorm':209# 'bc4-snorm':210# 'bc5-unorm':211# 'bc5-snorm':212# 'bc6h-ufloat':213# 'bc6h-sfloat':214# 'bc7-unorm':215# 'bc7-srgb':216# 'etc2-r8g8b8-unorm':217# 'etc2-r8g8b8-srgb':218# 'etc2-r8g8b8a1-unorm':219# 'etc2-r8g8b8a1-srgb':220# 'etc2-r8g8b8a8-unorm':221# 'etc2-r8g8b8a8-srgb':222# 'eac-r11-unorm':223# 'eac-r11-snorm':224# 'eac-r11g11-unorm':225# 'eac-r11g11-snorm':226# 'astc-4x4-unorm':227# 'astc-4x4-srgb':228# 'astc-5x4-unorm':229# 'astc-5x4-srgb':230# 'astc-5x5-unorm':231# 'astc-5x5-srgb':232# 'astc-6x5-unorm':233# 'astc-6x5-srgb':234# 'astc-6x6-unorm':235# 'astc-6x6-srgb':236# 'astc-8x5-unorm':237# 'astc-8x5-srgb':238# 'astc-8x6-unorm':239# 'astc-8x6-srgb':240# 'astc-8x8-unorm':241# 'astc-8x8-srgb':242# 'astc-10x5-unorm':243# 'astc-10x5-srgb':244# 'astc-10x6-unorm':245# 'astc-10x6-srgb':246# 'astc-10x8-unorm':247# 'astc-10x8-srgb':248# 'astc-10x10-unorm':249# 'astc-10x10-srgb':250# 'astc-12x10-unorm':251# 'astc-12x10-srgb':252# 'astc-12x12-unorm':253# 'astc-12x12-srgb':254}255def perror(str):256 sys.stderr.write("textool: ")257 sys.stderr.write(str)258 sys.stderr.write("\n")259 sys.stderr.flush()260 sys.exit(1)261def pwarn(str):262 sys.stderr.write("textool: ")263 sys.stderr.write(str)264 sys.stderr.write("\n")265 sys.stderr.flush()266def parse_command_line():267 argp = argparse.ArgumentParser(description="Process and compress textures")268 argp.add_argument('-m', '--merge', action='store_true', help='Combine textures into one single file')269 argp.add_argument('-c', '--cubemap', action='store_true', help='Create cubemap, implies merge')270 argp.add_argument('-g', '--generate-mipmaps', action='store_true', help='Generate mipmaps')271 argp.add_argument('-l', '--list-formats', action='store_true', help='List supported formats, then exit')272 argp.add_argument('-f', '--format' , action='store', type=str, help='Select output format (r16g16b16a16-sfloat)')273 argp.add_argument('-S', '--reshape', action='store', type=str, help='Reshape image to w:h:d:l')274 argp.add_argument('-s', '--scale', action='store', type=str, help='Multiply all pixels by r:g:b:a')275 argp.add_argument('-b', '--bias', action='store', type=str, help='Add r:g:b:a to all pixels')276 argp.add_argument('-o', '--output', action='store', type=str, help='Output file ({input}.dds)')277 argp.add_argument('-C', '--directory', action='store', type=str, help='Set working directory')278 argp.add_argument('images', nargs=argparse.REMAINDER)279 argv = argp.parse_args()280 if not argv.format:281 argv.format = 'r16g16b16a16-sfloat'282 if not argv.directory:283 argv.directory = ""284 if not argv.output:285 argv.output = "{input}.dds"286 if not argv.list_formats and len(argv.images) < 1:287 perror("No input files specified")288 return argv289def image_load(images):290 for image in images:291 pwarn("Processing %s..." % image)292 img = Image.open(image)293 img.load()294 pixels = np.asarray(img, dtype='float32')295 channels = pixels.shape[2] if len(pixels.shape) > 2 else 1296 pixels = pixels.reshape((pixels.shape[0], pixels.shape[1], 1, 1, channels))297 if channels < 4:298 pixels = np.pad(pixels, ((0,0),(0,0),(0,0),(0,0),(0, 4 - channels)), mode='constant', constant_values=0)299 if img.mode != 'F':300 pixels /= 255.0301 yield image, pixels302def image_load_combined(images):303 return []304def image_resize_half(pixels):305 return pixels306def image_convert(pixels, fmt, mipmaps):307 data = []308 for l in xrange(pixels.shape[3]):309 slice = ""310 for z in xrange(pixels.shape[2]):311 for y in xrange(0, pixels.shape[1], fmt[PF_BLKH]):312 for x in xrange(0, pixels.shape[0], fmt[PF_BLKW]):313 slice += fmt[PF_FUNC](pixels[y:y+fmt[PF_BLKH],x:x+fmt[PF_BLKW],z,l,:])314 data.append([ slice ])315 return data316def dds_write(output, pixels, shape, fmt, cubemap):317 pwarn("Writing to '%s'..." % output)318 try:319 out = open(output, 'wb')320 except:321 perror("Failed to open output file!")322 flags = 0x1007 # DDS_CAPS, DDS_WIDTH, DDS_HEIGHT, DDS_PF323 caps0 = 0x00001008 # DDSCAPS_COMPLEX, DDSCAPS_TEXTURE324 caps1 = 0325 flags10 = 0326 dims = 2327 mipmaps = len(pixels[0])328 if fmt[PF_PACKING] == 'L': pitch = int((shape[1] * fmt[PF_BPP] + 7) / 8)329 if fmt[PF_PACKING] == 'B': pitch = max(int((shape[1] + 3) / 4), 1) * fmt[PF_BPP]330 if pitch > 0: flags |= 0x8 # DDS_PITCH331 if mipmaps > 1: flags |= 0x20000 # DDS_MIPMAPCOUNT332 if shape[2] > 1: flags |= 0x800000 # DDS_DEPTH333 if mipmaps > 1: caps0 |= 0x400000 # DDSCAPS_MIPMAP334 if cubemap: caps1 |= 0xfe00 # DDSCAPS2_CUBEMAP, DDSCAPS2_CUBEMAP_ALL_FACES335 if cubemap: flags10 |= 0x4 # DDS_RESOURCE_MISC_TEXTURECUBE336 if shape[0] > 1: dims = 3337 if shape[2] > 1: dims = 4338 out.write(struct.pack("=I II IIII I IIII IIII III III I IIII IIII I II III",339 0x20534444, 124, flags, # magic, size, flags340 shape[1], shape[0], pitch, shape[2], mipmaps, # width, height, pitch, depth, mipmaps341 0,0,0,0, 0,0,0,0, 0,0,0, # reserved[11]342 32, 0x04, 0x30315844, 0, 0, 0, 0, 0, # pf_size, flags:FOURCC, fourcc:DX10, bits, rmask, gmask, bmask, amask343 caps0, caps1, 0, 0, 0, # caps0, caps1, caps2, caps3, reserved344 fmt[PF_DXGI], dims, flags10, shape[3], 0)) # dx10_fmt, dimensions, flags, array_count, reserved345 for image in pixels:346 for mipmap in image:347 out.write(mipmap)348 out.close()349np.set_printoptions(threshold=np.nan)350argv = parse_command_line()351if argv.list_formats:352 pwarn("Supported formats:")...

Full Screen

Full Screen

db distinct.py

Source:db distinct.py Github

copy

Full Screen

1import rethinkdb as r2import json3from datetime import datetime, tzinfo4conn = r.connect()5conn.use("ygo")6# pack list before processing7# packnames = [8# {"pack": 'Absolute Powerforce', "release": datetime.strptime("02, 16, 2010", '%m, %d, %Y'), "shortname": "TAEV"},9# {"pack": 'Abyss Rising', "release": datetime.strptime("11, 9, 2012", '%m, %d, %Y'), "shortname": "TAEV"},10# {"pack": 'Ancient Prophecy', "release": datetime.strptime("09, 1, 2009", '%m, %d, %Y'), "shortname": "TAEV"},11# {"pack": 'Ancient Sanctuary', "release": datetime.strptime("06, 1, 2004", '%m, %d, %Y'), "shortname": "TAEV"},12# {"pack": 'Battles of Legend: Light\'s Revenge', "release": datetime.strptime("07, 7, 2017", '%m, %d, %Y'), "shortname": "TAEV"},13# {"pack": 'Battles of Legend: Relentless Revenge', "release": datetime.strptime("06, 29, 2018", '%m, %d, %Y'), "shortname": "TAEV"},14# {"pack": 'Breakers of Shadow', "release": datetime.strptime("1, 15, 2016", '%m, %d, %Y'), "shortname": "TAEV"},15# {"pack": 'Circuit Break', "release": datetime.strptime("10, 20, 2017", '%m, %d, %Y'), "shortname": "TAEV"},16# {"pack": 'Clash of Rebellions', "release": datetime.strptime("08, 7, 2015", '%m, %d, %Y'), "shortname": "TAEV"},17# {"pack": 'Code of the Duelist', "release": datetime.strptime("08, 4, 2017", '%m, %d, %Y'), "shortname": "TAEV"},18# {"pack": 'Cosmo Blazer', "release": datetime.strptime("1, 25, 2013", '%m, %d, %Y'), "shortname": "TAEV"},19# {"pack": 'Crimson Crisis', "release": datetime.strptime("03, 3, 2009", '%m, %d, %Y'), "shortname": "TAEV"},20# {"pack": 'Crossed Souls', "release": datetime.strptime("05, 15, 2015", '%m, %d, %Y'), "shortname": "TAEV"},21# {"pack": 'Crossroads of Chaos', "release": datetime.strptime("11, 18, 2008", '%m, %d, %Y'), "shortname": "TAEV"},22# {"pack": 'Cyberdark Impact', "release": datetime.strptime("11, 15, 2006", '%m, %d, %Y'), "shortname": "TAEV"},23# {"pack": 'Cybernetic Horizon', "release": datetime.strptime("07, 27, 2018", '%m, %d, %Y'), "shortname": "TAEV"},24# {"pack": 'Cybernetic Revolution', "release": datetime.strptime("08, 17, 2005", '%m, %d, %Y'), "shortname": "TAEV"},25# {"pack": 'Dark Beginning 1', "release": datetime.strptime("10, 12, 2004", '%m, %d, %Y'), "shortname": "TAEV"},26# {"pack": 'Dark Beginning 2', "release": datetime.strptime("07, 27, 2005", '%m, %d, %Y'), "shortname": "TAEV"},27# {"pack": 'Dark Crisis', "release": datetime.strptime("12, 1, 2003", '%m, %d, %Y'), "shortname": "TAEV"},28# {"pack": 'Dark Legends', "release": datetime.strptime("11, 21, 2008", '%m, %d, %Y'), "shortname": "TAEV"},29# {"pack": 'Dark Revelation Volume 4', "release": datetime.strptime("11, 14, 2007", '%m, %d, %Y'), "shortname": "TAEV"},30# {"pack": 'Dark Saviors', "release": datetime.strptime("05, 25, 2018", '%m, %d, %Y'), "shortname": "TAEV"},31# {"pack": 'Destiny Soldiers', "release": datetime.strptime("11, 18, 2016", '%m, %d, %Y'), "shortname": "TAEV"},32# {"pack": 'Dimension of Chaos', "release": datetime.strptime("11, 6, 2015", '%m, %d, %Y'), "shortname": "TAEV"},33# {"pack": 'Dragons of Legend', "release": datetime.strptime("04, 25, 2014", '%m, %d, %Y'), "shortname": "TAEV"},34# {"pack": 'Dragons of Legend 2', "release": datetime.strptime("1, 1, 2012", '%m, %d, %Y'), "shortname": "TAEV"},35# {"pack": 'Duelist Alliance', "release": datetime.strptime("08, 15, 2014", '%m, %d, %Y'), "shortname": "TAEV"},36# {"pack": 'Duelist Revolution', "release": datetime.strptime("08, 17, 2010", '%m, %d, %Y'), "shortname": "TAEV"},37# {"pack": 'Elemental Energy', "release": datetime.strptime("11, 16, 2005", '%m, %d, %Y'), "shortname": "TAEV"},38# {"pack": 'Enemy of Justice', "release": datetime.strptime("05, 17, 2006", '%m, %d, %Y'), "shortname": "TAEV"},39# {"pack": 'Exclusive Pack', "release": datetime.strptime("08, 1, 2004", '%m, %d, %Y'), "shortname": "TAEV"},40# {"pack": 'Extreme Force', "release": datetime.strptime("02, 2, 2018", '%m, %d, %Y'), "shortname": "TAEV"},41# {"pack": 'Extreme Victory', "release": datetime.strptime("05, 10, 2011", '%m, %d, %Y'), "shortname": "TAEV"},42# {"pack": 'Flames of Destruction', "release": datetime.strptime("05, 4, 2018", '%m, %d, %Y'), "shortname": "TAEV"},43# {"pack": 'Flaming Eternity', "release": datetime.strptime("03, 1, 2005", '%m, %d, %Y'), "shortname": "TAEV"},44# {"pack": 'Force of the Breaker', "release": datetime.strptime("05, 16, 2007", '%m, %d, %Y'), "shortname": "TAEV"},45# {"pack": 'Fusion Enforcers', "release": datetime.strptime("02, 24, 2017", '%m, %d, %Y'), "shortname": "TAEV"},46# {"pack": 'Galactic Overlord', "release": datetime.strptime("05, 8, 2012", '%m, %d, %Y'), "shortname": "TAEV"},47# {"pack": 'Generation Force', "release": datetime.strptime("08, 16, 2011", '%m, %d, %Y'), "shortname": "TAEV"},48# {"pack": 'Gladiator\'s Assault', "release": datetime.strptime("11, 14, 2007", '%m, %d, %Y'), "shortname": "TAEV"},49# {"pack": 'Hidden Arsenal', "release": datetime.strptime("11, 10, 2009", '%m, %d, %Y'), "shortname": "TAEV"},50# {"pack": 'Hidden Arsenal 2', "release": datetime.strptime("07, 20, 2010", '%m, %d, %Y'), "shortname": "TAEV"},51# {"pack": 'Hidden Arsenal 3', "release": datetime.strptime("12, 7, 2010", '%m, %d, %Y'), "shortname": "TAEV"},52# {"pack": 'Hidden Arsenal 4: Trishula\'s Triumph', "release": datetime.strptime("04, 19, 2011", '%m, %d, %Y'), "shortname": "TAEV"},53# {"pack": 'High-Speed Riders', "release": datetime.strptime("10, 2, 2015", '%m, %d, %Y'), "shortname": "TAEV"},54# {"pack": 'Invasion of Chaos', "release": datetime.strptime("03, 1, 2004", '%m, %d, %Y'), "shortname": "TAEV"},55# {"pack": 'Invasion: Vengeance', "release": datetime.strptime("11, 4, 2016", '%m, %d, %Y'), "shortname": "TAEV"},56# {"pack": 'Judgment of the Light', "release": datetime.strptime("08, 9, 2013", '%m, %d, %Y'), "shortname": "TAEV"},57# {"pack": 'Labyrinth of Nightmare', "release": datetime.strptime("03, 1, 2003", '%m, %d, %Y'), "shortname": "TAEV"},58# {"pack": 'Legacy of Darkness', "release": datetime.strptime("06, 6, 2003", '%m, %d, %Y'), "shortname": "TAEV"},59# {"pack": 'Legend of Blue Eyes White Dragon', "release": datetime.strptime("12, 1, 2004", '%m, %d, %Y'), "shortname": "TAEV"},60# {"pack": 'Legendary Duelists', "release": datetime.strptime("09, 8, 2017", '%m, %d, %Y'), "shortname": "TAEV"},61# {"pack": 'Legendary Duelists: Ancient Millennium', "release": datetime.strptime("02, 23, 2018", '%m, %d, %Y'), "shortname": "TAEV"},62# {"pack": 'Legendary Duelists: White Dragon Abyss', "release": datetime.strptime("09, 28, 2018", '%m, %d, %Y'), "shortname": "TAEV"},63# {"pack": 'Light of Destruction', "release": datetime.strptime("05, 13, 2008", '%m, %d, %Y'), "shortname": "TAEV"},64# {"pack": 'Lord of the Tachyon Galaxy', "release": datetime.strptime("05, 17, 2013", '%m, %d, %Y'), "shortname": "TAEV"},65# {"pack": 'Magician\'s Force', "release": datetime.strptime("10, 10, 2003", '%m, %d, %Y'), "shortname": "TAEV"},66# {"pack": 'Maximum Crisis', "release": datetime.strptime("05, 5, 2017", '%m, %d, %Y'), "shortname": "TAEV"},67# {"pack": 'Metal Raiders', "release": datetime.strptime("06, 26, 2002", '%m, %d, %Y'), "shortname": "TAEV"},68# {"pack": 'Movie Pack', "release": datetime.strptime("08, 13, 2004", '%m, %d, %Y'), "shortname": "TAEV"},69# {"pack": 'Number Hunters', "release": datetime.strptime("07, 12, 2013", '%m, %d, %Y'), "shortname": "TAEV"},70# {"pack": 'Order of Chaos', "release": datetime.strptime("1, 24, 2012", '%m, %d, %Y'), "shortname": "TAEV"},71# {"pack": 'Pendulum Evolution', "release": datetime.strptime("06, 23, 2017", '%m, %d, %Y'), "shortname": "TAEV"},72# {"pack": 'Phantom Darkness', "release": datetime.strptime("02, 13, 2008", '%m, %d, %Y'), "shortname": "TAEV"},73# {"pack": 'Pharaoh\'s Servant', "release": datetime.strptime("10, 20, 2002", "%m, %d, %Y"), "shortname": "TAEV"},74# {"pack": 'Pharaonic Guardian', "release": datetime.strptime("07, 18, 2003", '%m, %d, %Y'), "shortname": "TAEV"},75# {"pack": 'Photon Shockwave', "release": datetime.strptime("11, 15, 2011", '%m, %d, %Y'), "shortname": "TAEV"},76# {"pack": 'Primal Origin', "release": datetime.strptime("05, 16, 2014", '%m, %d, %Y'), "shortname": "TAEV"},77# {"pack": 'Raging Battle', "release": datetime.strptime("05, 12, 2009", '%m, %d, %Y'), "shortname": "TAEV"},78# {"pack": 'Raging Tempest', "release": datetime.strptime("02, 10, 2017", '%m, %d, %Y'), "shortname": "TAEV"},79# {"pack": 'Return of the Duelist', "release": datetime.strptime("08, 28, 2012", '%m, %d, %Y'), "shortname": "TAEV"},80# {"pack": 'Rise of Destiny', "release": datetime.strptime("12, 1, 2004", '%m, %d, %Y'), "shortname": "TAEV"},81# {"pack": 'Secrets of Eternity', "release": datetime.strptime("1, 16, 2015", '%m, %d, %Y'), "shortname": "TAEV"},82# {"pack": 'Shadow of Infinity', "release": datetime.strptime("02, 18, 2006", '%m, %d, %Y'), "shortname": "TAEV"},83# {"pack": 'Shadow Specters', "release": datetime.strptime("11, 8, 2013", '%m, %d, %Y'), "shortname": "TAEV"},84# {"pack": 'Shadows in Valhalla', "release": datetime.strptime("08, 17, 2018", '%m, %d, %Y'), "shortname": "TAEV"},85# {"pack": 'Shining Victories', "release": datetime.strptime("05, 6, 2016", '%m, %d, %Y'), "shortname": "TAEV"},86# {"pack": 'Soul Fusion', "release": datetime.strptime("10, 19, 2018", '%m, %d, %Y'), "shortname": "TAEV"},87# {"pack": 'Soul of the Duelist', "release": datetime.strptime("10, 1, 2004", '%m, %d, %Y'), "shortname": "TAEV"},88# {"pack": 'Spell Ruler', "release": datetime.strptime("09, 16, 2002", "%m, %d, %Y"), "shortname": "TAEV"},89# {"pack": 'Spirit Warriors', "release": datetime.strptime("11, 17, 2017", '%m, %d, %Y'), "shortname": "TAEV"},90# {"pack": 'Stardust Overdrive', "release": datetime.strptime("11, 17, 2009", '%m, %d, %Y'), "shortname": "TAEV"},91# {"pack": 'Starstrike Blast', "release": datetime.strptime("11, 16, 2010", '%m, %d, %Y'), "shortname": "TAEV"},92# {"pack": 'Storm of Ragnarok', "release": datetime.strptime("02, 8, 2011", '%m, %d, %Y'), "shortname": "TAEV"},93# {"pack": 'Strike of Neos', "release": datetime.strptime("02, 28, 2007", '%m, %d, %Y'), "shortname": "TAEV"},94# {"pack": 'Tactical Evolution', "release": datetime.strptime("08, 15, 2007", '%m, %d, %Y'), "shortname": "TAEV"},95# {"pack": 'The Dark Illusion', "release": datetime.strptime("08, 5, 2016", '%m, %d, %Y'), "shortname": "TAEV"},96# {"pack": 'The Duelist Genesis', "release": datetime.strptime("09, 2, 2008", '%m, %d, %Y'), "shortname": "TAEV"},97# {"pack": 'The Lost Millennium', "release": datetime.strptime("06, 1, 2005", '%m, %d, %Y'), "shortname": "TAEV"},98# {"pack": 'The New Challengers', "release": datetime.strptime("11, 7, 2014", '%m, %d, %Y'), "shortname": "TAEV"},99# {"pack": 'The Shining Darkness', "release": datetime.strptime("05, 11, 2010", '%m, %d, %Y'), "shortname": "TAEV"},100# {"pack": 'War of the Giants: Round 2', "release": datetime.strptime("1, 17, 2014", '%m, %d, %Y'), "shortname": "TAEV"},101# {"pack": 'Wing Raiders', "release": datetime.strptime("02, 12, 2016", '%m, %d, %Y'), "shortname": "TAEV"},102# {"pack": 'World Superstars', "release": datetime.strptime("04, 17, 2015", '%m, %d, %Y'), "shortname": "TAEV"}]103# grabs shortnames from abbrv file104# y = ""105# file = open("packAbbrv")106# for line in file:107# for x, value in enumerate(packnames):108# if packnames[x]["pack"] == line.strip():109# y = line.strip()110# elif y == packnames[x]["pack"]:111# packnames[x]["shortname"] = line.strip()112# print("%s," % (packnames[x]))113# y = ""114# insert packs into packlist115# time = r.make_timezone("-06:00")116#117# packnames = [118# {'pack': 'Absolute Powerforce', 'shortname': 'ABPF', 'release': datetime(2010, 2, 16, 0, 0, 0, 0, time)},119# {'pack': 'Abyss Rising', 'shortname': 'ABYR', 'release': datetime(2012, 11, 9, 0, 0, 0, 0, time)},120# {'pack': 'Ancient Prophecy', 'shortname': 'ANPR', 'release': datetime(2009, 9, 1, 0, 0, 0, 0, time)},121# {'pack': 'Ancient Sanctuary', 'shortname': 'AST', 'release': datetime(2004, 6, 1, 0, 0, 0, 0, time)},122# {'pack': "Battles of Legend: Light's Revenge", 'shortname': 'BLLR', 'release': datetime(2017, 7, 7, 0, 0, 0, 0, time)},123# {'pack': 'Battles of Legend: Relentless Revenge', 'shortname': 'BLRR', 'release': datetime(2018, 6, 29, 0, 0, 0, 0, time)},124# {'pack': 'Breakers of Shadow', 'shortname': 'BOSH', 'release': datetime(2016, 1, 15, 0, 0, 0, 0, time)},125# {'pack': 'Circuit Break', 'shortname': 'CIBR', 'release': datetime(2017, 10, 20, 0, 0, 0, 0, time)},126# {'pack': 'Clash of Rebellions', 'shortname': 'CORE', 'release': datetime(2015, 8, 7, 0, 0, 0, 0, time)},127# {'pack': 'Code of the Duelist', 'shortname': 'COTD', 'release': datetime(2017, 8, 4, 0, 0, 0, 0, time)},128# {'pack': 'Cosmo Blazer', 'shortname': 'CBLZ', 'release': datetime(2013, 1, 25, 0, 0, 0, 0, time)},129# {'pack': 'Crimson Crisis', 'shortname': 'CRMS', 'release': datetime(2009, 3, 3, 0, 0, 0, 0, time)},130# {'pack': 'Crossed Souls', 'shortname': 'CROS', 'release': datetime(2015, 5, 15, 0, 0, 0, 0, time)},131# {'pack': 'Crossroads of Chaos', 'shortname': 'CSOC', 'release': datetime(2008, 11, 18, 0, 0, 0, 0, time)},132# {'pack': 'Cyberdark Impact', 'shortname': 'CDIP', 'release': datetime(2006, 11, 15, 0, 0, 0, 0, time)},133# {'pack': 'Cybernetic Horizon', 'shortname': 'CYHO', 'release': datetime(2018, 7, 27, 0, 0, 0, 0, time)},134# {'pack': 'Cybernetic Revolution', 'shortname': 'CRV', 'release': datetime(2005, 8, 17, 0, 0, 0, 0, time)},135# {'pack': 'Dark Beginning 1', 'shortname': 'DB1', 'release': datetime(2004, 10, 12, 0, 0, 0, 0, time)},136# {'pack': 'Dark Beginning 2', 'shortname': 'DB2', 'release': datetime(2005, 7, 27, 0, 0, 0, 0, time)},137# {'pack': 'Dark Crisis', 'shortname': 'DCR', 'release': datetime(2003, 12, 1, 0, 0, 0, 0, time)},138# {'pack': 'Dark Legends', 'shortname': 'DLG1', 'release': datetime(2008, 11, 21, 0, 0, 0, 0, time)},139# {'pack': 'Dark Revelation Volume 4', 'shortname': 'DR04', 'release': datetime(2007, 11, 14, 0, 0, 0, 0, time)},140# {'pack': 'Dark Saviors', 'shortname': 'DASA', 'release': datetime(2018, 5, 25, 0, 0, 0, 0, time)},141# {'pack': 'Destiny Soldiers', 'shortname': 'DESO', 'release': datetime(2016, 11, 18, 0, 0, 0, 0, time)},142# {'pack': 'Dimension of Chaos', 'shortname': 'DOCS', 'release': datetime(2015, 11, 6, 0, 0, 0, 0, time)},143# {'pack': 'Dragons of Legend', 'shortname': 'DRLG', 'release': datetime(2014, 4, 25, 0, 0, 0, 0, time)},144# {'pack': 'Dragons of Legend 2', 'shortname': 'DRL2', 'release': datetime(2012, 1, 1, 0, 0, 0, 0, time)},145# {'pack': 'Duelist Alliance', 'shortname': 'DUEA', 'release': datetime(2014, 8, 15, 0, 0, 0, 0, time)},146# {'pack': 'Duelist Revolution', 'shortname': 'DREV', 'release': datetime(2010, 8, 17, 0, 0, 0, 0, time)},147# {'pack': 'Elemental Energy', 'shortname': 'EEN', 'release': datetime(2005, 11, 16, 0, 0, 0, 0, time)},148# {'pack': 'Enemy of Justice', 'shortname': 'EOJ', 'release': datetime(2006, 5, 17, 0, 0, 0, 0, time)},149# {'pack': 'Exclusive Pack', 'shortname': 'EP1', 'release': datetime(2004, 8, 1, 0, 0, 0, 0, time)},150# {'pack': 'Extreme Force', 'shortname': 'EXFO', 'release': datetime(2018, 2, 2, 0, 0, 0, 0, time)},151# {'pack': 'Extreme Victory', 'shortname': 'EXVC', 'release': datetime(2011, 5, 10, 0, 0, 0, 0, time)},152# {'pack': 'Flames of Destruction', 'shortname': 'FLOD', 'release': datetime(2018, 5, 4, 0, 0, 0, 0, time)},153# {'pack': 'Flaming Eternity', 'shortname': 'FET', 'release': datetime(2005, 3, 1, 0, 0, 0, 0, time)},154# {'pack': 'Force of the Breaker', 'shortname': 'FOTB', 'release': datetime(2007, 5, 16, 0, 0, 0, 0, time)},155# {'pack': 'Fusion Enforcers', 'shortname': 'FUEN', 'release': datetime(2017, 2, 24, 0, 0, 0, 0, time)},156# {'pack': 'Galactic Overlord', 'shortname': 'GAOV', 'release': datetime(2012, 5, 8, 0, 0, 0, 0, time)},157# {'pack': 'Generation Force', 'shortname': 'GENF', 'release': datetime(2011, 8, 16, 0, 0, 0, 0, time)},158# {'pack': "Gladiator's Assault", 'shortname': 'GLAS', 'release': datetime(2007, 11, 14, 0, 0, 0, 0, time)},159# {'pack': 'Hidden Arsenal', 'shortname': 'HA01', 'release': datetime(2009, 11, 10, 0, 0, 0, 0, time)},160# {'pack': 'Hidden Arsenal 2', 'shortname': 'HA02', 'release': datetime(2010, 7, 20, 0, 0, 0, 0, time)},161# {'pack': 'Hidden Arsenal 3', 'shortname': 'HA03', 'release': datetime(2010, 12, 7, 0, 0, 0, 0, time)},162# {'pack': "Hidden Arsenal 4: Trishula's Triumph", 'shortname': 'HA04', 'release': datetime(2011, 4, 19, 0, 0, 0, 0, time)},163# {'pack': 'High-Speed Riders', 'shortname': 'HSRD', 'release': datetime(2015, 10, 2, 0, 0, 0, 0, time)},164# {'pack': 'Invasion of Chaos', 'shortname': 'IOC', 'release': datetime(2004, 3, 1, 0, 0, 0, 0, time)},165# {'pack': 'Invasion: Vengeance', 'shortname': 'INOV', 'release': datetime(2016, 11, 4, 0, 0, 0, 0, time)},166# {'pack': 'Judgment of the Light', 'shortname': 'JOTL', 'release': datetime(2013, 8, 9, 0, 0, 0, 0, time)},167# {'pack': 'Labyrinth of Nightmare', 'shortname': 'LON', 'release': datetime(2003, 3, 1, 0, 0, 0, 0, time)},168# {'pack': 'Legacy of Darkness', 'shortname': 'LOD', 'release': datetime(2003, 6, 6, 0, 0, 0, 0, time)},169# {'pack': 'Legend of Blue Eyes White Dragon', 'shortname': 'LOB', 'release': datetime(2004, 12, 1, 0, 0, 0, 0, time)},170# {'pack': 'Legendary Duelists', 'shortname': 'LEDU', 'release': datetime(2017, 9, 8, 0, 0, 0, 0, time)},171# {'pack': 'Legendary Duelists: Ancient Millennium', 'shortname': 'LED2', 'release': datetime(2018, 2, 23, 0, 0, 0, 0, time)},172# {'pack': 'Legendary Duelists: White Dragon Abyss', 'shortname': 'LED3', 'release': datetime(2018, 9, 28, 0, 0, 0, 0, time)},173# {'pack': 'Light of Destruction', 'shortname': 'LODT', 'release': datetime(2008, 5, 13, 0, 0, 0, 0, time)},174# {'pack': 'Lord of the Tachyon Galaxy', 'shortname': 'LTGY', 'release': datetime(2013, 5, 17, 0, 0, 0, 0, time)},175# {'pack': "Magician's Force", 'shortname': 'MFC', 'release': datetime(2003, 10, 10, 0, 0, 0, 0, time)},176# {'pack': 'Maximum Crisis', 'shortname': 'MACR', 'release': datetime(2017, 5, 5, 0, 0, 0, 0, time)},177# {'pack': 'Metal Raiders', 'shortname': 'MRD', 'release': datetime(2002, 6, 26, 0, 0, 0, 0, time)},178# {'pack': 'Movie Pack', 'shortname': 'MOV', 'release': datetime(2004, 8, 13, 0, 0, 0, 0, time)},179# {'pack': 'Number Hunters', 'shortname': 'NUMH', 'release': datetime(2013, 7, 12, 0, 0, 0, 0, time)},180# {'pack': 'Order of Chaos', 'shortname': 'ORCS', 'release': datetime(2012, 1, 24, 0, 0, 0, 0, time)},181# {'pack': 'Pendulum Evolution', 'shortname': 'PEVO', 'release': datetime(2017, 6, 23, 0, 0, 0, 0, time)},182# {'pack': 'Phantom Darkness', 'shortname': 'PTDN', 'release': datetime(2008, 2, 13, 0, 0, 0, 0, time)},183# {'pack': "Pharaoh's Servant", 'shortname': 'PSV', 'release': datetime(2002, 10, 20, 0, 0, 0, 0, time)},184# {'pack': 'Pharaonic Guardian', 'shortname': 'PGD', 'release': datetime(2003, 7, 18, 0, 0, 0, 0, time)},185# {'pack': 'Photon Shockwave', 'shortname': 'PHSW', 'release': datetime(2011, 11, 15, 0, 0, 0, 0, time)},186# {'pack': 'Primal Origin', 'shortname': 'PRIO', 'release': datetime(2014, 5, 16, 0, 0, 0, 0, time)},187# {'pack': 'Raging Battle', 'shortname': 'RGBT', 'release': datetime(2009, 5, 12, 0, 0, 0, 0, time)},188# {'pack': 'Raging Tempest', 'shortname': 'RATE', 'release': datetime(2017, 2, 10, 0, 0, 0, 0, time)},189# {'pack': 'Return of the Duelist', 'shortname': 'REDU', 'release': datetime(2012, 8, 28, 0, 0, 0, 0, time)},190# {'pack': 'Rise of Destiny', 'shortname': 'RDS', 'release': datetime(2004, 12, 1, 0, 0, 0, 0, time)},191# {'pack': 'Secrets of Eternity', 'shortname': 'SECE', 'release': datetime(2015, 1, 16, 0, 0, 0, 0, time)},192# {'pack': 'Shadow of Infinity', 'shortname': 'SOI', 'release': datetime(2006, 2, 18, 0, 0, 0, 0, time)},193# {'pack': 'Shadow Specters', 'shortname': 'SHSP', 'release': datetime(2013, 11, 8, 0, 0, 0, 0, time)},194# {'pack': 'Shadows in Valhalla', 'shortname': 'SHVA', 'release': datetime(2018, 8, 17, 0, 0, 0, 0, time)},195# {'pack': 'Shining Victories', 'shortname': 'SHVI', 'release': datetime(2016, 5, 6, 0, 0, 0, 0, time)},196# {'pack': 'Soul Fusion', 'shortname': 'SOFU', 'release': datetime(2018, 10, 19, 0, 0, 0, 0, time)},197# {'pack': 'Soul of the Duelist', 'shortname': 'SOD', 'release': datetime(2004, 10, 1, 0, 0, 0, 0, time)},198# {'pack': 'Spell Ruler', 'shortname': 'SRL', 'release': datetime(2002, 9, 16, 0, 0, 0, 0, time)},199# {'pack': 'Spirit Warriors', 'shortname': 'SPWA', 'release': datetime(2017, 11, 17, 0, 0, 0, 0, time)},200# {'pack': 'Stardust Overdrive', 'shortname': 'SOVR', 'release': datetime(2009, 11, 17, 0, 0, 0, 0, time)},201# {'pack': 'Starstrike Blast', 'shortname': 'STBL', 'release': datetime(2010, 11, 16, 0, 0, 0, 0, time)},202# {'pack': 'Storm of Ragnarok', 'shortname': 'STOR', 'release': datetime(2011, 2, 8, 0, 0, 0, 0, time)},203# {'pack': 'Strike of Neos', 'shortname': 'STON', 'release': datetime(2007, 2, 28, 0, 0, 0, 0, time)},204# {'pack': 'Tactical Evolution', 'shortname': 'TAEV', 'release': datetime(2007, 8, 15, 0, 0, 0, 0, time)},205# {'pack': 'The Dark Illusion', 'shortname': 'TDIL', 'release': datetime(2016, 8, 5, 0, 0, 0, 0, time)},206# {'pack': 'The Duelist Genesis', 'shortname': 'TDGS', 'release': datetime(2008, 9, 2, 0, 0, 0, 0, time)},207# {'pack': 'The Lost Millennium', 'shortname': 'TLM', 'release': datetime(2005, 6, 1, 0, 0, 0, 0, time)},208# {'pack': 'The New Challengers', 'shortname': 'NECH', 'release': datetime(2014, 11, 7, 0, 0, 0, 0, time)},209# {'pack': 'The Shining Darkness', 'shortname': 'TSHD', 'release': datetime(2010, 5, 11, 0, 0, 0, 0, time)},210# {'pack': 'War of the Giants: Round 2', 'shortname': 'BPW2', 'release': datetime(2014, 1, 17, 0, 0, 0, 0, time)},211# {'pack': 'Wing Raiders', 'shortname': 'WIRA', 'release': datetime(2016, 2, 12, 0, 0, 0, 0, time)},212# {'pack': 'World Superstars', 'shortname': 'WSUP', 'release': datetime(2015, 4, 17, 0, 0, 0, 0, time)}]213#214# results = r.table("packlist").insert(packnames).run(conn)...

Full Screen

Full Screen

ism.py

Source:ism.py Github

copy

Full Screen

...16s88 = compat_Struct('>bx')17s16 = compat_Struct('>h')18s1616 = compat_Struct('>hxx')19s32 = compat_Struct('>i')20unity_matrix = (s32.pack(0x10000) + s32.pack(0) * 3) * 2 + s32.pack(0x40000000)21TRACK_ENABLED = 0x122TRACK_IN_MOVIE = 0x223TRACK_IN_PREVIEW = 0x424SELF_CONTAINED = 0x125def box(box_type, payload):26 return u32.pack(8 + len(payload)) + box_type + payload27def full_box(box_type, version, flags, payload):28 return box(box_type, u8.pack(version) + u32.pack(flags)[1:] + payload)29def write_piff_header(stream, params):30 track_id = params['track_id']31 fourcc = params['fourcc']32 duration = params['duration']33 timescale = params.get('timescale', 10000000)34 language = params.get('language', 'und')35 height = params.get('height', 0)36 width = params.get('width', 0)37 is_audio = width == 0 and height == 038 creation_time = modification_time = int(time.time())39 ftyp_payload = b'isml' # major brand40 ftyp_payload += u32.pack(1) # minor version41 ftyp_payload += b'piff' + b'iso2' # compatible brands42 stream.write(box(b'ftyp', ftyp_payload)) # File Type Box43 mvhd_payload = u64.pack(creation_time)44 mvhd_payload += u64.pack(modification_time)45 mvhd_payload += u32.pack(timescale)46 mvhd_payload += u64.pack(duration)47 mvhd_payload += s1616.pack(1) # rate48 mvhd_payload += s88.pack(1) # volume49 mvhd_payload += u16.pack(0) # reserved50 mvhd_payload += u32.pack(0) * 2 # reserved51 mvhd_payload += unity_matrix52 mvhd_payload += u32.pack(0) * 6 # pre defined53 mvhd_payload += u32.pack(0xffffffff) # next track id54 moov_payload = full_box(b'mvhd', 1, 0, mvhd_payload) # Movie Header Box55 tkhd_payload = u64.pack(creation_time)56 tkhd_payload += u64.pack(modification_time)57 tkhd_payload += u32.pack(track_id) # track id58 tkhd_payload += u32.pack(0) # reserved59 tkhd_payload += u64.pack(duration)60 tkhd_payload += u32.pack(0) * 2 # reserved61 tkhd_payload += s16.pack(0) # layer62 tkhd_payload += s16.pack(0) # alternate group63 tkhd_payload += s88.pack(1 if is_audio else 0) # volume64 tkhd_payload += u16.pack(0) # reserved65 tkhd_payload += unity_matrix66 tkhd_payload += u1616.pack(width)67 tkhd_payload += u1616.pack(height)68 trak_payload = full_box(b'tkhd', 1, TRACK_ENABLED | TRACK_IN_MOVIE | TRACK_IN_PREVIEW, tkhd_payload) # Track Header Box69 mdhd_payload = u64.pack(creation_time)70 mdhd_payload += u64.pack(modification_time)71 mdhd_payload += u32.pack(timescale)72 mdhd_payload += u64.pack(duration)73 mdhd_payload += u16.pack(((ord(language[0]) - 0x60) << 10) | ((ord(language[1]) - 0x60) << 5) | (ord(language[2]) - 0x60))74 mdhd_payload += u16.pack(0) # pre defined75 mdia_payload = full_box(b'mdhd', 1, 0, mdhd_payload) # Media Header Box76 hdlr_payload = u32.pack(0) # pre defined77 hdlr_payload += b'soun' if is_audio else b'vide' # handler type78 hdlr_payload += u32.pack(0) * 3 # reserved79 hdlr_payload += (b'Sound' if is_audio else b'Video') + b'Handler\0' # name80 mdia_payload += full_box(b'hdlr', 0, 0, hdlr_payload) # Handler Reference Box81 if is_audio:82 smhd_payload = s88.pack(0) # balance83 smhd_payload += u16.pack(0) # reserved84 media_header_box = full_box(b'smhd', 0, 0, smhd_payload) # Sound Media Header85 else:86 vmhd_payload = u16.pack(0) # graphics mode87 vmhd_payload += u16.pack(0) * 3 # opcolor88 media_header_box = full_box(b'vmhd', 0, 1, vmhd_payload) # Video Media Header89 minf_payload = media_header_box90 dref_payload = u32.pack(1) # entry count91 dref_payload += full_box(b'url ', 0, SELF_CONTAINED, b'') # Data Entry URL Box92 dinf_payload = full_box(b'dref', 0, 0, dref_payload) # Data Reference Box93 minf_payload += box(b'dinf', dinf_payload) # Data Information Box94 stsd_payload = u32.pack(1) # entry count95 sample_entry_payload = u8.pack(0) * 6 # reserved96 sample_entry_payload += u16.pack(1) # data reference index97 if is_audio:98 sample_entry_payload += u32.pack(0) * 2 # reserved99 sample_entry_payload += u16.pack(params.get('channels', 2))100 sample_entry_payload += u16.pack(params.get('bits_per_sample', 16))101 sample_entry_payload += u16.pack(0) # pre defined102 sample_entry_payload += u16.pack(0) # reserved103 sample_entry_payload += u1616.pack(params['sampling_rate'])104 if fourcc == 'AACL':105 sample_entry_box = box(b'mp4a', sample_entry_payload)106 else:107 sample_entry_payload += u16.pack(0) # pre defined108 sample_entry_payload += u16.pack(0) # reserved109 sample_entry_payload += u32.pack(0) * 3 # pre defined110 sample_entry_payload += u16.pack(width)111 sample_entry_payload += u16.pack(height)112 sample_entry_payload += u1616.pack(0x48) # horiz resolution 72 dpi113 sample_entry_payload += u1616.pack(0x48) # vert resolution 72 dpi114 sample_entry_payload += u32.pack(0) # reserved115 sample_entry_payload += u16.pack(1) # frame count116 sample_entry_payload += u8.pack(0) * 32 # compressor name117 sample_entry_payload += u16.pack(0x18) # depth118 sample_entry_payload += s16.pack(-1) # pre defined119 codec_private_data = binascii.unhexlify(params['codec_private_data'].encode('utf-8'))120 if fourcc in ('H264', 'AVC1'):121 sps, pps = codec_private_data.split(u32.pack(1))[1:]122 avcc_payload = u8.pack(1) # configuration version123 avcc_payload += sps[1:4] # avc profile indication + profile compatibility + avc level indication124 avcc_payload += u8.pack(0xfc | (params.get('nal_unit_length_field', 4) - 1)) # complete representation (1) + reserved (11111) + length size minus one125 avcc_payload += u8.pack(1) # reserved (0) + number of sps (0000001)126 avcc_payload += u16.pack(len(sps))127 avcc_payload += sps128 avcc_payload += u8.pack(1) # number of pps129 avcc_payload += u16.pack(len(pps))130 avcc_payload += pps131 sample_entry_payload += box(b'avcC', avcc_payload) # AVC Decoder Configuration Record132 sample_entry_box = box(b'avc1', sample_entry_payload) # AVC Simple Entry133 stsd_payload += sample_entry_box134 stbl_payload = full_box(b'stsd', 0, 0, stsd_payload) # Sample Description Box135 stts_payload = u32.pack(0) # entry count136 stbl_payload += full_box(b'stts', 0, 0, stts_payload) # Decoding Time to Sample Box137 stsc_payload = u32.pack(0) # entry count138 stbl_payload += full_box(b'stsc', 0, 0, stsc_payload) # Sample To Chunk Box139 stco_payload = u32.pack(0) # entry count140 stbl_payload += full_box(b'stco', 0, 0, stco_payload) # Chunk Offset Box141 minf_payload += box(b'stbl', stbl_payload) # Sample Table Box142 mdia_payload += box(b'minf', minf_payload) # Media Information Box143 trak_payload += box(b'mdia', mdia_payload) # Media Box144 moov_payload += box(b'trak', trak_payload) # Track Box145 mehd_payload = u64.pack(duration)146 mvex_payload = full_box(b'mehd', 1, 0, mehd_payload) # Movie Extends Header Box147 trex_payload = u32.pack(track_id) # track id148 trex_payload += u32.pack(1) # default sample description index149 trex_payload += u32.pack(0) # default sample duration150 trex_payload += u32.pack(0) # default sample size151 trex_payload += u32.pack(0) # default sample flags152 mvex_payload += full_box(b'trex', 0, 0, trex_payload) # Track Extends Box153 moov_payload += box(b'mvex', mvex_payload) # Movie Extends Box154 stream.write(box(b'moov', moov_payload)) # Movie Box155def extract_box_data(data, box_sequence):156 data_reader = io.BytesIO(data)157 while True:158 box_size = u32.unpack(data_reader.read(4))[0]159 box_type = data_reader.read(4)160 if box_type == box_sequence[0]:161 box_data = data_reader.read(box_size - 8)162 if len(box_sequence) == 1:163 return box_data164 return extract_box_data(box_data, box_sequence[1:])165 data_reader.seek(box_size - 8, 1)166class IsmFD(FragmentFD):167 """168 Download segments in a ISM manifest169 """170 FD_NAME = 'ism'171 def real_download(self, filename, info_dict):172 segments = info_dict['fragments'][:1] if self.params.get(173 'test', False) else info_dict['fragments']174 ctx = {175 'filename': filename,176 'total_frags': len(segments),177 }178 self._prepare_and_start_frag_download(ctx)179 fragment_retries = self.params.get('fragment_retries', 0)180 skip_unavailable_fragments = self.params.get('skip_unavailable_fragments', True)181 track_written = False182 frag_index = 0183 for i, segment in enumerate(segments):184 frag_index += 1185 if frag_index <= ctx['fragment_index']:186 continue187 count = 0188 while count <= fragment_retries:189 try:190 success, frag_content = self._download_fragment(ctx, segment['url'], info_dict)191 if not success:192 return False193 if not track_written:194 tfhd_data = extract_box_data(frag_content, [b'moof', b'traf', b'tfhd'])195 info_dict['_download_params']['track_id'] = u32.unpack(tfhd_data[4:8])[0]196 write_piff_header(ctx['dest_stream'], info_dict['_download_params'])197 track_written = True198 self._append_fragment(ctx, frag_content)199 break200 except compat_urllib_error.HTTPError as err:201 count += 1202 if count <= fragment_retries:203 self.report_retry_fragment(err, frag_index, count, fragment_retries)204 if count > fragment_retries:205 if skip_unavailable_fragments:206 self.report_skip_fragment(frag_index)207 continue208 self.report_error('giving up after %s fragment retries' % fragment_retries)209 return False...

Full Screen

Full Screen

test_pack.py

Source:test_pack.py Github

copy

Full Screen

...103 for indexfile, version, size in (self.packindexfile_v1, self.packindexfile_v2):104 index = PackIndexFile(indexfile)105 self._assert_index_file(index, version, size)106 # END run tests107 def test_pack(self):108 # there is this special version 3, but apparently its like 2 ...109 for packfile, version, size in (self.packfile_v2_3_ascii, self.packfile_v2_1, self.packfile_v2_2):110 pack = PackFile(packfile)111 self._assert_pack_file(pack, version, size)112 # END for each pack to test113 @with_rw_directory114 def test_pack_entity(self, rw_dir):115 pack_objs = list()116 for packinfo, indexinfo in ((self.packfile_v2_1, self.packindexfile_v1),117 (self.packfile_v2_2, self.packindexfile_v2),118 (self.packfile_v2_3_ascii, self.packindexfile_v2_3_ascii)):119 packfile, version, size = packinfo120 indexfile, version, size = indexinfo121 entity = PackEntity(packfile)122 assert entity.pack().path() == packfile123 assert entity.index().path() == indexfile124 pack_objs.extend(entity.stream_iter())125 count = 0126 for info, stream in izip(entity.info_iter(), entity.stream_iter()):127 count += 1128 assert info.binsha == stream.binsha129 assert len(info.binsha) == 20130 assert info.type_id == stream.type_id131 assert info.size == stream.size132 # we return fully resolved items, which is implied by the sha centric access133 assert not info.type_id in delta_types134 # try all calls135 assert len(entity.collect_streams(info.binsha))136 oinfo = entity.info(info.binsha)137 assert isinstance(oinfo, OInfo)138 assert oinfo.binsha is not None139 ostream = entity.stream(info.binsha)140 assert isinstance(ostream, OStream)141 assert ostream.binsha is not None142 # verify the stream143 try:144 assert entity.is_valid_stream(info.binsha, use_crc=True)145 except UnsupportedOperation:146 pass147 # END ignore version issues148 assert entity.is_valid_stream(info.binsha, use_crc=False)149 # END for each info, stream tuple150 assert count == size151 # END for each entity152 # pack writing - write all packs into one153 # index path can be None154 pack_path1 = tempfile.mktemp('', "pack1", rw_dir)155 pack_path2 = tempfile.mktemp('', "pack2", rw_dir)156 index_path = tempfile.mktemp('', 'index', rw_dir)157 iteration = 0158 def rewind_streams():159 for obj in pack_objs:160 obj.stream.seek(0)161 # END utility162 for ppath, ipath, num_obj in zip((pack_path1, pack_path2),163 (index_path, None),164 (len(pack_objs), None)):165 iwrite = None166 if ipath:167 ifile = open(ipath, 'wb')168 iwrite = ifile.write169 # END handle ip170 # make sure we rewind the streams ... we work on the same objects over and over again171 if iteration > 0:172 rewind_streams()173 # END rewind streams174 iteration += 1175 with open(ppath, 'wb') as pfile:176 pack_sha, index_sha = PackEntity.write_pack(pack_objs, pfile.write, iwrite, object_count=num_obj)177 assert os.path.getsize(ppath) > 100178 # verify pack179 pf = PackFile(ppath)180 assert pf.size() == len(pack_objs)181 assert pf.version() == PackFile.pack_version_default182 assert pf.checksum() == pack_sha183 pf.close()184 # verify index185 if ipath is not None:186 ifile.close()187 assert os.path.getsize(ipath) > 100188 idx = PackIndexFile(ipath)189 assert idx.version() == PackIndexFile.index_version_default190 assert idx.packfile_checksum() == pack_sha...

Full Screen

Full Screen

Pytest Tutorial

Looking for an in-depth tutorial around pytest? LambdaTest covers the detailed pytest tutorial that has everything related to the pytest, from setting up the pytest framework to automation testing. Delve deeper into pytest testing by exploring advanced use cases like parallel testing, pytest fixtures, parameterization, executing multiple test cases from a single file, and more.

Chapters

  1. What is pytest
  2. Pytest installation: Want to start pytest from scratch? See how to install and configure pytest for Python automation testing.
  3. Run first test with pytest framework: Follow this step-by-step tutorial to write and run your first pytest script.
  4. Parallel testing with pytest: A hands-on guide to parallel testing with pytest to improve the scalability of your test automation.
  5. Generate pytest reports: Reports make it easier to understand the results of pytest-based test runs. Learn how to generate pytest reports.
  6. Pytest Parameterized tests: Create and run your pytest scripts while avoiding code duplication and increasing test coverage with parameterization.
  7. Pytest Fixtures: Check out how to implement pytest fixtures for your end-to-end testing needs.
  8. Execute Multiple Test Cases: Explore different scenarios for running multiple test cases in pytest from a single file.
  9. Stop Test Suite after N Test Failures: See how to stop your test suite after n test failures in pytest using the @pytest.mark.incremental decorator and maxfail command-line option.

YouTube

Skim our below pytest tutorial playlist to get started with automation testing using the pytest framework.

https://www.youtube.com/playlist?list=PLZMWkkQEwOPlcGgDmHl8KkXKeLF83XlrP

Run Pytest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful