Best JavaScript code snippet using wpt
textool.py
Source:textool.py
...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:")...
db distinct.py
Source:db distinct.py
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)...
ism.py
Source:ism.py
...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...
test_pack.py
Source:test_pack.py
...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...
SquareCell.py
Source:SquareCell.py
1#battery-printer2#rely on home position set with 1st code loaded (separator)3#needs to re-zero "Z" between codes/syringes, but assume same x, y4#packaging bottom5#cathode6#separator7#packaging top8#anode9#sealing10from mecode import G11#nordson Tips sizes (color, inner diameter, outer diamter, in mm) 12#Olive 1.54 1.8313#Amber 1.36 1.6514#Grey 1.19 ??15#Green 0.84 1.2716#Pink 0.61 0.9117#Purple 0.51 0.8218#Blue 0.41 0.7219#Orange 0.33 0.6520#Red 0.25 0.5221#Clear 0.20 0.4222#Lavender 0.15 0.3123#Yellow 0.10 0.2424#Define variables25printvel = 150 #printvel; mm/min26printvel_pack = 10027printvel_sep = 10028tipsize_in = 1.54 #tipsize for electrodes, separator; mm29tipsize_out = 1.83 #tipsize for electrodes, separator; mm30tipsize_pack_in = 0.20 #tipsize for packaging; mm31tipsize_pack_out = 0.42 #tipsize for packaging; mm32square_edge = 20 #outer edge length in mm33square_thickness = 3 #outer edge to inner edge width in mm34offset_pack_in = square_thickness-tipsize_pack_out+(tipsize_pack_out-tipsize_pack_in)/2 #lower left corner35offset_pack_out = -(tipsize_pack_out-tipsize_pack_in)/2 #lower left corner36layers = 1 #layers for electrodes, separator; mm37layerheight = 0.5 #stepheight; mm 38layerheight_sep = 0.0539layers_pack_1 = int((layers*layerheight)/tipsize_pack_in)+140layerheight_pack_1 = (layers*layerheight)/layers_pack_141layers_pack_2 = int((layers*layerheight+layerheight_sep)/tipsize_pack_in)+142layerheight_pack_2 = (layers*layerheight+layerheight_sep)/layers_pack_243layerheight_seal = 0.144port = 145press = 3046press_pack = 2047press_sep = 3048number_x= 149number_y = 150spacing_x = 5.051spacing_y = 5.052#Define function53def pressure_set (line, press):54 line = 'M9000 P{line} Q{press}'.format(line=line, press=press)55 g.write(line)56def pressure_on ():57 g.write('M9001')58def pressure_off ():59 g.write('M10000')60def square_3D (path_length, path_width, nozzle_size, z_step, layers): #starts lower outer left, starts at absolute Z=061 62 step_number = int(path_width/nozzle_size) + 163 64 step_size = path_width/step_number65 66 for i in range (layers):67 g.move(Z=z_step)68 pressure_on()69 70 for i in range (step_number-1):71 g.move(x=path_length-nozzle_size-i*2*step_size)72 g.move(y=path_length-nozzle_size-i*2*step_size)73 g.move(x=-(path_length-nozzle_size-i*2*step_size))74 g.move(y=-(path_length-nozzle_size-i*2*step_size))75 g.move(x=step_size, y=step_size) 76 77 g.move(x=path_length-nozzle_size-(step_number-1)*2*step_size)78 g.move(y=path_length-nozzle_size-(step_number-1)*2*step_size)79 g.move(x=-(path_length-nozzle_size-(step_number-1)*2*step_size))80 g.move(y=-(path_length-nozzle_size-(step_number-1)*2*step_size))81 82 pressure_off()83 g.dwell(3)84 g.move(x=-step_size*(step_number-1), y=-step_size*(step_number-1))85 86 87#file- 1packaging_bottom88g = G(89 outfile = "/Users/SeanWei/Documents/Python/PrintCode/squarecell/squarecell_20mm_3mm_1packaging_bottom.txt",90 header = "/Users/SeanWei/Documents/Python/PrintCode/header_batteryprinter.txt",91 footer = "/Users/SeanWei/Documents/Python/PrintCode/footer_batteryprinter.txt",92 aerotech_include = False,93 direct_write = False,94 print_lines = False, 95 )96#Code starts97g.set_home(x=0,y=0,Z=0) #lower left corner, nozzle edge with substrate edge, absolute zero98g.feed(printvel_pack)99g.abs_move(Z=layerheight_pack_1)100g.abs_move(x=offset_pack_in, y=offset_pack_in, )101pressure_set(port, press_pack)102pressure_on()103 104for i in range(layers_pack_1):105 g.rect(square_edge-2*square_thickness+tipsize_pack_in, square_edge-2*square_thickness+tipsize_pack_in)106 g.move(Z=layerheight_pack_1)107 108pressure_off()109g.dwell(3.0)110g.abs_move(Z=5)111 112g.abs_move(x=offset_pack_out, y=offset_pack_out)113g.abs_move(Z=layerheight_pack_1)114pressure_set(port, press_pack)115pressure_on()116 117for i in range(layers_pack_1):118 g.rect(square_edge-tipsize_pack_in, square_edge-tipsize_pack_in)119 g.move(Z=layerheight_pack_1)120 121pressure_off()122g.dwell(3.0)123 124g.abs_move(Z=5)125#file - 2cathode126g = G(127 outfile = "/Users/SeanWei/Documents/Python/PrintCode/squarecell/squarecell_20mm_3mm_2cathode.txt",128 header = "/Users/SeanWei/Documents/Python/PrintCode/header_batteryprinter.txt",129 footer = "/Users/SeanWei/Documents/Python/PrintCode/footer_batteryprinter.txt",130 aerotech_include = False,131 direct_write = False,132 print_lines = False, 133 )134#Code starts135g.abs_move(x=tipsize_pack_in+tipsize_out, y=tipsize_pack_in+tipsize_out)136g.abs_move(Z=0)137g.feed(printvel)138pressure_set(port, press) 139square_3D (square_edge-2*tipsize_pack_in, square_thickness-2*tipsize_pack_in, tipsize_out, layerheight, layers)140g.abs_move(Z=5)141 142#file - 3separator143g = G(144 outfile = "/Users/SeanWei/Documents/Python/PrintCode/squarecell/squarecell_20mm_3mm_3separator.txt",145 header = "/Users/SeanWei/Documents/Python/PrintCode/header_batteryprinter.txt",146 footer = "/Users/SeanWei/Documents/Python/PrintCode/footer_batteryprinter.txt",147 aerotech_include = False,148 direct_write = False,149 print_lines = False, 150 )151#Code starts152g.abs_move(x=tipsize_pack_in+tipsize_out, y=tipsize_pack_in+tipsize_out)153g.abs_move(Z=layers*layerheight+layerheight_sep)154g.feed(printvel_sep)155pressure_set(port, press) 156square_3D (square_edge-2*tipsize_pack_in, square_thickness-2*tipsize_pack_in, tipsize_out, layerheight_sep, 1)157g.abs_move(Z=5) 158#file- 4packaging_top159g = G(160 outfile = "/Users/SeanWei/Documents/Python/PrintCode/squarecell/squarecell_20mm_3mm_4packaging_top.txt",161 header = "/Users/SeanWei/Documents/Python/PrintCode/header_batteryprinter.txt",162 footer = "/Users/SeanWei/Documents/Python/PrintCode/footer_batteryprinter.txt",163 aerotech_include = False,164 direct_write = False,165 print_lines = False, 166 )167#Code starts168g.set_home(x=0,y=0,Z=0) #lower left corner, nozzle edge with substrate edge, absolute zero169g.feed(printvel_pack)170g.abs_move(x=offset_pack_in, y=offset_pack_in)171g.abs_move(Z=layers*layerheight+layerheight_sep+layerheight_pack_2)172pressure_set(port, press_pack)173pressure_on()174 175for i in range(layers_pack_2):176 g.rect(square_edge-2*square_thickness+tipsize_pack_in, square_edge-2*square_thickness+tipsize_pack_in)177 g.move(Z=layerheight_pack_2)178 179pressure_off()180g.dwell(3.0)181g.abs_move(Z=5)182 183g.abs_move(x=offset_pack_out, y=offset_pack_out)184g.abs_move(Z=layers*layerheight+layerheight_sep+layerheight_pack_2)185pressure_set(port, press_pack)186pressure_on()187 188for i in range(layers_pack_2):189 g.rect(square_edge-tipsize_pack_in, square_edge-tipsize_pack_in)190 g.move(Z=layerheight_pack_2)191 192pressure_off()193g.dwell(3.0)194 195g.abs_move(Z=5)196#file - 5anode197g = G(198 outfile = "/Users/SeanWei/Documents/Python/PrintCode/squarecell/squarecell_20mm_3mm_5anode.txt",199 header = "/Users/SeanWei/Documents/Python/PrintCode/header_batteryprinter.txt",200 footer = "/Users/SeanWei/Documents/Python/PrintCode/footer_batteryprinter.txt",201 aerotech_include = False,202 direct_write = False,203 print_lines = False, 204 )205#Code starts206g.abs_move(x=tipsize_pack_in+tipsize_out, y=tipsize_pack_in+tipsize_out)207g.abs_move(Z=2*layers*layerheight+layerheight_sep)208g.feed(printvel)209pressure_set(port, press) 210square_3D (square_edge-2*tipsize_pack_in, square_thickness-2*tipsize_pack_in, tipsize_out, layerheight, layers)211g.abs_move(Z=5)212#file- 6seal213g = G(214 outfile = "/Users/SeanWei/Documents/Python/PrintCode/squarecell/squarecell_20mm_3mm_6seal.txt",215 header = "/Users/SeanWei/Documents/Python/PrintCode/header_batteryprinter.txt",216 footer = "/Users/SeanWei/Documents/Python/PrintCode/footer_batteryprinter.txt",217 aerotech_include = False,218 direct_write = False,219 print_lines = False, 220 )221#Code starts222g.set_home(x=0,y=0,Z=0) #lower left corner, nozzle edge with substrate edge, absolute zero223g.feed(printvel_pack)224g.abs_move(x=offset_pack_in, y=offset_pack_in)225g.abs_move(Z=2*layers*layerheight+layerheight_sep+layerheight_seal)226pressure_set(port, press_pack)227pressure_on() 228g.rect(square_edge-2*square_thickness+tipsize_pack_in, square_edge-2*square_thickness+tipsize_pack_in)229 230pressure_off()231g.dwell(3.0)232g.abs_move(Z=5)233 234g.abs_move(x=offset_pack_out, y=offset_pack_out)235g.abs_move(Z=2*layers*layerheight+layerheight_sep+layerheight_seal)236pressure_set(port, press_pack)237pressure_on()238 239g.rect(square_edge-tipsize_pack_in, square_edge-tipsize_pack_in)240 241pressure_off()242g.dwell(3.0)243 244g.abs_move(Z=5)245 246 247#To end248#g.view(backend='matplotlib')249#g.view()...
xdrlib.py
Source:xdrlib.py
...33 return self.__buf.getvalue()34 # backwards compatibility35 get_buf = get_buffer36 def pack_uint(self, x):37 self.__buf.write(struct.pack('>L', x))38 pack_int = pack_uint39 pack_enum = pack_int40 def pack_bool(self, x):41 if x: self.__buf.write('\0\0\0\1')42 else: self.__buf.write('\0\0\0\0')43 def pack_uhyper(self, x):44 self.pack_uint(x>>32 & 0xffffffffL)45 self.pack_uint(x & 0xffffffffL)46 pack_hyper = pack_uhyper47 def pack_float(self, x):48 try: self.__buf.write(struct.pack('>f', x))49 except struct.error, msg:50 raise ConversionError, msg51 def pack_double(self, x):52 try: self.__buf.write(struct.pack('>d', x))53 except struct.error, msg:54 raise ConversionError, msg55 def pack_fstring(self, n, s):56 if n < 0:57 raise ValueError, 'fstring size must be nonnegative'58 n = ((n+3)/4)*459 data = s[:n]60 data = data + (n - len(data)) * '\0'61 self.__buf.write(data)62 pack_fopaque = pack_fstring63 def pack_string(self, s):64 n = len(s)65 self.pack_uint(n)66 self.pack_fstring(n, s)67 pack_opaque = pack_string68 pack_bytes = pack_string69 def pack_list(self, list, pack_item):70 for item in list:71 self.pack_uint(1)72 pack_item(item)73 self.pack_uint(0)74 def pack_farray(self, n, list, pack_item):75 if len(list) != n:76 raise ValueError, 'wrong array size'77 for item in list:78 pack_item(item)79 def pack_array(self, list, pack_item):80 n = len(list)81 self.pack_uint(n)82 self.pack_farray(n, list, pack_item)83class Unpacker:84 """Unpacks various data representations from the given buffer."""85 def __init__(self, data):86 self.reset(data)87 def reset(self, data):88 self.__buf = data89 self.__pos = 090 def get_position(self):91 return self.__pos92 def set_position(self, position):93 self.__pos = position94 def get_buffer(self):95 return self.__buf96 def done(self):97 if self.__pos < len(self.__buf):98 raise Error('unextracted data remains')99 def unpack_uint(self):100 i = self.__pos101 self.__pos = j = i+4102 data = self.__buf[i:j]103 if len(data) < 4:104 raise EOFError105 x = struct.unpack('>L', data)[0]106 try:107 return int(x)108 except OverflowError:109 return x110 def unpack_int(self):111 i = self.__pos112 self.__pos = j = i+4113 data = self.__buf[i:j]114 if len(data) < 4:115 raise EOFError116 return struct.unpack('>l', data)[0]117 unpack_enum = unpack_int118 unpack_bool = unpack_int119 def unpack_uhyper(self):120 hi = self.unpack_uint()121 lo = self.unpack_uint()122 return long(hi)<<32 | lo123 def unpack_hyper(self):124 x = self.unpack_uhyper()125 if x >= 0x8000000000000000L:126 x = x - 0x10000000000000000L127 return x128 def unpack_float(self):129 i = self.__pos130 self.__pos = j = i+4131 data = self.__buf[i:j]132 if len(data) < 4:133 raise EOFError134 return struct.unpack('>f', data)[0]135 def unpack_double(self):136 i = self.__pos137 self.__pos = j = i+8138 data = self.__buf[i:j]139 if len(data) < 8:140 raise EOFError141 return struct.unpack('>d', data)[0]142 def unpack_fstring(self, n):143 if n < 0:144 raise ValueError, 'fstring size must be nonnegative'145 i = self.__pos146 j = i + (n+3)/4*4147 if j > len(self.__buf):148 raise EOFError149 self.__pos = j150 return self.__buf[i:i+n]151 unpack_fopaque = unpack_fstring152 def unpack_string(self):153 n = self.unpack_uint()154 return self.unpack_fstring(n)155 unpack_opaque = unpack_string...
packer_defs.py
Source:packer_defs.py
1# Copyright (c) 2001, Stanford University2# All rights reserved.3#4# See the file LICENSE.txt for information on redistributing this software.5# This script generates the packer/packer.def file.6import sys7import cPickle8import apiutil9apiutil.CopyrightDef()10print "DESCRIPTION \"\""11print "EXPORTS"12keys = apiutil.GetDispatchedFunctions(sys.argv[1]+"/APIspec.txt")13for func_name in keys:14 if apiutil.CanPack(func_name):15 print "crPack%s" % func_name16 print "crPack%sSWAP" % func_name17functions = [18 'crPackVertexAttrib1dARBBBOX',19 'crPackVertexAttrib1dvARBBBOX',20 'crPackVertexAttrib1fARBBBOX',21 'crPackVertexAttrib1fvARBBBOX',22 'crPackVertexAttrib1sARBBBOX',23 'crPackVertexAttrib1svARBBBOX',24 'crPackVertexAttrib2dARBBBOX',25 'crPackVertexAttrib2dvARBBBOX',26 'crPackVertexAttrib2fARBBBOX',27 'crPackVertexAttrib2fvARBBBOX',28 'crPackVertexAttrib2sARBBBOX',29 'crPackVertexAttrib2svARBBBOX',30 'crPackVertexAttrib3dARBBBOX',31 'crPackVertexAttrib3dvARBBBOX',32 'crPackVertexAttrib3fARBBBOX',33 'crPackVertexAttrib3fvARBBBOX',34 'crPackVertexAttrib3sARBBBOX',35 'crPackVertexAttrib3svARBBBOX',36 'crPackVertexAttrib4dARBBBOX',37 'crPackVertexAttrib4dvARBBBOX',38 'crPackVertexAttrib4fARBBBOX',39 'crPackVertexAttrib4fvARBBBOX',40 'crPackVertexAttrib4sARBBBOX',41 'crPackVertexAttrib4svARBBBOX',42 'crPackVertexAttrib4usvARBBBOX',43 'crPackVertexAttrib4ivARBBBOX',44 'crPackVertexAttrib4uivARBBBOX',45 'crPackVertexAttrib4bvARBBBOX',46 'crPackVertexAttrib4ubvARBBBOX',47 'crPackVertexAttrib4NusvARBBBOX',48 'crPackVertexAttrib4NsvARBBBOX',49 'crPackVertexAttrib4NuivARBBBOX',50 'crPackVertexAttrib4NivARBBBOX',51 'crPackVertexAttrib4NubvARBBBOX',52 'crPackVertexAttrib4NbvARBBBOX',53 'crPackVertexAttrib4NubARBBBOX',54 'crPackVertex2dBBOX',55 'crPackVertex2dvBBOX',56 'crPackVertex2fBBOX',57 'crPackVertex2fvBBOX',58 'crPackVertex2iBBOX',59 'crPackVertex2ivBBOX',60 'crPackVertex2sBBOX',61 'crPackVertex2svBBOX',62 'crPackVertex3dBBOX',63 'crPackVertex3dvBBOX',64 'crPackVertex3fBBOX',65 'crPackVertex3fvBBOX',66 'crPackVertex3iBBOX',67 'crPackVertex3ivBBOX',68 'crPackVertex3sBBOX',69 'crPackVertex3svBBOX',70 'crPackVertex4dBBOX',71 'crPackVertex4dvBBOX',72 'crPackVertex4fBBOX',73 'crPackVertex4fvBBOX',74 'crPackVertex4iBBOX',75 'crPackVertex4ivBBOX',76 'crPackVertex4sBBOX',77 'crPackVertex4svBBOX',78 'crPackVertexAttrib1dARBBBOX_COUNT',79 'crPackVertexAttrib1dvARBBBOX_COUNT',80 'crPackVertexAttrib1fARBBBOX_COUNT',81 'crPackVertexAttrib1fvARBBBOX_COUNT',82 'crPackVertexAttrib1sARBBBOX_COUNT',83 'crPackVertexAttrib1svARBBBOX_COUNT',84 'crPackVertexAttrib2dARBBBOX_COUNT',85 'crPackVertexAttrib2dvARBBBOX_COUNT',86 'crPackVertexAttrib2fARBBBOX_COUNT',87 'crPackVertexAttrib2fvARBBBOX_COUNT',88 'crPackVertexAttrib2sARBBBOX_COUNT',89 'crPackVertexAttrib2svARBBBOX_COUNT',90 'crPackVertexAttrib3dARBBBOX_COUNT',91 'crPackVertexAttrib3dvARBBBOX_COUNT',92 'crPackVertexAttrib3fARBBBOX_COUNT',93 'crPackVertexAttrib3fvARBBBOX_COUNT',94 'crPackVertexAttrib3sARBBBOX_COUNT',95 'crPackVertexAttrib3svARBBBOX_COUNT',96 'crPackVertexAttrib4dARBBBOX_COUNT',97 'crPackVertexAttrib4dvARBBBOX_COUNT',98 'crPackVertexAttrib4fARBBBOX_COUNT',99 'crPackVertexAttrib4fvARBBBOX_COUNT',100 'crPackVertexAttrib4sARBBBOX_COUNT',101 'crPackVertexAttrib4svARBBBOX_COUNT',102 'crPackVertexAttrib4usvARBBBOX_COUNT',103 'crPackVertexAttrib4ivARBBBOX_COUNT',104 'crPackVertexAttrib4uivARBBBOX_COUNT',105 'crPackVertexAttrib4bvARBBBOX_COUNT',106 'crPackVertexAttrib4ubvARBBBOX_COUNT',107 'crPackVertexAttrib4NusvARBBBOX_COUNT',108 'crPackVertexAttrib4NsvARBBBOX_COUNT',109 'crPackVertexAttrib4NuivARBBBOX_COUNT',110 'crPackVertexAttrib4NivARBBBOX_COUNT',111 'crPackVertexAttrib4NubvARBBBOX_COUNT',112 'crPackVertexAttrib4NbvARBBBOX_COUNT',113 'crPackVertexAttrib4NubARBBBOX_COUNT',114 'crPackVertex2dBBOX_COUNT',115 'crPackVertex2dvBBOX_COUNT',116 'crPackVertex2fBBOX_COUNT',117 'crPackVertex2fvBBOX_COUNT',118 'crPackVertex2iBBOX_COUNT',119 'crPackVertex2ivBBOX_COUNT',120 'crPackVertex2sBBOX_COUNT',121 'crPackVertex2svBBOX_COUNT',122 'crPackVertex3dBBOX_COUNT',123 'crPackVertex3dvBBOX_COUNT',124 'crPackVertex3fBBOX_COUNT',125 'crPackVertex3fvBBOX_COUNT',126 'crPackVertex3iBBOX_COUNT',127 'crPackVertex3ivBBOX_COUNT',128 'crPackVertex3sBBOX_COUNT',129 'crPackVertex3svBBOX_COUNT',130 'crPackVertex4dBBOX_COUNT',131 'crPackVertex4dvBBOX_COUNT',132 'crPackVertex4fBBOX_COUNT',133 'crPackVertex4fvBBOX_COUNT',134 'crPackVertex4iBBOX_COUNT',135 'crPackVertex4ivBBOX_COUNT',136 'crPackVertex4sBBOX_COUNT',137 'crPackVertex4svBBOX_COUNT',138 'crPackVertexAttribs1dvNV',139 'crPackVertexAttribs1fvNV',140 'crPackVertexAttribs1svNV',141 'crPackVertexAttribs2dvNV',142 'crPackVertexAttribs2fvNV',143 'crPackVertexAttribs2svNV',144 'crPackVertexAttribs3dvNV',145 'crPackVertexAttribs3fvNV',146 'crPackVertexAttribs3svNV',147 'crPackVertexAttribs4dvNV',148 'crPackVertexAttribs4fvNV',149 'crPackVertexAttribs4svNV',150 'crPackVertexAttribs4ubvNV',151 'crPackExpandDrawArrays',152 'crPackExpandDrawElements',153 'crPackUnrollDrawElements',154 'crPackExpandDrawRangeElements',155 'crPackExpandArrayElement',156 'crPackExpandMultiDrawArraysEXT',157 'crPackMultiDrawArraysEXT',158 'crPackMultiDrawElementsEXT',159 'crPackExpandMultiDrawElementsEXT',160 'crPackMapBufferARB',161 'crPackUnmapBufferARB' ]162for func_name in functions:163 print "%s" % func_name164 print "%sSWAP" % func_name165print """166crPackInitBuffer167crPackResetPointers168crPackAppendBuffer169crPackAppendBoundedBuffer170crPackSetBuffer171crPackSetBufferDEBUG172crPackReleaseBuffer173crPackFlushFunc174crPackFlushArg175crPackSendHugeFunc176crPackBoundsInfoCR177crPackResetBoundingBox178crPackGetBoundingBox179crPackOffsetCurrentPointers180crPackNullCurrentPointers181crPackNewContext182crPackGetContext183crPackSetContext184crPackFree185crNetworkPointerWrite186crPackCanHoldBuffer187crPackCanHoldBoundedBuffer188crPackMaxData189crPackErrorFunction190cr_packer_globals191_PackerTSD...
update.py
Source:update.py
1#!/usr/bin/env python2"""3Copyright (c) 2006-2018 sqlmap developers (http://sqlmap.org/)4See the file 'LICENSE' for copying permission5"""6import codecs7import os8import re9import urllib210import urlparse11from xml.dom.minidom import Document12# Path to the XML file with signatures13MSSQL_XML = os.path.abspath("../../xml/banner/mssql.xml")14# Url to update Microsoft SQL Server XML versions file from15MSSQL_VERSIONS_URL = "http://www.sqlsecurity.com/FAQs/SQLServerVersionDatabase/tabid/63/Default.aspx"16def updateMSSQLXML():17 if not os.path.exists(MSSQL_XML):18 errMsg = "[ERROR] file '%s' does not exist. Please run the script from its parent directory" % MSSQL_XML19 print errMsg20 return21 infoMsg = "[INFO] retrieving data from '%s'" % MSSQL_VERSIONS_URL22 print infoMsg23 try:24 req = urllib2.Request(MSSQL_VERSIONS_URL)25 f = urllib2.urlopen(req)26 mssqlVersionsHtmlString = f.read()27 f.close()28 except urllib2.URLError:29 __mssqlPath = urlparse.urlsplit(MSSQL_VERSIONS_URL)30 __mssqlHostname = __mssqlPath[1]31 warnMsg = "[WARNING] sqlmap was unable to connect to %s," % __mssqlHostname32 warnMsg += " check your Internet connection and retry"33 print warnMsg34 return35 releases = re.findall("class=\"BCC_DV_01DarkBlueTitle\">SQL Server\s(.+?)\sBuilds", mssqlVersionsHtmlString, re.I)36 releasesCount = len(releases)37 # Create the minidom document38 doc = Document()39 # Create the <root> base element40 root = doc.createElement("root")41 doc.appendChild(root)42 for index in xrange(0, releasesCount):43 release = releases[index]44 # Skip Microsoft SQL Server 6.5 because the HTML45 # table is in another format46 if release == "6.5":47 continue48 # Create the <signatures> base element49 signatures = doc.createElement("signatures")50 signatures.setAttribute("release", release)51 root.appendChild(signatures)52 startIdx = mssqlVersionsHtmlString.index("SQL Server %s Builds" % releases[index])53 if index == releasesCount - 1:54 stopIdx = len(mssqlVersionsHtmlString)55 else:56 stopIdx = mssqlVersionsHtmlString.index("SQL Server %s Builds" % releases[index + 1])57 mssqlVersionsReleaseString = mssqlVersionsHtmlString[startIdx:stopIdx]58 servicepackVersion = re.findall("</td><td>(7\.0|2000|2005|2008|2008 R2)*(.*?)</td><td.*?([\d\.]+)</td>[\r]*\n", mssqlVersionsReleaseString, re.I)59 for servicePack, version in servicepackVersion:60 if servicePack.startswith(" "):61 servicePack = servicePack[1:]62 if "/" in servicePack:63 servicePack = servicePack[:servicePack.index("/")]64 if "(" in servicePack:65 servicePack = servicePack[:servicePack.index("(")]66 if "-" in servicePack:67 servicePack = servicePack[:servicePack.index("-")]68 if "*" in servicePack:69 servicePack = servicePack[:servicePack.index("*")]70 if servicePack.startswith("+"):71 servicePack = "0%s" % servicePack72 servicePack = servicePack.replace("\t", " ")73 servicePack = servicePack.replace("No SP", "0")74 servicePack = servicePack.replace("RTM", "0")75 servicePack = servicePack.replace("TM", "0")76 servicePack = servicePack.replace("SP", "")77 servicePack = servicePack.replace("Service Pack", "")78 servicePack = servicePack.replace("<a href=\"http:", "")79 servicePack = servicePack.replace(" ", " ")80 servicePack = servicePack.replace("+ ", "+")81 servicePack = servicePack.replace(" +", "+")82 if servicePack.endswith(" "):83 servicePack = servicePack[:-1]84 if servicePack and version:85 # Create the main <card> element86 signature = doc.createElement("signature")87 signatures.appendChild(signature)88 # Create a <version> element89 versionElement = doc.createElement("version")90 signature.appendChild(versionElement)91 # Give the <version> elemenet some text92 versionText = doc.createTextNode(version)93 versionElement.appendChild(versionText)94 # Create a <servicepack> element95 servicepackElement = doc.createElement("servicepack")96 signature.appendChild(servicepackElement)97 # Give the <servicepack> elemenet some text98 servicepackText = doc.createTextNode(servicePack)99 servicepackElement.appendChild(servicepackText)100 # Save our newly created XML to the signatures file101 mssqlXml = codecs.open(MSSQL_XML, "w", "utf8")102 doc.writexml(writer=mssqlXml, addindent=" ", newl="\n")103 mssqlXml.close()104 infoMsg = "[INFO] done. retrieved data parsed and saved into '%s'" % MSSQL_XML105 print infoMsg106if __name__ == "__main__":...
Using AI Code Generation
1var wptools = require('wptools');2var fs = require('fs');3var request = require('request');4var async = require('async');5var _ = require('underscore');6var path = require('path');7var Promise = require('bluebird');8var csv = require('csv');9var input = fs.createReadStream('test.csv');10var parser = csv.parse();11var transformer = csv.transform(function(data){12 return data.map(function(value){13 return value.trim();14 });15});16var writer = csv.stringify();17var output = fs.createWriteStream('output.csv');18input.pipe(parser).pipe(transformer).pipe(writer).pipe(output);19var csvData = [];20parser.on('readable', function(){21 while(record = parser.read()){22 csvData.push(record);23 }24});25parser.on('end', function(){26 var data = [];27 async.eachSeries(csvData, function(line, callback) {28 var name = line[1];29 var url = line[0];30 var page = wptools.page(name);31 page.get(function(err, resp) {32 var image = resp.image;33 var image_url = resp.image_url;34 var infobox = resp.infobox;35 var description = resp.description;36 var coordinates = resp.coordinates;37 var category = resp.category;38 data.push([url, name, image, image_url, infobox, description, coordinates, category]);39 callback();40 });41 }, function(err) {42 if( err ) {43 console.log('A file failed to process');44 } else {45 console.log('All files have been processed successfully');46 var output = fs.createWriteStream('output.csv');47 csv.stringify(data, function(err, data){48 output.write(data);49 });50 }51 });52});
Using AI Code Generation
1var wptools = require('./lib/wptools');2var wp = wptools.pack;3var wptools = require('./lib/wptools');4var wp = wptools.unpack;5var wptools = require('./lib/wptools');6var wp = wptools.pack;7var wp = wptools.unpack;8var wptools = require('./lib/wptools');9var wp = wptools.pack;10var wp = wptools.unpack;11var wptools = require('./lib/wptools');12var wp = wptools.pack;13var wp = wptools.unpack;14var wptools = require('./lib/wptools');15var wp = wptools.pack;16var wp = wptools.unpack;17var wptools = require('./lib/wptools');18var wp = wptools.pack;19var wp = wptools.unpack;20var wptools = require('./lib/wptools');21var wp = wptools.pack;22var wp = wptools.unpack;23var wptools = require('./lib/wptools');24var wp = wptools.pack;25var wp = wptools.unpack;26var wptools = require('./lib/wptools');27var wp = wptools.pack;28var wp = wptools.unpack;29var wptools = require('./lib/wptools');30var wp = wptools.pack;31var wp = wptools.unpack;32var wptools = require('./lib/wptools');33var wp = wptools.pack;34var wp = wptools.unpack;35var wptools = require('./lib/wptools');36var wp = wptools.pack;
Using AI Code Generation
1var wptools = require('wptools');2var wiki = wptools.page('Albert Einstein');3wiki.pack(function(err, resp) {4 console.log(resp);5});6var wptools = require('wptools');7var wiki = wptools.page('Albert Einstein');8wiki.pack(function(err, resp) {9 console.log(resp);10});11var wptools = require('wptools');12var wiki = wptools.page('Albert Einstein');13wiki.pack(function(err, resp) {14 console.log(resp);15});16var wptools = require('wptools');17var wiki = wptools.page('Albert Einstein');18wiki.pack(function(err, resp) {19 console.log(resp);20});21var wptools = require('wptools');22var wiki = wptools.page('Albert Einstein');23wiki.pack(function(err, resp) {24 console.log(resp);25});26var wptools = require('wptools');27var wiki = wptools.page('Albert Einstein');28wiki.pack(function(err, resp) {29 console.log(resp);30});31var wptools = require('wptools');32var wiki = wptools.page('Albert Einstein');33wiki.pack(function(err, resp) {34 console.log(resp);35});36var wptools = require('wptools');37var wiki = wptools.page('Albert Einstein');38wiki.pack(function(err, resp) {39 console.log(resp);40});41var wptools = require('wptools');42var wiki = wptools.page('Albert Einstein');43wiki.pack(function(err, resp) {44 console.log(resp);45});46var wptools = require('wptools');47var wiki = wptools.page('Albert
Using AI Code Generation
1var wptool = require('wptool');2var pack = wptool.pack({3 'dependencies': {4 }5}, function(err, data) {6 console.log(data);7});
Using AI Code Generation
1var wptools = require('wptools');2var output = wptools.page('Wikipedia').get(function(err, resp){3 console.log(resp);4});5var wptools = require('wptools');6var output = wptools.page('Wikipedia').get(function(err, resp){7 console.log(resp);8});9var wptools = require('wptools');10var output = wptools.page('Wikipedia').get(function(err, resp){11 console.log(resp);12});13var wptools = require('wptools');14var output = wptools.page('Wikipedia').get(function(err, resp){15 console.log(resp);16});17var wptools = require('wptools');18var output = wptools.page('Wikipedia').get(function(err, resp){19 console.log(resp);20});21var wptools = require('wptools');22var output = wptools.page('Wikipedia').get(function(err, resp){23 console.log(resp);24});25var wptools = require('wptools');26var output = wptools.page('Wikipedia').get(function(err, resp){27 console.log(resp);28});29var wptools = require('wptools');30var output = wptools.page('Wikipedia').get(function(err, resp){31 console.log(resp);32});33var wptools = require('wptools');34var output = wptools.page('Wikipedia').get(function(err, resp){35 console.log(resp);36});37var wptools = require('wptools');38var output = wptools.page('Wikipedia').get(function(err, resp){39 console.log(resp);40});
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!