1 import Martel
2 from Martel import RecordReader, Parser
3
4 from xml.sax import handler, saxutils
5 from StringIO import StringIO
6
7
8
9
10
11
35
38 self.error_count = 0
39 self.fatal_error_count = 0
40 - def error(self, exception):
41 self.error_count = self.error_count + 1
43 self.fatal_error_count = self.fatal_error_count + 1
44
47 self.tag = tag
48 self.count = 0
50 if tag == self.tag:
51 self.count = self.count + 1
52
54 record = Martel.Group("A", Martel.Str("X\n") + Martel.Re("a*\n"))
55 p = record.make_parser()
56
57 parser = Parser.RecordParser("blah", {}, p.tagtable, (0, 1, {}),
58 RecordReader.StartsWith, ("X",))
59
60 err = CountErrors()
61 parser.setErrorHandler(err)
62 count = CountRecords("A")
63 parser.setContentHandler(count)
64
65 parser.parseString("X\na\nX\nb\nX\naaa\nX\naaaa\nX\nq\nX\na\n")
66
67 assert err.fatal_error_count == 0, err.fatal_error_count
68 assert err.error_count == 2, err.error_count
69 assert count.count == 4, count.count
70
121
122
165
210
252
294
346
377
444
455
456 if __name__ == "__main__":
457 test()
458