Current Path: > > lib64 > python2.7 > Tools > > scripts
Operation : Linux premium131.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64 Software : Apache Server IP : 162.0.232.56 | Your IP: 216.73.216.111 Domains : 1034 Domain(s) Permission : [ 0755 ]
Name | Type | Size | Last Modified | Actions |
---|---|---|---|---|
analyze_dxp.py | File | 4205 bytes | April 10 2024 04:58:41. | |
analyze_dxp.pyc | File | 4748 bytes | April 10 2024 04:58:46. | |
analyze_dxp.pyo | File | 4748 bytes | April 10 2024 04:58:46. | |
byext.py | File | 3944 bytes | April 10 2024 04:58:41. | |
byext.pyc | File | 4521 bytes | April 10 2024 04:58:46. | |
byext.pyo | File | 4521 bytes | April 10 2024 04:58:46. | |
byteyears.py | File | 1637 bytes | April 10 2024 04:58:41. | |
byteyears.pyc | File | 1398 bytes | April 10 2024 04:58:46. | |
byteyears.pyo | File | 1398 bytes | April 10 2024 04:58:46. | |
checkappend.py | File | 4657 bytes | April 10 2024 04:58:41. | |
checkappend.pyc | File | 4886 bytes | April 10 2024 04:58:46. | |
checkappend.pyo | File | 4886 bytes | April 10 2024 04:58:46. | |
checkpip.py | File | 757 bytes | April 10 2024 04:58:41. | |
checkpip.pyc | File | 1044 bytes | April 10 2024 04:58:46. | |
checkpip.pyo | File | 1044 bytes | April 10 2024 04:58:46. | |
checkpyc.py | File | 2010 bytes | April 10 2024 04:58:41. | |
checkpyc.pyc | File | 1976 bytes | April 10 2024 04:58:46. | |
checkpyc.pyo | File | 1976 bytes | April 10 2024 04:58:46. | |
classfix.py | File | 5952 bytes | April 10 2024 04:58:41. | |
classfix.pyc | File | 4189 bytes | April 10 2024 04:58:46. | |
classfix.pyo | File | 4189 bytes | April 10 2024 04:58:46. | |
cleanfuture.py | File | 8577 bytes | April 10 2024 04:58:41. | |
cleanfuture.pyc | File | 7394 bytes | April 10 2024 04:58:46. | |
cleanfuture.pyo | File | 7361 bytes | April 10 2024 04:58:44. | |
combinerefs.py | File | 4380 bytes | April 10 2024 04:58:41. | |
combinerefs.pyc | File | 4256 bytes | April 10 2024 04:58:46. | |
combinerefs.pyo | File | 4223 bytes | April 10 2024 04:58:44. | |
copytime.py | File | 663 bytes | April 10 2024 04:58:41. | |
copytime.pyc | File | 937 bytes | April 10 2024 04:58:46. | |
copytime.pyo | File | 937 bytes | April 10 2024 04:58:46. | |
crlf.py | File | 610 bytes | April 10 2024 04:58:41. | |
crlf.pyc | File | 855 bytes | April 10 2024 04:58:46. | |
crlf.pyo | File | 855 bytes | April 10 2024 04:58:46. | |
cvsfiles.py | File | 1786 bytes | April 10 2024 04:58:41. | |
cvsfiles.pyc | File | 2163 bytes | April 10 2024 04:58:46. | |
cvsfiles.pyo | File | 2163 bytes | April 10 2024 04:58:46. | |
db2pickle.py | File | 3570 bytes | April 10 2024 04:58:41. | |
db2pickle.pyc | File | 3497 bytes | April 10 2024 04:58:46. | |
db2pickle.pyo | File | 3497 bytes | April 10 2024 04:58:46. | |
diff.py | File | 2066 bytes | April 10 2024 04:58:41. | |
diff.pyc | File | 2386 bytes | April 10 2024 04:58:46. | |
diff.pyo | File | 2386 bytes | April 10 2024 04:58:46. | |
dutree.py | File | 1615 bytes | April 10 2024 04:58:41. | |
dutree.pyc | File | 2230 bytes | April 10 2024 04:58:46. | |
dutree.pyo | File | 2230 bytes | April 10 2024 04:58:46. | |
eptags.py | File | 1483 bytes | April 10 2024 04:58:41. | |
eptags.pyc | File | 1876 bytes | April 10 2024 04:58:46. | |
eptags.pyo | File | 1876 bytes | April 10 2024 04:58:46. | |
find_recursionlimit.py | File | 3473 bytes | April 10 2024 04:58:41. | |
find_recursionlimit.pyc | File | 5673 bytes | April 10 2024 04:58:46. | |
find_recursionlimit.pyo | File | 5673 bytes | April 10 2024 04:58:46. | |
finddiv.py | File | 2517 bytes | April 10 2024 04:58:41. | |
finddiv.pyc | File | 3296 bytes | April 10 2024 04:58:46. | |
finddiv.pyo | File | 3296 bytes | April 10 2024 04:58:46. | |
findlinksto.py | File | 1069 bytes | April 10 2024 04:58:41. | |
findlinksto.pyc | File | 1425 bytes | April 10 2024 04:58:46. | |
findlinksto.pyo | File | 1425 bytes | April 10 2024 04:58:46. | |
findnocoding.py | File | 2808 bytes | April 10 2024 04:58:41. | |
findnocoding.pyc | File | 3201 bytes | April 10 2024 04:58:46. | |
findnocoding.pyo | File | 3201 bytes | April 10 2024 04:58:46. | |
fixcid.py | File | 9995 bytes | April 10 2024 04:58:41. | |
fixcid.pyc | File | 7851 bytes | April 10 2024 04:58:46. | |
fixcid.pyo | File | 7851 bytes | April 10 2024 04:58:46. | |
fixdiv.py | File | 13841 bytes | April 10 2024 04:58:41. | |
fixdiv.pyc | File | 13849 bytes | April 10 2024 04:58:46. | |
fixdiv.pyo | File | 13766 bytes | April 10 2024 04:58:44. | |
fixheader.py | File | 1189 bytes | April 10 2024 04:58:41. | |
fixheader.pyc | File | 1471 bytes | April 10 2024 04:58:46. | |
fixheader.pyo | File | 1471 bytes | April 10 2024 04:58:46. | |
fixnotice.py | File | 3051 bytes | April 10 2024 04:58:41. | |
fixnotice.pyc | File | 3500 bytes | April 10 2024 04:58:46. | |
fixnotice.pyo | File | 3500 bytes | April 10 2024 04:58:46. | |
fixps.py | File | 893 bytes | April 10 2024 04:58:41. | |
fixps.pyc | File | 969 bytes | April 10 2024 04:58:46. | |
fixps.pyo | File | 969 bytes | April 10 2024 04:58:46. | |
google.py | File | 519 bytes | April 10 2024 04:58:41. | |
google.pyc | File | 792 bytes | April 10 2024 04:58:46. | |
google.pyo | File | 792 bytes | April 10 2024 04:58:46. | |
gprof2html.py | File | 2167 bytes | April 10 2024 04:58:41. | |
gprof2html.pyc | File | 2277 bytes | April 10 2024 04:58:46. | |
gprof2html.pyo | File | 2277 bytes | April 10 2024 04:58:46. | |
h2py.py | File | 5953 bytes | April 10 2024 04:58:41. | |
h2py.pyc | File | 4392 bytes | April 10 2024 04:58:46. | |
h2py.pyo | File | 4392 bytes | April 10 2024 04:58:46. | |
hotshotmain.py | File | 1483 bytes | April 10 2024 04:58:41. | |
hotshotmain.pyc | File | 1863 bytes | April 10 2024 04:58:46. | |
hotshotmain.pyo | File | 1863 bytes | April 10 2024 04:58:46. | |
ifdef.py | File | 3718 bytes | April 10 2024 04:58:41. | |
ifdef.pyc | File | 2265 bytes | April 10 2024 04:58:46. | |
ifdef.pyo | File | 2265 bytes | April 10 2024 04:58:46. | |
lfcr.py | File | 618 bytes | April 10 2024 04:58:41. | |
lfcr.pyc | File | 880 bytes | April 10 2024 04:58:46. | |
lfcr.pyo | File | 880 bytes | April 10 2024 04:58:46. | |
linktree.py | File | 2424 bytes | April 10 2024 04:58:41. | |
linktree.pyc | File | 2025 bytes | April 10 2024 04:58:46. | |
linktree.pyo | File | 2025 bytes | April 10 2024 04:58:46. | |
lll.py | File | 742 bytes | April 10 2024 04:58:41. | |
lll.pyc | File | 942 bytes | April 10 2024 04:58:46. | |
lll.pyo | File | 942 bytes | April 10 2024 04:58:46. | |
logmerge.py | File | 5575 bytes | April 10 2024 04:58:41. | |
logmerge.pyc | File | 5083 bytes | April 10 2024 04:58:46. | |
logmerge.pyo | File | 5083 bytes | April 10 2024 04:58:46. | |
mailerdaemon.py | File | 7942 bytes | April 10 2024 04:58:41. | |
mailerdaemon.pyc | File | 7364 bytes | April 10 2024 04:58:46. | |
mailerdaemon.pyo | File | 7364 bytes | April 10 2024 04:58:46. | |
md5sum.py | File | 2385 bytes | April 10 2024 04:58:41. | |
md5sum.pyc | File | 2917 bytes | April 10 2024 04:58:46. | |
md5sum.pyo | File | 2917 bytes | April 10 2024 04:58:46. | |
methfix.py | File | 5462 bytes | April 10 2024 04:58:41. | |
methfix.pyc | File | 4125 bytes | April 10 2024 04:58:46. | |
methfix.pyo | File | 4125 bytes | April 10 2024 04:58:46. | |
mkreal.py | File | 1627 bytes | April 10 2024 04:58:41. | |
mkreal.pyc | File | 1980 bytes | April 10 2024 04:58:46. | |
mkreal.pyo | File | 1980 bytes | April 10 2024 04:58:46. | |
ndiff.py | File | 3808 bytes | April 10 2024 04:58:41. | |
ndiff.pyc | File | 3859 bytes | April 10 2024 04:58:46. | |
ndiff.pyo | File | 3859 bytes | April 10 2024 04:58:46. | |
nm2def.py | File | 2443 bytes | April 10 2024 04:58:41. | |
nm2def.pyc | File | 2960 bytes | April 10 2024 04:58:46. | |
nm2def.pyo | File | 2960 bytes | April 10 2024 04:58:46. | |
objgraph.py | File | 6017 bytes | April 10 2024 04:58:41. | |
objgraph.pyc | File | 4933 bytes | April 10 2024 04:58:46. | |
objgraph.pyo | File | 4933 bytes | April 10 2024 04:58:46. | |
parseentities.py | File | 1719 bytes | April 10 2024 04:58:41. | |
parseentities.pyc | File | 2077 bytes | April 10 2024 04:58:46. | |
parseentities.pyo | File | 2077 bytes | April 10 2024 04:58:46. | |
patchcheck.py | File | 7679 bytes | April 10 2024 04:58:41. | |
patchcheck.pyc | File | 9128 bytes | April 10 2024 04:58:46. | |
patchcheck.pyo | File | 9128 bytes | April 10 2024 04:58:46. | |
pathfix.py | File | 4329 bytes | April 10 2024 04:58:41. | |
pathfix.pyc | File | 3838 bytes | April 10 2024 04:58:46. | |
pathfix.pyo | File | 3838 bytes | April 10 2024 04:58:46. | |
pdeps.py | File | 3936 bytes | April 10 2024 04:58:41. | |
pdeps.pyc | File | 3220 bytes | April 10 2024 04:58:46. | |
pdeps.pyo | File | 3220 bytes | April 10 2024 04:58:46. | |
pickle2db.py | File | 3942 bytes | April 10 2024 04:58:41. | |
pickle2db.pyc | File | 3819 bytes | April 10 2024 04:58:46. | |
pickle2db.pyo | File | 3819 bytes | April 10 2024 04:58:46. | |
pindent.py | File | 17170 bytes | April 10 2024 04:58:41. | |
pindent.pyc | File | 11559 bytes | April 10 2024 04:58:46. | |
pindent.pyo | File | 11559 bytes | April 10 2024 04:58:46. | |
ptags.py | File | 1224 bytes | April 10 2024 04:58:41. | |
ptags.pyc | File | 1407 bytes | April 10 2024 04:58:46. | |
ptags.pyo | File | 1407 bytes | April 10 2024 04:58:46. | |
pysource.py | File | 3846 bytes | April 10 2024 04:58:41. | |
pysource.pyc | File | 4009 bytes | April 10 2024 04:58:46. | |
pysource.pyo | File | 4009 bytes | April 10 2024 04:58:46. | |
redemo.py | File | 5792 bytes | April 10 2024 04:58:41. | |
redemo.pyc | File | 5249 bytes | April 10 2024 04:58:46. | |
redemo.pyo | File | 5249 bytes | April 10 2024 04:58:46. | |
reindent-rst.py | File | 278 bytes | April 10 2024 04:58:41. | |
reindent-rst.pyc | File | 481 bytes | April 10 2024 04:58:46. | |
reindent-rst.pyo | File | 481 bytes | April 10 2024 04:58:46. | |
reindent.py | File | 11417 bytes | April 10 2024 04:58:41. | |
reindent.pyc | File | 9629 bytes | April 10 2024 04:58:46. | |
reindent.pyo | File | 9590 bytes | April 10 2024 04:58:44. | |
rgrep.py | File | 1492 bytes | April 10 2024 04:58:41. | |
rgrep.pyc | File | 1881 bytes | April 10 2024 04:58:46. | |
rgrep.pyo | File | 1881 bytes | April 10 2024 04:58:46. | |
serve.py | File | 1147 bytes | April 10 2024 04:58:41. | |
serve.pyc | File | 1597 bytes | April 10 2024 04:58:46. | |
serve.pyo | File | 1597 bytes | April 10 2024 04:58:46. | |
setup.py | File | 421 bytes | April 10 2024 04:58:41. | |
setup.pyc | File | 548 bytes | April 10 2024 04:58:46. | |
setup.pyo | File | 548 bytes | April 10 2024 04:58:46. | |
suff.py | File | 621 bytes | April 10 2024 04:58:41. | |
suff.pyc | File | 904 bytes | April 10 2024 04:58:46. | |
suff.pyo | File | 904 bytes | April 10 2024 04:58:46. | |
svneol.py | File | 2930 bytes | April 10 2024 04:58:41. | |
svneol.pyc | File | 2904 bytes | April 10 2024 04:58:46. | |
svneol.pyo | File | 2825 bytes | April 10 2024 04:58:44. | |
texcheck.py | File | 9256 bytes | April 10 2024 04:58:41. | |
texcheck.pyc | File | 8376 bytes | April 10 2024 04:58:46. | |
texcheck.pyo | File | 8376 bytes | April 10 2024 04:58:46. | |
texi2html.py | File | 69825 bytes | April 10 2024 04:58:41. | |
texi2html.pyc | File | 83323 bytes | April 10 2024 04:58:46. | |
texi2html.pyo | File | 83323 bytes | April 10 2024 04:58:46. | |
treesync.py | File | 5783 bytes | April 10 2024 04:58:41. | |
treesync.pyc | File | 5990 bytes | April 10 2024 04:58:46. | |
treesync.pyo | File | 5990 bytes | April 10 2024 04:58:46. | |
untabify.py | File | 1215 bytes | April 10 2024 04:58:41. | |
untabify.pyc | File | 1583 bytes | April 10 2024 04:58:46. | |
untabify.pyo | File | 1583 bytes | April 10 2024 04:58:46. | |
which.py | File | 1630 bytes | April 10 2024 04:58:41. | |
which.pyc | File | 1632 bytes | April 10 2024 04:58:46. | |
which.pyo | File | 1632 bytes | April 10 2024 04:58:46. | |
win_add2path.py | File | 1620 bytes | April 10 2024 04:58:41. | |
win_add2path.pyc | File | 2069 bytes | April 10 2024 04:58:46. | |
win_add2path.pyo | File | 2069 bytes | April 10 2024 04:58:46. | |
xxci.py | File | 2797 bytes | April 10 2024 04:58:41. | |
xxci.pyc | File | 4017 bytes | April 10 2024 04:58:46. | |
xxci.pyo | File | 4017 bytes | April 10 2024 04:58:46. |
#! /usr/bin/python2.7 """fixdiv - tool to fix division operators. To use this tool, first run `python -Qwarnall yourscript.py 2>warnings'. This runs the script `yourscript.py' while writing warning messages about all uses of the classic division operator to the file `warnings'. The warnings look like this: <file>:<line>: DeprecationWarning: classic <type> division The warnings are written to stderr, so you must use `2>' for the I/O redirect. I know of no way to redirect stderr on Windows in a DOS box, so you will have to modify the script to set sys.stderr to some kind of log file if you want to do this on Windows. The warnings are not limited to the script; modules imported by the script may also trigger warnings. In fact a useful technique is to write a test script specifically intended to exercise all code in a particular module or set of modules. Then run `python fixdiv.py warnings'. This first reads the warnings, looking for classic division warnings, and sorts them by file name and line number. Then, for each file that received at least one warning, it parses the file and tries to match the warnings up to the division operators found in the source code. If it is successful, it writes its findings to stdout, preceded by a line of dashes and a line of the form: Index: <file> If the only findings found are suggestions to change a / operator into a // operator, the output is acceptable input for the Unix 'patch' program. Here are the possible messages on stdout (N stands for a line number): - A plain-diff-style change ('NcN', a line marked by '<', a line containing '---', and a line marked by '>'): A / operator was found that should be changed to //. This is the recommendation when only int and/or long arguments were seen. - 'True division / operator at line N' and a line marked by '=': A / operator was found that can remain unchanged. This is the recommendation when only float and/or complex arguments were seen. - 'Ambiguous / operator (..., ...) at line N', line marked by '?': A / operator was found for which int or long as well as float or complex arguments were seen. This is highly unlikely; if it occurs, you may have to restructure the code to keep the classic semantics, or maybe you don't care about the classic semantics. - 'No conclusive evidence on line N', line marked by '*': A / operator was found for which no warnings were seen. This could be code that was never executed, or code that was only executed with user-defined objects as arguments. You will have to investigate further. Note that // can be overloaded separately from /, using __floordiv__. True division can also be separately overloaded, using __truediv__. Classic division should be the same as either of those. (XXX should I add a warning for division on user-defined objects, to disambiguate this case from code that was never executed?) - 'Phantom ... warnings for line N', line marked by '*': A warning was seen for a line not containing a / operator. The most likely cause is a warning about code executed by 'exec' or eval() (see note below), or an indirect invocation of the / operator, for example via the div() function in the operator module. It could also be caused by a change to the file between the time the test script was run to collect warnings and the time fixdiv was run. - 'More than one / operator in line N'; or 'More than one / operator per statement in lines N-N': The scanner found more than one / operator on a single line, or in a statement split across multiple lines. Because the warnings framework doesn't (and can't) show the offset within the line, and the code generator doesn't always give the correct line number for operations in a multi-line statement, we can't be sure whether all operators in the statement were executed. To be on the safe side, by default a warning is issued about this case. In practice, these cases are usually safe, and the -m option suppresses these warning. - 'Can't find the / operator in line N', line marked by '*': This really shouldn't happen. It means that the tokenize module reported a '/' operator but the line it returns didn't contain a '/' character at the indicated position. - 'Bad warning for line N: XYZ', line marked by '*': This really shouldn't happen. It means that a 'classic XYZ division' warning was read with XYZ being something other than 'int', 'long', 'float', or 'complex'. Notes: - The augmented assignment operator /= is handled the same way as the / operator. - This tool never looks at the // operator; no warnings are ever generated for use of this operator. - This tool never looks at the / operator when a future division statement is in effect; no warnings are generated in this case, and because the tool only looks at files for which at least one classic division warning was seen, it will never look at files containing a future division statement. - Warnings may be issued for code not read from a file, but executed using an exec statement or the eval() function. These may have <string> in the filename position, in which case the fixdiv script will attempt and fail to open a file named '<string>' and issue a warning about this failure; or these may be reported as 'Phantom' warnings (see above). You're on your own to deal with these. You could make all recommended changes and add a future division statement to all affected files, and then re-run the test script; it should not issue any warnings. If there are any, and you have a hard time tracking down where they are generated, you can use the -Werror option to force an error instead of a first warning, generating a traceback. - The tool should be run from the same directory as that from which the original script was run, otherwise it won't be able to open files given by relative pathnames. """ import sys import getopt import re import tokenize multi_ok = 0 def main(): try: opts, args = getopt.getopt(sys.argv[1:], "hm") except getopt.error, msg: usage(msg) return 2 for o, a in opts: if o == "-h": print __doc__ return if o == "-m": global multi_ok multi_ok = 1 if not args: usage("at least one file argument is required") return 2 if args[1:]: sys.stderr.write("%s: extra file arguments ignored\n", sys.argv[0]) warnings = readwarnings(args[0]) if warnings is None: return 1 files = warnings.keys() if not files: print "No classic division warnings read from", args[0] return files.sort() exit = None for filename in files: x = process(filename, warnings[filename]) exit = exit or x return exit def usage(msg): sys.stderr.write("%s: %s\n" % (sys.argv[0], msg)) sys.stderr.write("Usage: %s [-m] warnings\n" % sys.argv[0]) sys.stderr.write("Try `%s -h' for more information.\n" % sys.argv[0]) PATTERN = ("^(.+?):(\d+): DeprecationWarning: " "classic (int|long|float|complex) division$") def readwarnings(warningsfile): prog = re.compile(PATTERN) try: f = open(warningsfile) except IOError, msg: sys.stderr.write("can't open: %s\n" % msg) return warnings = {} while 1: line = f.readline() if not line: break m = prog.match(line) if not m: if line.find("division") >= 0: sys.stderr.write("Warning: ignored input " + line) continue filename, lineno, what = m.groups() list = warnings.get(filename) if list is None: warnings[filename] = list = [] list.append((int(lineno), intern(what))) f.close() return warnings def process(filename, list): print "-"*70 assert list # if this fails, readwarnings() is broken try: fp = open(filename) except IOError, msg: sys.stderr.write("can't open: %s\n" % msg) return 1 print "Index:", filename f = FileContext(fp) list.sort() index = 0 # list[:index] has been processed, list[index:] is still to do g = tokenize.generate_tokens(f.readline) while 1: startlineno, endlineno, slashes = lineinfo = scanline(g) if startlineno is None: break assert startlineno <= endlineno is not None orphans = [] while index < len(list) and list[index][0] < startlineno: orphans.append(list[index]) index += 1 if orphans: reportphantomwarnings(orphans, f) warnings = [] while index < len(list) and list[index][0] <= endlineno: warnings.append(list[index]) index += 1 if not slashes and not warnings: pass elif slashes and not warnings: report(slashes, "No conclusive evidence") elif warnings and not slashes: reportphantomwarnings(warnings, f) else: if len(slashes) > 1: if not multi_ok: rows = [] lastrow = None for (row, col), line in slashes: if row == lastrow: continue rows.append(row) lastrow = row assert rows if len(rows) == 1: print "*** More than one / operator in line", rows[0] else: print "*** More than one / operator per statement", print "in lines %d-%d" % (rows[0], rows[-1]) intlong = [] floatcomplex = [] bad = [] for lineno, what in warnings: if what in ("int", "long"): intlong.append(what) elif what in ("float", "complex"): floatcomplex.append(what) else: bad.append(what) lastrow = None for (row, col), line in slashes: if row == lastrow: continue lastrow = row line = chop(line) if line[col:col+1] != "/": print "*** Can't find the / operator in line %d:" % row print "*", line continue if bad: print "*** Bad warning for line %d:" % row, bad print "*", line elif intlong and not floatcomplex: print "%dc%d" % (row, row) print "<", line print "---" print ">", line[:col] + "/" + line[col:] elif floatcomplex and not intlong: print "True division / operator at line %d:" % row print "=", line elif intlong and floatcomplex: print "*** Ambiguous / operator (%s, %s) at line %d:" % ( "|".join(intlong), "|".join(floatcomplex), row) print "?", line fp.close() def reportphantomwarnings(warnings, f): blocks = [] lastrow = None lastblock = None for row, what in warnings: if row != lastrow: lastblock = [row] blocks.append(lastblock) lastblock.append(what) for block in blocks: row = block[0] whats = "/".join(block[1:]) print "*** Phantom %s warnings for line %d:" % (whats, row) f.report(row, mark="*") def report(slashes, message): lastrow = None for (row, col), line in slashes: if row != lastrow: print "*** %s on line %d:" % (message, row) print "*", chop(line) lastrow = row class FileContext: def __init__(self, fp, window=5, lineno=1): self.fp = fp self.window = 5 self.lineno = 1 self.eoflookahead = 0 self.lookahead = [] self.buffer = [] def fill(self): while len(self.lookahead) < self.window and not self.eoflookahead: line = self.fp.readline() if not line: self.eoflookahead = 1 break self.lookahead.append(line) def readline(self): self.fill() if not self.lookahead: return "" line = self.lookahead.pop(0) self.buffer.append(line) self.lineno += 1 return line def __getitem__(self, index): self.fill() bufstart = self.lineno - len(self.buffer) lookend = self.lineno + len(self.lookahead) if bufstart <= index < self.lineno: return self.buffer[index - bufstart] if self.lineno <= index < lookend: return self.lookahead[index - self.lineno] raise KeyError def report(self, first, last=None, mark="*"): if last is None: last = first for i in range(first, last+1): try: line = self[first] except KeyError: line = "<missing line>" print mark, chop(line) def scanline(g): slashes = [] startlineno = None endlineno = None for type, token, start, end, line in g: endlineno = end[0] if startlineno is None: startlineno = endlineno if token in ("/", "/="): slashes.append((start, line)) if type == tokenize.NEWLINE: break return startlineno, endlineno, slashes def chop(line): if line.endswith("\n"): return line[:-1] else: return line if __name__ == "__main__": sys.exit(main())
SILENT KILLER Tool