annotate Lib/keyword.py @ 79675:c0a2294de787 2.7

Issue #16199: Backport 2to3 typo fix from 3.2.
author Chris Jerdonek <chris.jerdonek@gmail.com>
date Thu, 11 Oct 2012 16:15:46 -0700
parents 05a808bc6867
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5204
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
1 #! /usr/bin/env python
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 7755
diff changeset
2
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 7755
diff changeset
3 """Keywords (from "graminit.c")
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 7755
diff changeset
4
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 7755
diff changeset
5 This file is automatically generated; please don't muck it up!
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 7755
diff changeset
6
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 7755
diff changeset
7 To update the symbols in this file, 'cd' to the top directory of
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 7755
diff changeset
8 the python source tree after building the interpreter and run:
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 7755
diff changeset
9
75268
05a808bc6867 Fix instructions on how to rebuild some modules
Éric Araujo <merwok@netwok.org>
parents: 44847
diff changeset
10 ./python Lib/keyword.py
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 7755
diff changeset
11 """
5203
05c7d8b4ffd6 Simple module to publish list of Python keywords.
Guido van Rossum <guido@python.org>
parents:
diff changeset
12
25949
36d418bea552 Patrick K. O'Brien notices that kwlist was missing from __all__.
Raymond Hettinger <python@rcn.com>
parents: 18152
diff changeset
13 __all__ = ["iskeyword", "kwlist"]
16198
32755b456369 a few more modules get __all__
Skip Montanaro <skip@pobox.com>
parents: 11706
diff changeset
14
5204
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
15 kwlist = [
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
16 #--start keywords--
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
17 'and',
36744
a2138dfb5965 Regenerate.
Thomas Wouters <thomas@python.org>
parents: 31967
diff changeset
18 'as',
5895
46cd352c7638 Regenerated; __assert__ becomes assert.
Guido van Rossum <guido@python.org>
parents: 5206
diff changeset
19 'assert',
5204
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
20 'break',
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
21 'class',
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
22 'continue',
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
23 'def',
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
24 'del',
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
25 'elif',
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
26 'else',
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
27 'except',
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
28 'exec',
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
29 'finally',
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
30 'for',
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
31 'from',
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
32 'global',
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
33 'if',
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
34 'import',
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
35 'in',
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
36 'is',
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
37 'lambda',
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
38 'not',
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
39 'or',
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
40 'pass',
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
41 'print',
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
42 'raise',
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
43 'return',
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
44 'try',
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
45 'while',
36744
a2138dfb5965 Regenerate.
Thomas Wouters <thomas@python.org>
parents: 31967
diff changeset
46 'with',
18152
54f76293d926 Updated keyword.py for "yield".
Tim Peters <tim.peters@gmail.com>
parents: 16496
diff changeset
47 'yield',
5204
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
48 #--end keywords--
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
49 ]
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
50
31061
4e31c261a668 SF patch #852140: keyword.py - use __contains__ and bool
Raymond Hettinger <python@rcn.com>
parents: 25949
diff changeset
51 iskeyword = frozenset(kwlist).__contains__
5204
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
52
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
53 def main():
16496
1ff9d571bac0 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16198
diff changeset
54 import sys, re
5203
05c7d8b4ffd6 Simple module to publish list of Python keywords.
Guido van Rossum <guido@python.org>
parents:
diff changeset
55
5204
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
56 args = sys.argv[1:]
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
57 iptfile = args and args[0] or "Python/graminit.c"
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
58 if len(args) > 1: optfile = args[1]
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
59 else: optfile = "Lib/keyword.py"
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
60
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
61 # scan the source file for keywords
5206
bd5e2c2c1e08 Ping's new version -- more efficient at finding the keywords.
Guido van Rossum <guido@python.org>
parents: 5205
diff changeset
62 fp = open(iptfile)
6519
24da035ceb6e Convert all remaining *simple* cases of regex usage to re usage.
Guido van Rossum <guido@python.org>
parents: 5895
diff changeset
63 strprog = re.compile('"([^"]+)"')
5206
bd5e2c2c1e08 Ping's new version -- more efficient at finding the keywords.
Guido van Rossum <guido@python.org>
parents: 5205
diff changeset
64 lines = []
44847
a6b190b0cf06 #1726198: replace while 1: fp.readline() with file iteration.
Georg Brandl <georg@python.org>
parents: 36744
diff changeset
65 for line in fp:
31967
3d046d063a84 Replace str.find()!=1 with the more readable "in" operator.
Raymond Hettinger <python@rcn.com>
parents: 31061
diff changeset
66 if '{1, "' in line:
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6519
diff changeset
67 match = strprog.search(line)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6519
diff changeset
68 if match:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6519
diff changeset
69 lines.append(" '" + match.group(1) + "',\n")
5206
bd5e2c2c1e08 Ping's new version -- more efficient at finding the keywords.
Guido van Rossum <guido@python.org>
parents: 5205
diff changeset
70 fp.close()
bd5e2c2c1e08 Ping's new version -- more efficient at finding the keywords.
Guido van Rossum <guido@python.org>
parents: 5205
diff changeset
71 lines.sort()
bd5e2c2c1e08 Ping's new version -- more efficient at finding the keywords.
Guido van Rossum <guido@python.org>
parents: 5205
diff changeset
72
bd5e2c2c1e08 Ping's new version -- more efficient at finding the keywords.
Guido van Rossum <guido@python.org>
parents: 5205
diff changeset
73 # load the output skeleton from the target
bd5e2c2c1e08 Ping's new version -- more efficient at finding the keywords.
Guido van Rossum <guido@python.org>
parents: 5205
diff changeset
74 fp = open(optfile)
bd5e2c2c1e08 Ping's new version -- more efficient at finding the keywords.
Guido van Rossum <guido@python.org>
parents: 5205
diff changeset
75 format = fp.readlines()
5204
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
76 fp.close()
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
77
5206
bd5e2c2c1e08 Ping's new version -- more efficient at finding the keywords.
Guido van Rossum <guido@python.org>
parents: 5205
diff changeset
78 # insert the lines of keywords
5204
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
79 try:
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
80 start = format.index("#--start keywords--\n") + 1
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
81 end = format.index("#--end keywords--\n")
5206
bd5e2c2c1e08 Ping's new version -- more efficient at finding the keywords.
Guido van Rossum <guido@python.org>
parents: 5205
diff changeset
82 format[start:end] = lines
5204
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
83 except ValueError:
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
84 sys.stderr.write("target does not contain format markers\n")
5206
bd5e2c2c1e08 Ping's new version -- more efficient at finding the keywords.
Guido van Rossum <guido@python.org>
parents: 5205
diff changeset
85 sys.exit(1)
5204
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
86
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
87 # write the output file
5206
bd5e2c2c1e08 Ping's new version -- more efficient at finding the keywords.
Guido van Rossum <guido@python.org>
parents: 5205
diff changeset
88 fp = open(optfile, 'w')
16496
1ff9d571bac0 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16198
diff changeset
89 fp.write(''.join(format))
5204
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
90 fp.close()
c248a07e5341 Ka-Ping Yee's version is better:
Guido van Rossum <guido@python.org>
parents: 5203
diff changeset
91
6519
24da035ceb6e Convert all remaining *simple* cases of regex usage to re usage.
Guido van Rossum <guido@python.org>
parents: 5895
diff changeset
92 if __name__ == "__main__":
24da035ceb6e Convert all remaining *simple* cases of regex usage to re usage.
Guido van Rossum <guido@python.org>
parents: 5895
diff changeset
93 main()