Commit f5187c8d authored by Guido van Rossum's avatar Guido van Rossum

improved test()

parent 54015fbb
...@@ -385,16 +385,40 @@ class HTMLParser(SGMLParser): ...@@ -385,16 +385,40 @@ class HTMLParser(SGMLParser):
pass pass
def test(): def test(args = None):
import sys import sys, formatter
file = 'test.html'
if sys.argv[1:]: file = sys.argv[1] if not args:
fp = open(file, 'r') args = sys.argv[1:]
data = fp.read()
fp.close() silent = args and args[0] == '-s'
from formatter import DumbWriter, AbstractFormatter if silent:
w = DumbWriter() del args[0]
f = AbstractFormatter(w)
if args:
file = args[0]
else:
file = 'test.html'
if file == '-':
f = sys.stdin
else:
try:
f = open(file, 'r')
except IOError, msg:
print file, ":", msg
sys.exit(1)
data = f.read()
if f is not sys.stdin:
f.close()
if silent:
f = formatter.NullFormatter()
else:
f = formatter.AbstractFormatter(formatter.DumbWriter())
p = HTMLParser(f) p = HTMLParser(f)
p.feed(data) p.feed(data)
p.close() p.close()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment