Add a basic SGML parser

I tried BeautifulSoup, which was okay, but was missing an understanding
of how OFX does SGML. That's fine, writing my own parser was not that
big of a deal
This commit is contained in:
Eli Ribble 2016-06-22 14:08:13 -06:00
parent 104289418b
commit 95244d2974
2 changed files with 83 additions and 0 deletions

17
tests/test_sgml.py Normal file
View file

@ -0,0 +1,17 @@
import vanth.sgml
def child_values(node):
return [(child.name, child.value) for child in node.children]
def test_siblings():
result = vanth.sgml.parse("<A><B><C>1<D>2<E>3</B></A>")
assert result.name == 'A'
assert child_values(result['B']) == [('C', '1'), ('D', '2'), ('E', '3')]
def test_closing():
result = vanth.sgml.parse("<A><B><C>1</B><D><E>2</D></A>")
assert result.name == 'A'
assert child_values(result) == [('B', ''), ('D', '')]
assert child_values(result['B']) == [('C', '1')]
assert child_values(result['D']) == [('E', '2')]