from test
import test_support
class AnchorCollector(htmllib
.HTMLParser
):
def __init__(self
, *args
, **kw
):
htmllib
.HTMLParser
.__init
__(self
, *args
, **kw
)
def get_anchor_info(self
):
def anchor_bgn(self
, *args
):
self
.__anchors
.append(args
)
class DeclCollector(htmllib
.HTMLParser
):
def __init__(self
, *args
, **kw
):
htmllib
.HTMLParser
.__init
__(self
, *args
, **kw
)
def unknown_decl(self
, data
):
self
.__decls
.append(data
)
class HTMLParserTestCase(unittest
.TestCase
):
def test_anchor_collection(self
):
parser
= AnchorCollector(formatter
.NullFormatter(), verbose
=1)
"""<a href='http://foo.org/' name='splat'> </a>
<a href='http://www.python.org/'> </a>
self
.assertEquals(parser
.get_anchor_info(),
[('http://foo.org/', 'splat', ''),
('http://www.python.org/', '', ''),
def test_decl_collection(self
):
parser
= DeclCollector(formatter
.NullFormatter(), verbose
=1)
<![if !supportEmptyParas]> <![endif]>
self
.assertEquals(parser
.get_decl_info(),
["if !supportEmptyParas",
test_support
.run_unittest(HTMLParserTestCase
)
if __name__
== "__main__":