diff options
author | Dave Cole <djc@object-craft.com.au> | 2004-08-26 00:37:31 (GMT) |
---|---|---|
committer | Dave Cole <djc@object-craft.com.au> | 2004-08-26 00:37:31 (GMT) |
commit | 3203efb55fde14c3f567f6864dab1454155d1dcb (patch) | |
tree | b550584948252f2d7677e877776bb3cdeae8faaf /Lib/test/test_pyexpat.py | |
parent | 0d58e2be0b81c12b0056d458a0480dc525af1abb (diff) | |
download | cpython-3203efb55fde14c3f567f6864dab1454155d1dcb.zip cpython-3203efb55fde14c3f567f6864dab1454155d1dcb.tar.gz cpython-3203efb55fde14c3f567f6864dab1454155d1dcb.tar.bz2 |
Patch #1014930. Expose current parse location to XMLParser.
Diffstat (limited to 'Lib/test/test_pyexpat.py')
-rw-r--r-- | Lib/test/test_pyexpat.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/Lib/test/test_pyexpat.py b/Lib/test/test_pyexpat.py index 44f9ee8..a9a5e8f 100644 --- a/Lib/test/test_pyexpat.py +++ b/Lib/test/test_pyexpat.py @@ -326,3 +326,42 @@ except RuntimeError, e: print "Expected RuntimeError for element 'a'; found %r" % e.args[0] else: print "Expected RuntimeError for 'a'" + +# Test Current* members: +class PositionTest: + + def __init__(self, expected_list, parser): + self.parser = parser + self.parser.StartElementHandler = self.StartElementHandler + self.parser.EndElementHandler = self.EndElementHandler + self.expected_list = expected_list + self.upto = 0 + + def StartElementHandler(self, name, attrs): + self.check_pos('s') + + def EndElementHandler(self, name): + self.check_pos('e') + + def check_pos(self, event): + pos = (event, + self.parser.CurrentByteIndex, + self.parser.CurrentLineNumber, + self.parser.CurrentColumnNumber) + require(self.upto < len(self.expected_list), + 'too many parser events') + expected = self.expected_list[self.upto] + require(pos == expected, + 'expected position %s, got %s' % (expected, pos)) + self.upto += 1 + + +parser = expat.ParserCreate() +handler = PositionTest([('s', 0, 1, 0), ('s', 5, 2, 1), ('s', 11, 3, 2), + ('e', 15, 3, 6), ('e', 17, 4, 1), ('e', 22, 5, 0)], + parser) +parser.Parse('''<a> + <b> + <c/> + </b> +</a>''', 1) |