Esempio n. 1
0
	def printone(u):
		source = parse.URL(u) if isinstance(u, url.URL) else parse.Stream(u)
		node = parse.tree(source, parse.Tidy(), parse.NS(html), parse.Node(base="", pool=xsc.Pool(html, xml)))
		if args.compact:
			node = node.normalized().compacted()
		node = node.pretty()
		print((node.string(encoding=sys.stdout.encoding)))
def test_htmlparse_base():
    e = parse.tree(b"<a href='gurk.gif'/>",
                   parse.Tidy(),
                   parse.NS(html),
                   parse.Node(base="hurz/index.html"),
                   validate=True)
    e = e.walknodes(html.a)[0]
    assert str(e.attrs.href) == "hurz/gurk.gif"
def test_parse_tidy_attrs():
    e = parse.tree(
        b"<a xmlns:xl='http://www.w3.org/1999/xlink' xml:lang='de' xl:href='gurk.gif' href='gurk.gif'/>",
        parse.Tidy(),
        parse.NS(html),
        parse.Node(pool=xsc.Pool(html, xml, xlink)),
        validate=True)
    a = e.walknodes(html.a)[0]
    assert str(a.attrs["href"]) == "gurk.gif"
    assert str(a.attrs[xml.Attrs.lang]) == "de"
    assert str(a.attrs[xlink.Attrs.href]) == "gurk.gif"
def test_parse_tidy_empty():
    e = parse.tree(b"", parse.Tidy(), parse.NS(), parse.Node(), validate=True)
    assert not e