Mercurial > cpython-lru_cache-weakref
annotate Tools/scripts/checkappend.py @ 49955:878d40468c4e legacy-trunk
Issue #4384: Added logging integration with warnings module using captureWarnings(). This change includes a NullHandler which does nothing; it will be of use to library developers who want to avoid the "No handlers could be found for logger XXX" message which can appear if the library user doesn't configure logging.
| author | Vinay Sajip <vinay_sajip@yahoo.co.uk> |
|---|---|
| date | Wed, 03 Dec 2008 23:22:58 +0000 |
| parents | 71a294bd7950 |
| children | 6b18a095c2e7 |
| rev | line source |
|---|---|
|
11879
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 #! /usr/bin/env python |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2 |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
3 # Released to the public domain, by Tim Peters, 28 February 2000. |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
4 |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
5 """checkappend.py -- search for multi-argument .append() calls. |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
6 |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
7 Usage: specify one or more file or directory paths: |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
8 checkappend [-v] file_or_dir [file_or_dir] ... |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
9 |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
10 Each file_or_dir is checked for multi-argument .append() calls. When |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
11 a directory, all .py files in the directory, and recursively in its |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
12 subdirectories, are checked. |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
13 |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
14 Use -v for status msgs. Use -vv for more status msgs. |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
15 |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
16 In the absence of -v, the only output is pairs of the form |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
17 |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
18 filename(linenumber): |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
19 line containing the suspicious append |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
20 |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
21 Note that this finds multi-argument append calls regardless of whether |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
22 they're attached to list objects. If a module defines a class with an |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
23 append method that takes more than one argument, calls to that method |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
24 will be listed. |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
25 |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
26 Note that this will not find multi-argument list.append calls made via a |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
27 bound method object. For example, this is not caught: |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
28 |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
29 somelist = [] |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
30 push = somelist.append |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
31 push(1, 2, 3) |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
32 """ |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
33 |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
34 __version__ = 1, 0, 0 |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
35 |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
36 import os |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
37 import sys |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
38 import getopt |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
39 import tokenize |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
40 |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
41 verbose = 0 |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
42 |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
43 def errprint(*args): |
|
25219
8a7a2f1f88f0
Apply diff2.txt from SF patch http://www.python.org/sf/572113
Walter Dörwald <walter@livinglogic.de>
parents:
11880
diff
changeset
|
44 msg = ' '.join(args) |
|
11879
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
45 sys.stderr.write(msg) |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
46 sys.stderr.write("\n") |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
47 |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
48 def main(): |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
49 args = sys.argv[1:] |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
50 global verbose |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
51 try: |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
52 opts, args = getopt.getopt(sys.argv[1:], "v") |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
53 except getopt.error, msg: |
|
11880
d27684ab215a
Correct type error in getopt.error handling code.
Guido van Rossum <guido@python.org>
parents:
11879
diff
changeset
|
54 errprint(str(msg) + "\n\n" + __doc__) |
|
11879
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
55 return |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
56 for opt, optarg in opts: |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
57 if opt == '-v': |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
58 verbose = verbose + 1 |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
59 if not args: |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
60 errprint(__doc__) |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
61 return |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
62 for arg in args: |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
63 check(arg) |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
64 |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
65 def check(file): |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
66 if os.path.isdir(file) and not os.path.islink(file): |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
67 if verbose: |
|
31515
71a294bd7950
Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents:
25219
diff
changeset
|
68 print "%r: listing directory" % (file,) |
|
11879
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
69 names = os.listdir(file) |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
70 for name in names: |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
71 fullname = os.path.join(file, name) |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
72 if ((os.path.isdir(fullname) and |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
73 not os.path.islink(fullname)) |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
74 or os.path.normcase(name[-3:]) == ".py"): |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
75 check(fullname) |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
76 return |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
77 |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
78 try: |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
79 f = open(file) |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
80 except IOError, msg: |
|
31515
71a294bd7950
Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents:
25219
diff
changeset
|
81 errprint("%r: I/O Error: %s" % (file, msg)) |
|
11879
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
82 return |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
83 |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
84 if verbose > 1: |
|
31515
71a294bd7950
Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents:
25219
diff
changeset
|
85 print "checking %r ..." % (file,) |
|
11879
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
86 |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
87 ok = AppendChecker(file, f).run() |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
88 if verbose and ok: |
|
31515
71a294bd7950
Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents:
25219
diff
changeset
|
89 print "%r: Clean bill of health." % (file,) |
|
11879
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
90 |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
91 [FIND_DOT, |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
92 FIND_APPEND, |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
93 FIND_LPAREN, |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
94 FIND_COMMA, |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
95 FIND_STMT] = range(5) |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
96 |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
97 class AppendChecker: |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
98 def __init__(self, fname, file): |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
99 self.fname = fname |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
100 self.file = file |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
101 self.state = FIND_DOT |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
102 self.nerrors = 0 |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
103 |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
104 def run(self): |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
105 try: |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
106 tokenize.tokenize(self.file.readline, self.tokeneater) |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
107 except tokenize.TokenError, msg: |
|
31515
71a294bd7950
Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents:
25219
diff
changeset
|
108 errprint("%r: Token Error: %s" % (self.fname, msg)) |
|
11879
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
109 self.nerrors = self.nerrors + 1 |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
110 return self.nerrors == 0 |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
111 |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
112 def tokeneater(self, type, token, start, end, line, |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
113 NEWLINE=tokenize.NEWLINE, |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
114 JUNK=(tokenize.COMMENT, tokenize.NL), |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
115 OP=tokenize.OP, |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
116 NAME=tokenize.NAME): |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
117 |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
118 state = self.state |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
119 |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
120 if type in JUNK: |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
121 pass |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
122 |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
123 elif state is FIND_DOT: |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
124 if type is OP and token == ".": |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
125 state = FIND_APPEND |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
126 |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
127 elif state is FIND_APPEND: |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
128 if type is NAME and token == "append": |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
129 self.line = line |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
130 self.lineno = start[0] |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
131 state = FIND_LPAREN |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
132 else: |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
133 state = FIND_DOT |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
134 |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
135 elif state is FIND_LPAREN: |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
136 if type is OP and token == "(": |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
137 self.level = 1 |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
138 state = FIND_COMMA |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
139 else: |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
140 state = FIND_DOT |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
141 |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
142 elif state is FIND_COMMA: |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
143 if type is OP: |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
144 if token in ("(", "{", "["): |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
145 self.level = self.level + 1 |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
146 elif token in (")", "}", "]"): |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
147 self.level = self.level - 1 |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
148 if self.level == 0: |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
149 state = FIND_DOT |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
150 elif token == "," and self.level == 1: |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
151 self.nerrors = self.nerrors + 1 |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
152 print "%s(%d):\n%s" % (self.fname, self.lineno, |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
153 self.line) |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
154 # don't gripe about this stmt again |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
155 state = FIND_STMT |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
156 |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
157 elif state is FIND_STMT: |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
158 if type is NEWLINE: |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
159 state = FIND_DOT |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
160 |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
161 else: |
|
31515
71a294bd7950
Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents:
25219
diff
changeset
|
162 raise SystemError("unknown internal state '%r'" % (state,)) |
|
11879
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
163 |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
164 self.state = state |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
165 |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
166 if __name__ == '__main__': |
|
a7d609ea90cc
Script by Tim Peters to discover illegal append() calls.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
167 main() |
