#! /usr/bin/python2.7 # Released to the public domain, by Tim Peters, 28 February 2000. """checkappend.py -- search for multi-argument .append() calls. Usage: specify one or more file or directory paths: checkappend [-v] file_or_dir [file_or_dir] ... Each file_or_dir is checked for multi-argument .append() calls. When a directory, all .py files in the directory, and recursively in its subdirectories, are checked. Use -v for status msgs. Use -vv for more status msgs. In the absence of -v, the only output is pairs of the form filename(linenumber): line containing the suspicious append Note that this finds multi-argument append calls regardless of whether they're attached to list objects. If a module defines a class with an append method that takes more than one argument, calls to that method will be listed. Note that this will not find multi-argument list.append calls made via a bound method object. For example, this is not caught: somelist = [] push = somelist.append push(1, 2, 3) """ __version__ = 1, 0, 0 import os import sys import getopt import tokenize verbose = 0 def errprint(*args): msg = ' '.join(args) sys.stderr.write(msg) sys.stderr.write("\n") def main(): args = sys.argv[1:] global verbose try: opts, args = getopt.getopt(sys.argv[1:], "v") except getopt.error, msg: errprint(str(msg) + "\n\n" + __doc__) return for opt, optarg in opts: if opt == '-v': verbose = verbose + 1 if not args: errprint(__doc__) return for arg in args: check(arg) def check(file): if os.path.isdir(file) and not os.path.islink(file): if verbose: print "%r: listing directory" % (file,) names = os.listdir(file) for name in names: fullname = os.path.join(file, name) if ((os.path.isdir(fullname) and not os.path.islink(fullname)) or os.path.normcase(name[-3:]) == ".py"): check(fullname) return try: f = open(file) except IOError, msg: errprint("%r: I/O Error: %s" % (file, msg)) return if verbose > 1: print "checking %r ..." % (file,) ok = AppendChecker(file, f).run() if verbose and ok: print "%r: Clean bill of health." % (file,) [FIND_DOT, FIND_APPEND, FIND_LPAREN, FIND_COMMA, FIND_STMT] = range(5) class AppendChecker: def __init__(self, fname, file): self.fname = fname self.file = file self.state = FIND_DOT self.nerrors = 0 def run(self): try: tokenize.tokenize(self.file.readline, self.tokeneater) except tokenize.TokenError, msg: errprint("%r: Token Error: %s" % (self.fname, msg)) self.nerrors = self.nerrors + 1 return self.nerrors == 0 def tokeneater(self, type, token, start, end, line, NEWLINE=tokenize.NEWLINE, JUNK=(tokenize.COMMENT, tokenize.NL), OP=tokenize.OP, NAME=tokenize.NAME): state = self.state if type in JUNK: pass elif state is FIND_DOT: if type is OP and token == ".": state = FIND_APPEND elif state is FIND_APPEND: if type is NAME and token == "append": self.line = line self.lineno = start[0] state = FIND_LPAREN else: state = FIND_DOT elif state is FIND_LPAREN: if type is OP and token == "(": self.level = 1 state = FIND_COMMA else: state = FIND_DOT elif state is FIND_COMMA: if type is OP: if token in ("(", "{", "["): self.level = self.level + 1 elif token in (")", "}", "]"): self.level = self.level - 1 if self.level == 0: state = FIND_DOT elif token == "," and self.level == 1: self.nerrors = self.nerrors + 1 print "%s(%d):\n%s" % (self.fname, self.lineno, self.line) # don't gripe about this stmt again state = FIND_STMT elif state is FIND_STMT: if type is NEWLINE: state = FIND_DOT else: raise SystemError("unknown internal state '%r'" % (state,)) self.state = state if __name__ == '__main__': main()
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
analyze_dxp.py | File | 4.11 KB | 0755 |
|
analyze_dxp.pyc | File | 4.64 KB | 0644 |
|
analyze_dxp.pyo | File | 4.64 KB | 0644 |
|
byext.py | File | 3.85 KB | 0755 |
|
byext.pyc | File | 4.42 KB | 0644 |
|
byext.pyo | File | 4.42 KB | 0644 |
|
byteyears.py | File | 1.6 KB | 0755 |
|
byteyears.pyc | File | 1.37 KB | 0644 |
|
byteyears.pyo | File | 1.37 KB | 0644 |
|
checkappend.py | File | 4.55 KB | 0755 |
|
checkappend.pyc | File | 4.77 KB | 0644 |
|
checkappend.pyo | File | 4.77 KB | 0644 |
|
checkpip.py | File | 757 B | 0755 |
|
checkpip.pyc | File | 1.02 KB | 0644 |
|
checkpip.pyo | File | 1.02 KB | 0644 |
|
checkpyc.py | File | 1.96 KB | 0755 |
|
checkpyc.pyc | File | 1.93 KB | 0644 |
|
checkpyc.pyo | File | 1.93 KB | 0644 |
|
classfix.py | File | 5.81 KB | 0755 |
|
classfix.pyc | File | 4.09 KB | 0644 |
|
classfix.pyo | File | 4.09 KB | 0644 |
|
cleanfuture.py | File | 8.38 KB | 0755 |
|
cleanfuture.pyc | File | 7.22 KB | 0644 |
|
cleanfuture.pyo | File | 7.19 KB | 0644 |
|
combinerefs.py | File | 4.28 KB | 0755 |
|
combinerefs.pyc | File | 4.16 KB | 0644 |
|
combinerefs.pyo | File | 4.12 KB | 0644 |
|
copytime.py | File | 663 B | 0755 |
|
copytime.pyc | File | 937 B | 0644 |
|
copytime.pyo | File | 937 B | 0644 |
|
crlf.py | File | 610 B | 0755 |
|
crlf.pyc | File | 855 B | 0644 |
|
crlf.pyo | File | 855 B | 0644 |
|
cvsfiles.py | File | 1.74 KB | 0755 |
|
cvsfiles.pyc | File | 2.11 KB | 0644 |
|
cvsfiles.pyo | File | 2.11 KB | 0644 |
|
db2pickle.py | File | 3.49 KB | 0755 |
|
db2pickle.pyc | File | 3.42 KB | 0644 |
|
db2pickle.pyo | File | 3.42 KB | 0644 |
|
diff.py | File | 2.02 KB | 0755 |
|
diff.pyc | File | 2.33 KB | 0644 |
|
diff.pyo | File | 2.33 KB | 0644 |
|
dutree.py | File | 1.58 KB | 0755 |
|
dutree.pyc | File | 2.18 KB | 0644 |
|
dutree.pyo | File | 2.18 KB | 0644 |
|
eptags.py | File | 1.45 KB | 0755 |
|
eptags.pyc | File | 1.83 KB | 0644 |
|
eptags.pyo | File | 1.83 KB | 0644 |
|
find_recursionlimit.py | File | 3.39 KB | 0755 |
|
find_recursionlimit.pyc | File | 5.54 KB | 0644 |
|
find_recursionlimit.pyo | File | 5.54 KB | 0644 |
|
finddiv.py | File | 2.46 KB | 0755 |
|
finddiv.pyc | File | 3.22 KB | 0644 |
|
finddiv.pyo | File | 3.22 KB | 0644 |
|
findlinksto.py | File | 1.04 KB | 0755 |
|
findlinksto.pyc | File | 1.39 KB | 0644 |
|
findlinksto.pyo | File | 1.39 KB | 0644 |
|
findnocoding.py | File | 2.74 KB | 0755 |
|
findnocoding.pyc | File | 3.13 KB | 0644 |
|
findnocoding.pyo | File | 3.13 KB | 0644 |
|
fixcid.py | File | 9.76 KB | 0755 |
|
fixcid.pyc | File | 7.67 KB | 0644 |
|
fixcid.pyo | File | 7.67 KB | 0644 |
|
fixdiv.py | File | 13.52 KB | 0755 |
|
fixdiv.pyc | File | 13.52 KB | 0644 |
|
fixdiv.pyo | File | 13.44 KB | 0644 |
|
fixheader.py | File | 1.16 KB | 0755 |
|
fixheader.pyc | File | 1.44 KB | 0644 |
|
fixheader.pyo | File | 1.44 KB | 0644 |
|
fixnotice.py | File | 2.98 KB | 0755 |
|
fixnotice.pyc | File | 3.42 KB | 0644 |
|
fixnotice.pyo | File | 3.42 KB | 0644 |
|
fixps.py | File | 893 B | 0755 |
|
fixps.pyc | File | 969 B | 0644 |
|
fixps.pyo | File | 969 B | 0644 |
|
google.py | File | 519 B | 0755 |
|
google.pyc | File | 792 B | 0644 |
|
google.pyo | File | 792 B | 0644 |
|
gprof2html.py | File | 2.12 KB | 0755 |
|
gprof2html.pyc | File | 2.22 KB | 0644 |
|
gprof2html.pyo | File | 2.22 KB | 0644 |
|
h2py.py | File | 5.81 KB | 0755 |
|
h2py.pyc | File | 4.29 KB | 0644 |
|
h2py.pyo | File | 4.29 KB | 0644 |
|
hotshotmain.py | File | 1.45 KB | 0755 |
|
hotshotmain.pyc | File | 1.82 KB | 0644 |
|
hotshotmain.pyo | File | 1.82 KB | 0644 |
|
ifdef.py | File | 3.63 KB | 0755 |
|
ifdef.pyc | File | 2.21 KB | 0644 |
|
ifdef.pyo | File | 2.21 KB | 0644 |
|
lfcr.py | File | 618 B | 0755 |
|
lfcr.pyc | File | 880 B | 0644 |
|
lfcr.pyo | File | 880 B | 0644 |
|
linktree.py | File | 2.37 KB | 0755 |
|
linktree.pyc | File | 1.98 KB | 0644 |
|
linktree.pyo | File | 1.98 KB | 0644 |
|
lll.py | File | 742 B | 0755 |
|
lll.pyc | File | 942 B | 0644 |
|
lll.pyo | File | 942 B | 0644 |
|
logmerge.py | File | 5.44 KB | 0755 |
|
logmerge.pyc | File | 4.96 KB | 0644 |
|
logmerge.pyo | File | 4.96 KB | 0644 |
|
mailerdaemon.py | File | 7.76 KB | 0755 |
|
mailerdaemon.pyc | File | 7.19 KB | 0644 |
|
mailerdaemon.pyo | File | 7.19 KB | 0644 |
|
md5sum.py | File | 2.33 KB | 0755 |
|
md5sum.pyc | File | 2.85 KB | 0644 |
|
md5sum.pyo | File | 2.85 KB | 0644 |
|
methfix.py | File | 5.33 KB | 0755 |
|
methfix.pyc | File | 4.03 KB | 0644 |
|
methfix.pyo | File | 4.03 KB | 0644 |
|
mkreal.py | File | 1.59 KB | 0755 |
|
mkreal.pyc | File | 1.93 KB | 0644 |
|
mkreal.pyo | File | 1.93 KB | 0644 |
|
ndiff.py | File | 3.72 KB | 0755 |
|
ndiff.pyc | File | 3.77 KB | 0644 |
|
ndiff.pyo | File | 3.77 KB | 0644 |
|
nm2def.py | File | 2.39 KB | 0755 |
|
nm2def.pyc | File | 2.89 KB | 0644 |
|
nm2def.pyo | File | 2.89 KB | 0644 |
|
objgraph.py | File | 5.88 KB | 0755 |
|
objgraph.pyc | File | 4.82 KB | 0644 |
|
objgraph.pyo | File | 4.82 KB | 0644 |
|
parseentities.py | File | 1.68 KB | 0755 |
|
parseentities.pyc | File | 2.03 KB | 0644 |
|
parseentities.pyo | File | 2.03 KB | 0644 |
|
patchcheck.py | File | 7.5 KB | 0755 |
|
patchcheck.pyc | File | 8.91 KB | 0644 |
|
patchcheck.pyo | File | 8.91 KB | 0644 |
|
pathfix.py | File | 4.23 KB | 0755 |
|
pathfix.pyc | File | 3.75 KB | 0644 |
|
pathfix.pyo | File | 3.75 KB | 0644 |
|
pdeps.py | File | 3.84 KB | 0755 |
|
pdeps.pyc | File | 3.14 KB | 0644 |
|
pdeps.pyo | File | 3.14 KB | 0644 |
|
pickle2db.py | File | 3.85 KB | 0755 |
|
pickle2db.pyc | File | 3.73 KB | 0644 |
|
pickle2db.pyo | File | 3.73 KB | 0644 |
|
pindent.py | File | 16.77 KB | 0755 |
|
pindent.pyc | File | 11.29 KB | 0644 |
|
pindent.pyo | File | 11.29 KB | 0644 |
|
ptags.py | File | 1.2 KB | 0755 |
|
ptags.pyc | File | 1.37 KB | 0644 |
|
ptags.pyo | File | 1.37 KB | 0644 |
|
pysource.py | File | 3.76 KB | 0755 |
|
pysource.pyc | File | 3.92 KB | 0644 |
|
pysource.pyo | File | 3.92 KB | 0644 |
|
redemo.py | File | 5.66 KB | 0755 |
|
redemo.pyc | File | 5.13 KB | 0644 |
|
redemo.pyo | File | 5.13 KB | 0644 |
|
reindent-rst.py | File | 278 B | 0755 |
|
reindent-rst.pyc | File | 481 B | 0644 |
|
reindent-rst.pyo | File | 481 B | 0644 |
|
reindent.py | File | 11.15 KB | 0755 |
|
reindent.pyc | File | 9.4 KB | 0644 |
|
reindent.pyo | File | 9.37 KB | 0644 |
|
rgrep.py | File | 1.46 KB | 0755 |
|
rgrep.pyc | File | 1.84 KB | 0644 |
|
rgrep.pyo | File | 1.84 KB | 0644 |
|
serve.py | File | 1.12 KB | 0755 |
|
serve.pyc | File | 1.56 KB | 0644 |
|
serve.pyo | File | 1.56 KB | 0644 |
|
setup.py | File | 421 B | 0644 |
|
setup.pyc | File | 548 B | 0644 |
|
setup.pyo | File | 548 B | 0644 |
|
suff.py | File | 621 B | 0755 |
|
suff.pyc | File | 904 B | 0644 |
|
suff.pyo | File | 904 B | 0644 |
|
svneol.py | File | 2.86 KB | 0755 |
|
svneol.pyc | File | 2.84 KB | 0644 |
|
svneol.pyo | File | 2.76 KB | 0644 |
|
texcheck.py | File | 9.04 KB | 0644 |
|
texcheck.pyc | File | 8.18 KB | 0644 |
|
texcheck.pyo | File | 8.18 KB | 0644 |
|
texi2html.py | File | 68.19 KB | 0755 |
|
texi2html.pyc | File | 81.37 KB | 0644 |
|
texi2html.pyo | File | 81.37 KB | 0644 |
|
treesync.py | File | 5.65 KB | 0755 |
|
treesync.pyc | File | 5.85 KB | 0644 |
|
treesync.pyo | File | 5.85 KB | 0644 |
|
untabify.py | File | 1.19 KB | 0755 |
|
untabify.pyc | File | 1.55 KB | 0644 |
|
untabify.pyo | File | 1.55 KB | 0644 |
|
which.py | File | 1.59 KB | 0755 |
|
which.pyc | File | 1.59 KB | 0644 |
|
which.pyo | File | 1.59 KB | 0644 |
|
win_add2path.py | File | 1.58 KB | 0644 |
|
win_add2path.pyc | File | 2.02 KB | 0644 |
|
win_add2path.pyo | File | 2.02 KB | 0644 |
|
xxci.py | File | 2.73 KB | 0755 |
|
xxci.pyc | File | 3.92 KB | 0644 |
|
xxci.pyo | File | 3.92 KB | 0644 |
|