ยปCore Development>Code coverage>Lib/keyword.py

Python code coverage for Lib/keyword.py

#countcontent
1n/a#! /usr/bin/env python3
2n/a
3n/a"""Keywords (from "graminit.c")
4n/a
5n/aThis file is automatically generated; please don't muck it up!
6n/a
7n/aTo update the symbols in this file, 'cd' to the top directory of
8n/athe python source tree after building the interpreter and run:
9n/a
10n/a ./python Lib/keyword.py
11n/a"""
12n/a
13n/a__all__ = ["iskeyword", "kwlist"]
14n/a
15n/akwlist = [
16n/a#--start keywords--
17n/a 'False',
18n/a 'None',
19n/a 'True',
20n/a 'and',
21n/a 'as',
22n/a 'assert',
23n/a 'break',
24n/a 'class',
25n/a 'continue',
26n/a 'def',
27n/a 'del',
28n/a 'elif',
29n/a 'else',
30n/a 'except',
31n/a 'finally',
32n/a 'for',
33n/a 'from',
34n/a 'global',
35n/a 'if',
36n/a 'import',
37n/a 'in',
38n/a 'is',
39n/a 'lambda',
40n/a 'nonlocal',
41n/a 'not',
42n/a 'or',
43n/a 'pass',
44n/a 'raise',
45n/a 'return',
46n/a 'try',
47n/a 'while',
48n/a 'with',
49n/a 'yield',
50n/a#--end keywords--
51n/a ]
52n/a
53n/aiskeyword = frozenset(kwlist).__contains__
54n/a
55n/adef main():
56n/a import sys, re
57n/a
58n/a args = sys.argv[1:]
59n/a iptfile = args and args[0] or "Python/graminit.c"
60n/a if len(args) > 1: optfile = args[1]
61n/a else: optfile = "Lib/keyword.py"
62n/a
63n/a # load the output skeleton from the target, taking care to preserve its
64n/a # newline convention.
65n/a with open(optfile, newline='') as fp:
66n/a format = fp.readlines()
67n/a nl = format[0][len(format[0].strip()):] if format else '\n'
68n/a
69n/a # scan the source file for keywords
70n/a with open(iptfile) as fp:
71n/a strprog = re.compile('"([^"]+)"')
72n/a lines = []
73n/a for line in fp:
74n/a if '{1, "' in line:
75n/a match = strprog.search(line)
76n/a if match:
77n/a lines.append(" '" + match.group(1) + "'," + nl)
78n/a lines.sort()
79n/a
80n/a # insert the lines of keywords into the skeleton
81n/a try:
82n/a start = format.index("#--start keywords--" + nl) + 1
83n/a end = format.index("#--end keywords--" + nl)
84n/a format[start:end] = lines
85n/a except ValueError:
86n/a sys.stderr.write("target does not contain format markers\n")
87n/a sys.exit(1)
88n/a
89n/a # write the output file
90n/a with open(optfile, 'w', newline='') as fp:
91n/a fp.writelines(format)
92n/a
93n/aif __name__ == "__main__":
94n/a main()