def readwarnings(warningsfile):
prog = re.compile(PATTERN)
+ warnings = {}
try:
f = open(warningsfile)
except IOError as 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), sys.intern(what)))
- f.close()
+ with f:
+ 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), sys.intern(what)))
return warnings
def process(filename, list):
except IOError as 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])
+ with fp:
+ 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", end=' ')
+ 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:
- print("*** More than one / operator per statement", end=' ')
- 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()
+ 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)
def reportphantomwarnings(warnings, f):
blocks = []
self.lines.append(line)
def flush(self):
- fp = open(self.dirname + '/' + makefile(self.name), 'w')
- fp.write(self.prologue)
- fp.write(self.text)
- fp.write(self.epilogue)
- fp.close()
+ with open(self.dirname + '/' + makefile(self.name), 'w') as fp:
+ fp.write(self.prologue)
+ fp.write(self.text)
+ fp.write(self.epilogue)
def link(self, label, nodename, rel=None, rev=None):
if nodename:
except IOError as msg:
print('*** Can\'t open include file', repr(file))
return
- print('!'*self.debugging, '--> file', repr(file))
- save_done = self.done
- save_skip = self.skip
- save_stack = self.stack
- self.includedepth = self.includedepth + 1
- self.parserest(fp, 0)
- self.includedepth = self.includedepth - 1
- fp.close()
+ with fp:
+ print('!'*self.debugging, '--> file', repr(file))
+ save_done = self.done
+ save_skip = self.skip
+ save_stack = self.stack
+ self.includedepth = self.includedepth + 1
+ self.parserest(fp, 0)
+ self.includedepth = self.includedepth - 1
self.done = save_done
self.skip = save_skip
self.stack = save_stack
# PROJECT FILE
try:
- fp = open(projectfile,'w')
- print('[OPTIONS]', file=fp)
- print('Auto Index=Yes', file=fp)
- print('Binary TOC=No', file=fp)
- print('Binary Index=Yes', file=fp)
- print('Compatibility=1.1', file=fp)
- print('Compiled file=' + resultfile + '', file=fp)
- print('Contents file=' + contentfile + '', file=fp)
- print('Default topic=' + defaulttopic + '', file=fp)
- print('Error log file=ErrorLog.log', file=fp)
- print('Index file=' + indexfile + '', file=fp)
- print('Title=' + title + '', file=fp)
- print('Display compile progress=Yes', file=fp)
- print('Full-text search=Yes', file=fp)
- print('Default window=main', file=fp)
- print('', file=fp)
- print('[WINDOWS]', file=fp)
- print('main=,"' + contentfile + '","' + indexfile
- + '","","",,,,,0x23520,222,0x1046,[10,10,780,560],'
- '0xB0000,,,,,,0', file=fp)
- print('', file=fp)
- print('[FILES]', file=fp)
- print('', file=fp)
- self.dumpfiles(fp)
- fp.close()
+ with open(projectfile, 'w') as fp:
+ print('[OPTIONS]', file=fp)
+ print('Auto Index=Yes', file=fp)
+ print('Binary TOC=No', file=fp)
+ print('Binary Index=Yes', file=fp)
+ print('Compatibility=1.1', file=fp)
+ print('Compiled file=' + resultfile + '', file=fp)
+ print('Contents file=' + contentfile + '', file=fp)
+ print('Default topic=' + defaulttopic + '', file=fp)
+ print('Error log file=ErrorLog.log', file=fp)
+ print('Index file=' + indexfile + '', file=fp)
+ print('Title=' + title + '', file=fp)
+ print('Display compile progress=Yes', file=fp)
+ print('Full-text search=Yes', file=fp)
+ print('Default window=main', file=fp)
+ print('', file=fp)
+ print('[WINDOWS]', file=fp)
+ print('main=,"' + contentfile + '","' + indexfile
+ + '","","",,,,,0x23520,222,0x1046,[10,10,780,560],'
+ '0xB0000,,,,,,0', file=fp)
+ print('', file=fp)
+ print('[FILES]', file=fp)
+ print('', file=fp)
+ self.dumpfiles(fp)
except IOError as msg:
print(projectfile, ':', msg)
sys.exit(1)
# CONTENT FILE
try:
- fp = open(contentfile,'w')
- print('<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">', file=fp)
- print('<!-- This file defines the table of contents -->', file=fp)
- print('<HTML>', file=fp)
- print('<HEAD>', file=fp)
- print('<meta name="GENERATOR" '
- 'content="Microsoft® HTML Help Workshop 4.1">', file=fp)
- print('<!-- Sitemap 1.0 -->', file=fp)
- print('</HEAD>', file=fp)
- print('<BODY>', file=fp)
- print(' <OBJECT type="text/site properties">', file=fp)
- print(' <param name="Window Styles" value="0x800025">', file=fp)
- print(' <param name="comment" value="title:">', file=fp)
- print(' <param name="comment" value="base:">', file=fp)
- print(' </OBJECT>', file=fp)
- self.dumpnodes(fp)
- print('</BODY>', file=fp)
- print('</HTML>', file=fp)
- fp.close()
+ with open(contentfile, 'w') as fp:
+ print('<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">', file=fp)
+ print('<!-- This file defines the table of contents -->', file=fp)
+ print('<HTML>', file=fp)
+ print('<HEAD>', file=fp)
+ print('<meta name="GENERATOR" '
+ 'content="Microsoft® HTML Help Workshop 4.1">', file=fp)
+ print('<!-- Sitemap 1.0 -->', file=fp)
+ print('</HEAD>', file=fp)
+ print('<BODY>', file=fp)
+ print(' <OBJECT type="text/site properties">', file=fp)
+ print(' <param name="Window Styles" value="0x800025">', file=fp)
+ print(' <param name="comment" value="title:">', file=fp)
+ print(' <param name="comment" value="base:">', file=fp)
+ print(' </OBJECT>', file=fp)
+ self.dumpnodes(fp)
+ print('</BODY>', file=fp)
+ print('</HTML>', file=fp)
except IOError as msg:
print(contentfile, ':', msg)
sys.exit(1)
# INDEX FILE
try:
- fp = open(indexfile ,'w')
- print('<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">', file=fp)
- print('<!-- This file defines the index -->', file=fp)
- print('<HTML>', file=fp)
- print('<HEAD>', file=fp)
- print('<meta name="GENERATOR" '
- 'content="Microsoft® HTML Help Workshop 4.1">', file=fp)
- print('<!-- Sitemap 1.0 -->', file=fp)
- print('</HEAD>', file=fp)
- print('<BODY>', file=fp)
- print('<OBJECT type="text/site properties">', file=fp)
- print('</OBJECT>', file=fp)
- self.dumpindex(fp)
- print('</BODY>', file=fp)
- print('</HTML>', file=fp)
- fp.close()
+ with open(indexfile, 'w') as fp:
+ print('<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">', file=fp)
+ print('<!-- This file defines the index -->', file=fp)
+ print('<HTML>', file=fp)
+ print('<HEAD>', file=fp)
+ print('<meta name="GENERATOR" '
+ 'content="Microsoft® HTML Help Workshop 4.1">', file=fp)
+ print('<!-- Sitemap 1.0 -->', file=fp)
+ print('</HEAD>', file=fp)
+ print('<BODY>', file=fp)
+ print('<OBJECT type="text/site properties">', file=fp)
+ print('</OBJECT>', file=fp)
+ self.dumpindex(fp)
+ print('</BODY>', file=fp)
+ print('</HTML>', file=fp)
except IOError as msg:
print(indexfile , ':', msg)
sys.exit(1)
print(file, ':', msg)
sys.exit(1)
- parser.parse(fp)
- fp.close()
+ with fp:
+ parser.parse(fp)
parser.report()
htmlhelp.finalize()