1# Test interning qstrs that go over the limit of the maximum qstr length 2# (which is 255 bytes for the default configuration) 3 4 5def make_id(n, base="a"): 6 return "".join(chr(ord(base) + i % 26) for i in range(n)) 7 8 9# identifiers in parser 10for l in range(254, 259): 11 g = {} 12 var = make_id(l) 13 try: 14 exec(var + "=1", g) 15 except RuntimeError: 16 print("RuntimeError", l) 17 continue 18 print(var in g) 19 20# calling a function with kwarg 21def f(**k): 22 print(k) 23 24 25for l in range(254, 259): 26 try: 27 exec("f({}=1)".format(make_id(l))) 28 except RuntimeError: 29 print("RuntimeError", l) 30 31# type construction 32for l in range(254, 259): 33 id = make_id(l) 34 try: 35 print(type(id, (), {}).__name__) 36 except RuntimeError: 37 print("RuntimeError", l) 38 39# hasattr, setattr, getattr 40class A: 41 pass 42 43 44for l in range(254, 259): 45 id = make_id(l) 46 a = A() 47 try: 48 setattr(a, id, 123) 49 except RuntimeError: 50 print("RuntimeError", l) 51 try: 52 print(hasattr(a, id), getattr(a, id)) 53 except RuntimeError: 54 print("RuntimeError", l) 55 56# format with keys 57for l in range(254, 259): 58 id = make_id(l) 59 try: 60 print(("{" + id + "}").format(**{id: l})) 61 except RuntimeError: 62 print("RuntimeError", l) 63 64# modulo format with keys 65for l in range(254, 259): 66 id = make_id(l) 67 try: 68 print(("%(" + id + ")d") % {id: l}) 69 except RuntimeError: 70 print("RuntimeError", l) 71 72# import module 73# (different OS's have different results so only run those that are consistent) 74for l in (100, 101, 256, 257, 258): 75 try: 76 __import__(make_id(l)) 77 except ImportError: 78 print("ok", l) 79 except RuntimeError: 80 print("RuntimeError", l) 81 82# import package 83for l in (100, 101, 102, 128, 129): 84 try: 85 exec("import " + make_id(l) + "." + make_id(l, "A")) 86 except ImportError: 87 print("ok", l) 88 except RuntimeError: 89 print("RuntimeError", l) 90