4 from test
import test_support
5 htmllib
= test_support
.import_module('htmllib', deprecated
=True)
8 class AnchorCollector(htmllib
.HTMLParser
):
9 def __init__(self
, *args
, **kw
):
11 htmllib
.HTMLParser
.__init
__(self
, *args
, **kw
)
13 def get_anchor_info(self
):
16 def anchor_bgn(self
, *args
):
17 self
.__anchors
.append(args
)
19 class DeclCollector(htmllib
.HTMLParser
):
20 def __init__(self
, *args
, **kw
):
22 htmllib
.HTMLParser
.__init
__(self
, *args
, **kw
)
24 def get_decl_info(self
):
27 def unknown_decl(self
, data
):
28 self
.__decls
.append(data
)
31 class HTMLParserTestCase(unittest
.TestCase
):
32 def test_anchor_collection(self
):
34 parser
= AnchorCollector(formatter
.NullFormatter(), verbose
=1)
36 """<a href='http://foo.org/' name='splat'> </a>
37 <a href='http://www.python.org/'> </a>
41 self
.assertEquals(parser
.get_anchor_info(),
42 [('http://foo.org/', 'splat', ''),
43 ('http://www.python.org/', '', ''),
47 def test_decl_collection(self
):
48 # See SF patch #545300
49 parser
= DeclCollector(formatter
.NullFormatter(), verbose
=1)
54 <![if !supportEmptyParas]> <![endif]>
59 self
.assertEquals(parser
.get_decl_info(),
60 ["if !supportEmptyParas",
65 test_support
.run_unittest(HTMLParserTestCase
)
68 if __name__
== "__main__":