Skip to content

Commit 078934a

Browse files
committed
keyword: Add pristine from Python-3.3.3 tarball.
1 parent 4101f31 commit 078934a

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

keyword/keyword.py

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#! /usr/bin/env python3
2+
3+
"""Keywords (from "graminit.c")
4+
5+
This file is automatically generated; please don't muck it up!
6+
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:
9+
10+
./python Lib/keyword.py
11+
"""
12+
13+
__all__ = ["iskeyword", "kwlist"]
14+
15+
kwlist = [
16+
#--start keywords--
17+
'False',
18+
'None',
19+
'True',
20+
'and',
21+
'as',
22+
'assert',
23+
'break',
24+
'class',
25+
'continue',
26+
'def',
27+
'del',
28+
'elif',
29+
'else',
30+
'except',
31+
'finally',
32+
'for',
33+
'from',
34+
'global',
35+
'if',
36+
'import',
37+
'in',
38+
'is',
39+
'lambda',
40+
'nonlocal',
41+
'not',
42+
'or',
43+
'pass',
44+
'raise',
45+
'return',
46+
'try',
47+
'while',
48+
'with',
49+
'yield',
50+
#--end keywords--
51+
]
52+
53+
iskeyword = frozenset(kwlist).__contains__
54+
55+
def main():
56+
import sys, re
57+
58+
args = sys.argv[1:]
59+
iptfile = args and args[0] or "Python/graminit.c"
60+
if len(args) > 1: optfile = args[1]
61+
else: optfile = "Lib/keyword.py"
62+
63+
# scan the source file for keywords
64+
with open(iptfile) as fp:
65+
strprog = re.compile('"([^"]+)"')
66+
lines = []
67+
for line in fp:
68+
if '{1, "' in line:
69+
match = strprog.search(line)
70+
if match:
71+
lines.append(" '" + match.group(1) + "',\n")
72+
lines.sort()
73+
74+
# load the output skeleton from the target
75+
with open(optfile) as fp:
76+
format = fp.readlines()
77+
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)
86+
87+
# write the output file
88+
fp = open(optfile, 'w')
89+
fp.write(''.join(format))
90+
fp.close()
91+
92+
if __name__ == "__main__":
93+
main()

0 commit comments

Comments
 (0)