def test_switchns(self): xml = ( '<html xmlns="http://www.w3.org/1999/xhtml">' '<p>in default namespace</p>' '<foo:div xmlns:foo="http://www.w3.org/1999/xhtml">' '<foo:p>in foo namespace</foo:p></foo:div></html>') self.assertEqual(xml, flatten(parseString(xml)))
def test_otherns(self): xml = ( '<html xmlns="http://www.w3.org/1999/xhtml" ' 'xmlns:xf="http://www.w3.org/2002/xforms"><p>' 'in default namespace</p><xf:input><xf:label>' 'in another namespace</xf:label></xf:input></html>') self.assertEqual(xml, flatten(parseString(xml)))
def test_invisiblens(self): """ Test that invisible tags do not get output with a namespace. """ xml = ('<p xmlns:n="http://nevow.com/ns/nevow/0.1">' '<n:invisible>123</n:invisible></p>') self.failUnlessEqual('<p>123</p>', flatten(parseString(xml)))
def load(self, ctx=None): if self._cache is None: doc = flatsax.parseString(self.template, self.ignoreDocType, self.ignoreComment) doc = flat.precompile(doc, ctx) if self.pattern is not None: doc = inevow.IQ(doc).onePattern(self.pattern) self._cache = doc return self._cache
def test_invisiblens(self): """ Test that invisible tags do not get output with a namespace. """ xml = ( '<p xmlns:n="http://nevow.com/ns/nevow/0.1">' '<n:invisible>123</n:invisible></p>') self.assertEqual('<p>123</p>', flatten(parseString(xml)))
def load(self, ctx=None): if self._cache is None: doc = flatsax.parseString(self.template, self.ignoreDocType, self.ignoreComment) doc = flat.precompile(doc, ctx) if self.pattern is not None: doc = inevow.IQ(doc).onePattern(self.pattern) self._cache = doc return self._cache
def test_commentWhereSpacingMatters(self): """Explicitly test that spacing in comments is maintained.""" xml = """<head> <!--[if IE]> <style> div.logo { margin-left: 10px; } </style> <![endif]--> </head>""" self.failUnlessEqual(xml, flatten(parseString(xml)))
def load(self, ctx=None, preprocessors=()): """ Get an instance, possibly cached from a previous call, of this document """ if self._cache is None: doc = flatsax.parseString(self.template, self.ignoreDocType, self.ignoreComment) for proc in preprocessors: doc = proc(doc) doc = flat.precompile(doc, ctx) if self.pattern is not None: doc = inevow.IQ(doc).onePattern(self.pattern) self._cache = doc return self._cache
def load(self, ctx=None, preprocessors=()): """ Get an instance, possibly cached from a previous call, of this document """ if self._cache is None: doc = flatsax.parseString(self.template, self.ignoreDocType, self.ignoreComment) for proc in preprocessors: doc = proc(doc) doc = flat.precompile(doc, ctx) if self.pattern is not None: doc = inevow.IQ(doc).onePattern(self.pattern) self._cache = doc return self._cache
def test_commentWhereSpacingMatters(self): """ Explicitly test that spacing in comments is maintained. """ xml = """<head> <!--[if IE]> <style> div.logo { margin-left: 10px; } </style> <![endif]--> </head>""" self.assertEqual(xml, flatten(parseString(xml)))
def test_unicodeComment(self): xml = '<!-- \xc2\xa3 --><html></html>' self.assertEqual(xml, flatten(parseString(xml)).encode("utf-8"))
def test_badNamespace(self): xml = '<html foo:bar="wee"><abc:p>xyz</abc:p></html>' self.assertEqual(xml, flatten(parseString(xml)))
def test_unicodeComment(self): xml = '<!-- \xc2\xa3 --><html></html>' self.assertEqual(xml, flatten(parseString(xml)))
def test_comment(self): xml = '<!-- comment &£ --><html></html>' self.assertEqual(xml, flatten(parseString(xml)))
def test_entities(self): xml = """<p>&</p>""" self.assertEqual(xml, flatten(parseString(xml)))
def test_cdata(self): xml = '<script type="text/javascript"><![CDATA[<abc]]></script>' self.assertEqual(xml, flatten(parseString(xml)))
def test_doctype(self): xml = '''<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n<html></html>''' self.failUnlessEqual(norm(xml), norm(flatten(parseString(xml))))
def test_cdata(self): xml = '''<script type="text/javascript"><![CDATA[<abc]]></script>''' self.failUnlessEqual(norm(xml), norm(flatten(parseString(xml))))
def test_entities(self): xml = """<p>&</p>""" self.failUnlessEqual(norm(xml), norm(flatten(parseString(xml))))
def test_doctype(self): xml = '''<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n<html></html>''' self.failUnlessEqual(norm(xml), norm(flatten(parseString(xml))))
def test_processingInstruction(self): xml = '''<html></html>''' self.failUnlessEqual(norm(xml), norm(flatten(parseString(xml))))
def test_xmlns(self): xml = '''<html xmlns="http://www.w3.org/1999/xhtml"></html>''' self.failUnlessEqual(norm(xml), norm(flatten(parseString(xml))))
def test_attrs(self): xml = '''<p class="foo"></p>''' self.failUnlessEqual(norm(xml), norm(flatten(parseString(xml))))
def test_parseString(self): xml = '''<html></html>''' self.failUnlessEqual(norm(xml), norm(flatten(parseString(xml))))
def test_parseString(self): xml = '''<html></html>''' self.failUnlessEqual(xml, flatten(parseString(xml)))
def test_xmlns(self): xml = '''<html xmlns="http://www.w3.org/1999/xhtml"></html>''' self.failUnlessEqual(xml, flatten(parseString(xml)))
def test_comment(self): xml = '''<!-- comment &£ --><html></html>''' self.failUnlessEqual(norm(xml), norm(flatten(parseString(xml))))
def test_cdata(self): xml = '''<script type="text/javascript"><![CDATA[<abc]]></script>''' self.failUnlessEqual(xml, flatten(parseString(xml)))
def test_unicodeComment(self): xml = '''<!-- \xc2\xa3 --><html></html>''' self.failUnlessEqual(norm(xml), norm(flatten(parseString(xml))))
def test_otherns(self): xml = ('<html xmlns="http://www.w3.org/1999/xhtml" ' 'xmlns:xf="http://www.w3.org/2002/xforms"><p>' 'in default namespace</p><xf:input><xf:label>' 'in another namespace</xf:label></xf:input></html>') self.assertEqual(xml, flatten(parseString(xml)))
def test_xmlAttr(self): xml = '''<html xml:lang="en"></html>''' self.failUnlessEqual(norm(xml), norm(flatten(parseString(xml))))
def test_cdata(self): xml = '<script type="text/javascript"><![CDATA[<abc]]></script>' self.assertEqual(xml, flatten(parseString(xml)))
def test_badNamespace(self): xml = '''<html foo:bar="wee"><abc:p>xyz</abc:p></html>''' self.failUnlessEqual(norm(xml), norm(flatten(parseString(xml))))
def test_switchns(self): xml = '''<html xmlns="http://www.w3.org/1999/xhtml"><p>in default namespace</p><foo:div xmlns:foo="http://www.w3.org/1999/xhtml"><foo:p>in foo namespace</foo:p></foo:div></html>''' self.failUnlessEqual(norm(xml), norm(flatten(parseString(xml))))
def test_otherns(self): xml = '''<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms"><p>in default namespace</p><xf:input><xf:label>in another namespace</xf:label></xf:input></html>''' self.failUnlessEqual(norm(xml), norm(flatten(parseString(xml))))
def test_xmlAttr(self): xml = '<html xml:lang="en"></html>' self.assertEqual(xml, flatten(parseString(xml)))
def test_switchns(self): xml = ('<html xmlns="http://www.w3.org/1999/xhtml">' '<p>in default namespace</p>' '<foo:div xmlns:foo="http://www.w3.org/1999/xhtml">' '<foo:p>in foo namespace</foo:p></foo:div></html>') self.assertEqual(xml, flatten(parseString(xml)))
def test_xmlAttr(self): xml = '<html xml:lang="en"></html>' self.assertEqual(xml, flatten(parseString(xml)))
def test_xmlAttr(self): xml = '''<html xml:lang="en"></html>''' self.failUnlessEqual(xml, flatten(parseString(xml)))
def test_comment(self): xml = '<!-- comment &£ --><html></html>' self.assertEqual(xml, flatten(parseString(xml)))
def test_switchns(self): xml = '''<html xmlns="http://www.w3.org/1999/xhtml"><p>in default namespace</p><foo:div xmlns:foo="http://www.w3.org/1999/xhtml"><foo:p>in foo namespace</foo:p></foo:div></html>''' self.failUnlessEqual(xml, flatten(parseString(xml)))
def test_attrs(self): xml = '''<p class="foo"></p>''' self.failUnlessEqual(xml, flatten(parseString(xml)))
def test_badNamespace(self): xml = '<html foo:bar="wee"><abc:p>xyz</abc:p></html>' self.assertEqual(xml, flatten(parseString(xml)))
def test_processingInstruction(self): xml = '''<html></html>''' self.failUnlessEqual(xml, flatten(parseString(xml)))
def test_entities(self): xml = """<p>&</p>""" self.assertEqual(xml, flatten(parseString(xml)))
def test_entities(self): xml = """<p>&</p>""" self.failUnlessEqual(xml, flatten(parseString(xml)))
def test_processingInstruction(self): xml = '''<html></html>''' self.assertEqual(xml, flatten(parseString(xml)))
def test_comment(self): xml = '''<!-- comment &£ --><html></html>''' self.failUnlessEqual(xml, flatten(parseString(xml)))
def test_doctype(self): xml = ( '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ' '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n' '<html></html>') self.assertEqual(norm(xml), norm(flatten(parseString(xml))))
def test_unicodeComment(self): xml = '''<!-- \xc2\xa3 --><html></html>''' self.failUnlessEqual(xml, flatten(parseString(xml)))
def test_parseString(self): xml = '''<html></html>''' self.assertEqual(xml, flatten(parseString(xml)))
def test_badNamespace(self): xml = '''<html foo:bar="wee"><abc:p>xyz</abc:p></html>''' self.failUnlessEqual(xml, flatten(parseString(xml)))
def test_parseString(self): xml = '''<html></html>''' self.assertEqual(xml, flatten(parseString(xml)))
def test_otherns(self): xml = '''<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms"><p>in default namespace</p><xf:input><xf:label>in another namespace</xf:label></xf:input></html>''' self.failUnlessEqual(xml, flatten(parseString(xml)))
def test_attrs(self): xml = '''<p class="foo"></p>''' self.assertEqual(xml, flatten(parseString(xml)))
def test_xmlns(self): xml = '''<html xmlns="http://www.w3.org/1999/xhtml"></html>''' self.assertEqual(xml, flatten(parseString(xml)))
def test_doctype(self): xml = ( '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ' '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n' '<html></html>') self.assertEqual(norm(xml), norm(flatten(parseString(xml))))