summaryrefslogtreecommitdiff
path: root/plugins/MirOTR/ekhtml/testsuite/pyparser.py
blob: a96d999bb7d5f3489d2d209a4c81cb021fa08eac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#! /usr/bin/env python

import ek_sgmllib, sys, string

class myparser(ek_sgmllib.SGMLParser):
    def __init__(self):
        ek_sgmllib.SGMLParser.__init__(self)

    def handle_data(self, data):
        sys.stdout.write(data)

    def start_way(self, attrs):
        print 'GOT WAY START!'
        
    def unknown_starttag(self, tag, attrs):
        print 'START: "%s"' % tag
        for i in range(len(attrs) - 1, -1, -1):
            key, val = attrs[i]
            print 'ATTRIBUTE: "%s" = "%s"' % (key, val)
        
    def unknown_endtag(self, tag):
        print 'END: "%s"' % tag
    
    def handle_comment(self, comment):
 	print 'COMMENT: "%s"' % comment
    
    def handle_entityref(self, name):
        self.handle_data('&' + name + ';')

    def handle_charref(self, name):
        self.handle_data('&#' + name + ';')
        
def testit(data):
    x = myparser()
    x.feed(data)
    x.close()
    
if __name__ == '__main__':
    if len(sys.argv) == 1:
        f = sys.stdin
    else:
        f = open(sys.argv[1])
        
    testit(f.read())