I don't think we know of any tests that really leak anymore
[python.git] / Lib / keyword.py
blobcd1d55e8a2cfea5f40a74fd98dabc427081dc294
1 #! /usr/bin/env python
3 """Keywords (from "graminit.c")
5 This file is automatically generated; please don't muck it up!
7 To update the symbols in this file, 'cd' to the top directory of
8 the python source tree after building the interpreter and run:
10 python Lib/keyword.py
11 """
13 __all__ = ["iskeyword", "kwlist"]
15 kwlist = [
16 #--start keywords--
17 'and',
18 'as',
19 'assert',
20 'break',
21 'class',
22 'continue',
23 'def',
24 'del',
25 'elif',
26 'else',
27 'except',
28 'exec',
29 'finally',
30 'for',
31 'from',
32 'global',
33 'if',
34 'import',
35 'in',
36 'is',
37 'lambda',
38 'not',
39 'or',
40 'pass',
41 'print',
42 'raise',
43 'return',
44 'try',
45 'while',
46 'with',
47 'yield',
48 #--end keywords--
51 iskeyword = frozenset(kwlist).__contains__
53 def main():
54 import sys, re
56 args = sys.argv[1:]
57 iptfile = args and args[0] or "Python/graminit.c"
58 if len(args) > 1: optfile = args[1]
59 else: optfile = "Lib/keyword.py"
61 # scan the source file for keywords
62 fp = open(iptfile)
63 strprog = re.compile('"([^"]+)"')
64 lines = []
65 while 1:
66 line = fp.readline()
67 if not line: break
68 if '{1, "' in line:
69 match = strprog.search(line)
70 if match:
71 lines.append(" '" + match.group(1) + "',\n")
72 fp.close()
73 lines.sort()
75 # load the output skeleton from the target
76 fp = open(optfile)
77 format = fp.readlines()
78 fp.close()
80 # insert the lines of keywords
81 try:
82 start = format.index("#--start keywords--\n") + 1
83 end = format.index("#--end keywords--\n")
84 format[start:end] = lines
85 except ValueError:
86 sys.stderr.write("target does not contain format markers\n")
87 sys.exit(1)
89 # write the output file
90 fp = open(optfile, 'w')
91 fp.write(''.join(format))
92 fp.close()
94 if __name__ == "__main__":
95 main()