• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1from __future__ import absolute_import, division, unicode_literals
2
3import sys
4import os
5
6if __name__ == '__main__':
7    # Allow us to import from the src directory
8    os.chdir(os.path.split(os.path.abspath(__file__))[0])
9    sys.path.insert(0, os.path.abspath(os.path.join(os.pardir, "src")))
10
11from html5lib.tokenizer import HTMLTokenizer
12
13
14class HTMLParser(object):
15    """ Fake parser to test tokenizer output """
16    def parse(self, stream, output=True):
17        tokenizer = HTMLTokenizer(stream)
18        for token in tokenizer:
19            if output:
20                print(token)
21
22if __name__ == "__main__":
23    x = HTMLParser()
24    if len(sys.argv) > 1:
25        if len(sys.argv) > 2:
26            import hotshot
27            import hotshot.stats
28            prof = hotshot.Profile('stats.prof')
29            prof.runcall(x.parse, sys.argv[1], False)
30            prof.close()
31            stats = hotshot.stats.load('stats.prof')
32            stats.strip_dirs()
33            stats.sort_stats('time')
34            stats.print_stats()
35        else:
36            x.parse(sys.argv[1])
37    else:
38        print("""Usage: python mockParser.py filename [stats]
39        If stats is specified the hotshots profiler will run and output the
40        stats instead.
41        """)
42