Issue #5768: Change to Unicode output logic and test case for same.
[python.git] / Lib / keyword.py
blob8eb2860307e5b4bc4bd05287fbb23ae6ca6bcb11
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 for line in fp:
66 if '{1, "' in line:
67 match = strprog.search(line)
68 if match:
69 lines.append(" '" + match.group(1) + "',\n")
70 fp.close()
71 lines.sort()
73 # load the output skeleton from the target
74 fp = open(optfile)
75 format = fp.readlines()
76 fp.close()
78 # insert the lines of keywords
79 try:
80 start = format.index("#--start keywords--\n") + 1
81 end = format.index("#--end keywords--\n")
82 format[start:end] = lines
83 except ValueError:
84 sys.stderr.write("target does not contain format markers\n")
85 sys.exit(1)
87 # write the output file
88 fp = open(optfile, 'w')
89 fp.write(''.join(format))
90 fp.close()
92 if __name__ == "__main__":
93 main()