Mercurial > cpython-lru_cache-weakref
annotate Lib/token.py @ 87690:66c1c9f32567 default tip
Add use_weakref option to functools.lru_cache
The use_weakref option makes lru_cache create weak references to the function
arguments when creating the cache key, which prevents them from staying in the
memory forever even after all other references to them are gone.
This is a proof of concept for http://bugs.python.org/issue19859
| author | Radomir Dopieralski <devel@sheep.art.pl> |
|---|---|
| date | Tue, 03 Dec 2013 16:02:48 +0100 |
| parents | 7d69d04522e3 |
| children |
| rev | line source |
|---|---|
|
66148
98bd3ca1ed86
Issue #10386: Added __all__ to token module; this simplifies importing
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
59522
diff
changeset
|
1 """Token constants (from "token.h").""" |
|
11707
6f4146846337
The third and final doc-string sweep by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents:
7755
diff
changeset
|
2 |
|
66148
98bd3ca1ed86
Issue #10386: Added __all__ to token module; this simplifies importing
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
59522
diff
changeset
|
3 __all__ = ['tok_name', 'ISTERMINAL', 'ISNONTERMINAL', 'ISEOF'] |
|
11707
6f4146846337
The third and final doc-string sweep by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents:
7755
diff
changeset
|
4 |
| 4084 | 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 # | |
|
73787
0f7253d6b1cc
Fix instructions on how to rebuild some modules
Éric Araujo <merwok@netwok.org>
parents:
66148
diff
changeset
|
10 # ./python Lib/token.py |
|
1407
b9fcfb99a3e5
* test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
11 |
| 4084 | 12 #--start constants-- |
|
1407
b9fcfb99a3e5
* test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
13 ENDMARKER = 0 |
|
b9fcfb99a3e5
* test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
14 NAME = 1 |
|
b9fcfb99a3e5
* test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
15 NUMBER = 2 |
|
b9fcfb99a3e5
* test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
16 STRING = 3 |
|
b9fcfb99a3e5
* test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
17 NEWLINE = 4 |
|
b9fcfb99a3e5
* test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
18 INDENT = 5 |
|
b9fcfb99a3e5
* test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
19 DEDENT = 6 |
|
b9fcfb99a3e5
* test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
20 LPAR = 7 |
|
b9fcfb99a3e5
* test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
21 RPAR = 8 |
|
b9fcfb99a3e5
* test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
22 LSQB = 9 |
|
b9fcfb99a3e5
* test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
23 RSQB = 10 |
|
b9fcfb99a3e5
* test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
24 COLON = 11 |
|
b9fcfb99a3e5
* test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
25 COMMA = 12 |
|
b9fcfb99a3e5
* test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
26 SEMI = 13 |
|
b9fcfb99a3e5
* test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
27 PLUS = 14 |
|
b9fcfb99a3e5
* test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
28 MINUS = 15 |
|
b9fcfb99a3e5
* test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
29 STAR = 16 |
|
b9fcfb99a3e5
* test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
30 SLASH = 17 |
|
b9fcfb99a3e5
* test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
31 VBAR = 18 |
|
b9fcfb99a3e5
* test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
32 AMPER = 19 |
|
b9fcfb99a3e5
* test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
33 LESS = 20 |
|
b9fcfb99a3e5
* test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
34 GREATER = 21 |
|
b9fcfb99a3e5
* test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
35 EQUAL = 22 |
|
b9fcfb99a3e5
* test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
36 DOT = 23 |
|
b9fcfb99a3e5
* test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
37 PERCENT = 24 |
|
74421
1c0c6fa7341c
Issue #13629: Renumber the tokens in token.h to match the _PyParser_TokenNames indexes.
Meador Inge <meadori@gmail.com>
parents:
73787
diff
changeset
|
38 LBRACE = 25 |
|
1c0c6fa7341c
Issue #13629: Renumber the tokens in token.h to match the _PyParser_TokenNames indexes.
Meador Inge <meadori@gmail.com>
parents:
73787
diff
changeset
|
39 RBRACE = 26 |
|
1c0c6fa7341c
Issue #13629: Renumber the tokens in token.h to match the _PyParser_TokenNames indexes.
Meador Inge <meadori@gmail.com>
parents:
73787
diff
changeset
|
40 EQEQUAL = 27 |
|
1c0c6fa7341c
Issue #13629: Renumber the tokens in token.h to match the _PyParser_TokenNames indexes.
Meador Inge <meadori@gmail.com>
parents:
73787
diff
changeset
|
41 NOTEQUAL = 28 |
|
1c0c6fa7341c
Issue #13629: Renumber the tokens in token.h to match the _PyParser_TokenNames indexes.
Meador Inge <meadori@gmail.com>
parents:
73787
diff
changeset
|
42 LESSEQUAL = 29 |
|
1c0c6fa7341c
Issue #13629: Renumber the tokens in token.h to match the _PyParser_TokenNames indexes.
Meador Inge <meadori@gmail.com>
parents:
73787
diff
changeset
|
43 GREATEREQUAL = 30 |
|
1c0c6fa7341c
Issue #13629: Renumber the tokens in token.h to match the _PyParser_TokenNames indexes.
Meador Inge <meadori@gmail.com>
parents:
73787
diff
changeset
|
44 TILDE = 31 |
|
1c0c6fa7341c
Issue #13629: Renumber the tokens in token.h to match the _PyParser_TokenNames indexes.
Meador Inge <meadori@gmail.com>
parents:
73787
diff
changeset
|
45 CIRCUMFLEX = 32 |
|
1c0c6fa7341c
Issue #13629: Renumber the tokens in token.h to match the _PyParser_TokenNames indexes.
Meador Inge <meadori@gmail.com>
parents:
73787
diff
changeset
|
46 LEFTSHIFT = 33 |
|
1c0c6fa7341c
Issue #13629: Renumber the tokens in token.h to match the _PyParser_TokenNames indexes.
Meador Inge <meadori@gmail.com>
parents:
73787
diff
changeset
|
47 RIGHTSHIFT = 34 |
|
1c0c6fa7341c
Issue #13629: Renumber the tokens in token.h to match the _PyParser_TokenNames indexes.
Meador Inge <meadori@gmail.com>
parents:
73787
diff
changeset
|
48 DOUBLESTAR = 35 |
|
1c0c6fa7341c
Issue #13629: Renumber the tokens in token.h to match the _PyParser_TokenNames indexes.
Meador Inge <meadori@gmail.com>
parents:
73787
diff
changeset
|
49 PLUSEQUAL = 36 |
|
1c0c6fa7341c
Issue #13629: Renumber the tokens in token.h to match the _PyParser_TokenNames indexes.
Meador Inge <meadori@gmail.com>
parents:
73787
diff
changeset
|
50 MINEQUAL = 37 |
|
1c0c6fa7341c
Issue #13629: Renumber the tokens in token.h to match the _PyParser_TokenNames indexes.
Meador Inge <meadori@gmail.com>
parents:
73787
diff
changeset
|
51 STAREQUAL = 38 |
|
1c0c6fa7341c
Issue #13629: Renumber the tokens in token.h to match the _PyParser_TokenNames indexes.
Meador Inge <meadori@gmail.com>
parents:
73787
diff
changeset
|
52 SLASHEQUAL = 39 |
|
1c0c6fa7341c
Issue #13629: Renumber the tokens in token.h to match the _PyParser_TokenNames indexes.
Meador Inge <meadori@gmail.com>
parents:
73787
diff
changeset
|
53 PERCENTEQUAL = 40 |
|
1c0c6fa7341c
Issue #13629: Renumber the tokens in token.h to match the _PyParser_TokenNames indexes.
Meador Inge <meadori@gmail.com>
parents:
73787
diff
changeset
|
54 AMPEREQUAL = 41 |
|
1c0c6fa7341c
Issue #13629: Renumber the tokens in token.h to match the _PyParser_TokenNames indexes.
Meador Inge <meadori@gmail.com>
parents:
73787
diff
changeset
|
55 VBAREQUAL = 42 |
|
1c0c6fa7341c
Issue #13629: Renumber the tokens in token.h to match the _PyParser_TokenNames indexes.
Meador Inge <meadori@gmail.com>
parents:
73787
diff
changeset
|
56 CIRCUMFLEXEQUAL = 43 |
|
1c0c6fa7341c
Issue #13629: Renumber the tokens in token.h to match the _PyParser_TokenNames indexes.
Meador Inge <meadori@gmail.com>
parents:
73787
diff
changeset
|
57 LEFTSHIFTEQUAL = 44 |
|
1c0c6fa7341c
Issue #13629: Renumber the tokens in token.h to match the _PyParser_TokenNames indexes.
Meador Inge <meadori@gmail.com>
parents:
73787
diff
changeset
|
58 RIGHTSHIFTEQUAL = 45 |
|
1c0c6fa7341c
Issue #13629: Renumber the tokens in token.h to match the _PyParser_TokenNames indexes.
Meador Inge <meadori@gmail.com>
parents:
73787
diff
changeset
|
59 DOUBLESTAREQUAL = 46 |
|
1c0c6fa7341c
Issue #13629: Renumber the tokens in token.h to match the _PyParser_TokenNames indexes.
Meador Inge <meadori@gmail.com>
parents:
73787
diff
changeset
|
60 DOUBLESLASH = 47 |
|
1c0c6fa7341c
Issue #13629: Renumber the tokens in token.h to match the _PyParser_TokenNames indexes.
Meador Inge <meadori@gmail.com>
parents:
73787
diff
changeset
|
61 DOUBLESLASHEQUAL = 48 |
|
1c0c6fa7341c
Issue #13629: Renumber the tokens in token.h to match the _PyParser_TokenNames indexes.
Meador Inge <meadori@gmail.com>
parents:
73787
diff
changeset
|
62 AT = 49 |
|
1c0c6fa7341c
Issue #13629: Renumber the tokens in token.h to match the _PyParser_TokenNames indexes.
Meador Inge <meadori@gmail.com>
parents:
73787
diff
changeset
|
63 RARROW = 50 |
|
1c0c6fa7341c
Issue #13629: Renumber the tokens in token.h to match the _PyParser_TokenNames indexes.
Meador Inge <meadori@gmail.com>
parents:
73787
diff
changeset
|
64 ELLIPSIS = 51 |
|
1c0c6fa7341c
Issue #13629: Renumber the tokens in token.h to match the _PyParser_TokenNames indexes.
Meador Inge <meadori@gmail.com>
parents:
73787
diff
changeset
|
65 OP = 52 |
|
1c0c6fa7341c
Issue #13629: Renumber the tokens in token.h to match the _PyParser_TokenNames indexes.
Meador Inge <meadori@gmail.com>
parents:
73787
diff
changeset
|
66 ERRORTOKEN = 53 |
|
1c0c6fa7341c
Issue #13629: Renumber the tokens in token.h to match the _PyParser_TokenNames indexes.
Meador Inge <meadori@gmail.com>
parents:
73787
diff
changeset
|
67 N_TOKENS = 54 |
| 4084 | 68 NT_OFFSET = 256 |
| 69 #--end constants-- | |
|
1407
b9fcfb99a3e5
* test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
70 |
|
66148
98bd3ca1ed86
Issue #10386: Added __all__ to token module; this simplifies importing
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
59522
diff
changeset
|
71 tok_name = {value: name |
|
98bd3ca1ed86
Issue #10386: Added __all__ to token module; this simplifies importing
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
59522
diff
changeset
|
72 for name, value in globals().items() |
|
77013
edb9ce3a6c2e
Issue #9260: A finer-grained import lock.
Antoine Pitrou <solipsis@pitrou.net>
parents:
74421
diff
changeset
|
73 if isinstance(value, int) and not name.startswith('_')} |
|
66148
98bd3ca1ed86
Issue #10386: Added __all__ to token module; this simplifies importing
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
59522
diff
changeset
|
74 __all__.extend(tok_name.values()) |
|
1407
b9fcfb99a3e5
* test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
75 |
|
3754
d23fea248a1e
Changes for new parser module (Fred Drake)
Guido van Rossum <guido@python.org>
parents:
1407
diff
changeset
|
76 def ISTERMINAL(x): |
|
d23fea248a1e
Changes for new parser module (Fred Drake)
Guido van Rossum <guido@python.org>
parents:
1407
diff
changeset
|
77 return x < NT_OFFSET |
|
1407
b9fcfb99a3e5
* test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
78 |
|
3754
d23fea248a1e
Changes for new parser module (Fred Drake)
Guido van Rossum <guido@python.org>
parents:
1407
diff
changeset
|
79 def ISNONTERMINAL(x): |
|
d23fea248a1e
Changes for new parser module (Fred Drake)
Guido van Rossum <guido@python.org>
parents:
1407
diff
changeset
|
80 return x >= NT_OFFSET |
|
d23fea248a1e
Changes for new parser module (Fred Drake)
Guido van Rossum <guido@python.org>
parents:
1407
diff
changeset
|
81 |
|
d23fea248a1e
Changes for new parser module (Fred Drake)
Guido van Rossum <guido@python.org>
parents:
1407
diff
changeset
|
82 def ISEOF(x): |
|
d23fea248a1e
Changes for new parser module (Fred Drake)
Guido van Rossum <guido@python.org>
parents:
1407
diff
changeset
|
83 return x == ENDMARKER |
| 4084 | 84 |
| 85 | |
|
66148
98bd3ca1ed86
Issue #10386: Added __all__ to token module; this simplifies importing
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
59522
diff
changeset
|
86 def _main(): |
|
6519
24da035ceb6e
Convert all remaining *simple* cases of regex usage to re usage.
Guido van Rossum <guido@python.org>
parents:
6406
diff
changeset
|
87 import re |
| 4084 | 88 import sys |
| 89 args = sys.argv[1:] | |
| 90 inFileName = args and args[0] or "Include/token.h" | |
| 91 outFileName = "Lib/token.py" | |
| 92 if len(args) > 1: | |
|
7755
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6519
diff
changeset
|
93 outFileName = args[1] |
| 4084 | 94 try: |
|
7755
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6519
diff
changeset
|
95 fp = open(inFileName) |
|
81039
7d69d04522e3
Replace IOError with OSError (#16715)
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
77013
diff
changeset
|
96 except OSError as err: |
|
7755
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6519
diff
changeset
|
97 sys.stdout.write("I/O error: %s\n" % str(err)) |
|
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6519
diff
changeset
|
98 sys.exit(1) |
|
16514
90c600a819e9
String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents:
14165
diff
changeset
|
99 lines = fp.read().split("\n") |
| 4084 | 100 fp.close() |
|
6519
24da035ceb6e
Convert all remaining *simple* cases of regex usage to re usage.
Guido van Rossum <guido@python.org>
parents:
6406
diff
changeset
|
101 prog = re.compile( |
|
25537
61d624f5c107
Updates to track Grammar changes. The patch to token.py loosens the regexp to
Michael W. Hudson <mwh@python.net>
parents:
19229
diff
changeset
|
102 "#define[ \t][ \t]*([A-Z0-9][A-Z0-9_]*)[ \t][ \t]*([0-9][0-9]*)", |
|
7755
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6519
diff
changeset
|
103 re.IGNORECASE) |
| 4084 | 104 tokens = {} |
| 105 for line in lines: | |
|
7755
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6519
diff
changeset
|
106 match = prog.match(line) |
|
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6519
diff
changeset
|
107 if match: |
|
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6519
diff
changeset
|
108 name, val = match.group(1, 2) |
| 16548 | 109 val = int(val) |
|
7755
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6519
diff
changeset
|
110 tokens[val] = name # reverse so we can sort them... |
|
40928
7bc7f740f69f
Use better idiom to sort keys.
Guido van Rossum <guido@python.org>
parents:
40921
diff
changeset
|
111 keys = sorted(tokens.keys()) |
| 4084 | 112 # load the output skeleton from the target: |
| 113 try: | |
|
7755
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6519
diff
changeset
|
114 fp = open(outFileName) |
|
81039
7d69d04522e3
Replace IOError with OSError (#16715)
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
77013
diff
changeset
|
115 except OSError as err: |
|
7755
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6519
diff
changeset
|
116 sys.stderr.write("I/O error: %s\n" % str(err)) |
|
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6519
diff
changeset
|
117 sys.exit(2) |
|
16514
90c600a819e9
String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents:
14165
diff
changeset
|
118 format = fp.read().split("\n") |
| 4084 | 119 fp.close() |
| 120 try: | |
|
7755
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6519
diff
changeset
|
121 start = format.index("#--start constants--") + 1 |
|
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6519
diff
changeset
|
122 end = format.index("#--end constants--") |
| 4084 | 123 except ValueError: |
|
7755
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6519
diff
changeset
|
124 sys.stderr.write("target does not contain format markers") |
|
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6519
diff
changeset
|
125 sys.exit(3) |
| 4084 | 126 lines = [] |
| 127 for val in keys: | |
|
7755
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6519
diff
changeset
|
128 lines.append("%s = %d" % (tokens[val], val)) |
| 4084 | 129 format[start:end] = lines |
| 130 try: | |
|
7755
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6519
diff
changeset
|
131 fp = open(outFileName, 'w') |
|
81039
7d69d04522e3
Replace IOError with OSError (#16715)
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
77013
diff
changeset
|
132 except OSError as err: |
|
7755
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6519
diff
changeset
|
133 sys.stderr.write("I/O error: %s\n" % str(err)) |
|
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6519
diff
changeset
|
134 sys.exit(4) |
|
16514
90c600a819e9
String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents:
14165
diff
changeset
|
135 fp.write("\n".join(format)) |
| 4084 | 136 fp.close() |
| 137 | |
| 138 | |
| 139 if __name__ == "__main__": | |
|
66148
98bd3ca1ed86
Issue #10386: Added __all__ to token module; this simplifies importing
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
59522
diff
changeset
|
140 _main() |
