def test_script_escaping_with_namespace(self): text = """<script xmlns="http://www.w3.org/1999/xhtml"> if (1 < 2) { alert("Doh"); } </script>""" output = XML(text).render(HTMLSerializer) self.assertEqual("""<script> if (1 < 2) { alert("Doh"); } </script>""", output)
def test_empty_script(self): text = """<html xmlns="http://www.w3.org/1999/xhtml"> <script src="foo.js" /> </html>""" output = XML(text).render(XHTMLSerializer) self.assertEqual("""<html xmlns="http://www.w3.org/1999/xhtml"> <script src="foo.js"></script> </html>""", output)
def test_style_escaping_with_namespace(self): text = """<style xmlns="http://www.w3.org/1999/xhtml"> html > body { display: none; } </style>""" output = XML(text).render(HTMLSerializer) self.assertEqual("""<style> html > body { display: none; } </style>""", output)
def test_embedded_svg(self): text = """<html xmlns="http://www.w3.org/1999/xhtml" xmlns:svg="http://www.w3.org/2000/svg"> <body> <button> <svg:svg width="600px" height="400px"> <svg:polygon id="triangle" points="50,50 50,300 300,300"></svg:polygon> </svg:svg> </button> </body> </html>""" output = XML(text).render(XHTMLSerializer) self.assertEqual(text, output)
def test_atom_with_xhtml(self): text = """<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"> <id>urn:uuid:c60843aa-0da8-4fa6-bbe5-98007bc6774e</id> <updated>2007-01-28T11:36:02.807108-06:00</updated> <title type="xhtml"> <div xmlns="http://www.w3.org/1999/xhtml">Example</div> </title> <subtitle type="xhtml"> <div xmlns="http://www.w3.org/1999/xhtml">Bla bla bla</div> </subtitle> <icon/> </feed>""" output = XML(text).render(XMLSerializer) self.assertEqual(text, output)
def test_style_escaping(self): text = '<style>html > body { display: none; }</style>' output = XML(text).render(HTMLSerializer) self.assertEqual('<style>html > body { display: none; }</style>', output)
def test_script_escaping(self): text = '<script>if (1 < 2) { alert("Doh"); }</script>' output = XML(text).render(HTMLSerializer) self.assertEqual('<script>if (1 < 2) { alert("Doh"); }</script>', output)
def test_empty_script(self): text = '<script src="foo.js" />' output = XML(text).render(XHTMLSerializer) self.assertEqual('<script src="foo.js"></script>', output)
def test_xml_space(self): text = '<foo xml:space="preserve"> Do not mess \n\n with me </foo>' output = XML(text).render(HTMLSerializer) self.assertEqual('<foo> Do not mess \n\n with me </foo>', output)
def test_text_content(self): stream = XML('<elem>foo</elem>') | EmptyTagFilter() self.assertEqual([Stream.START, Stream.TEXT, Stream.END], [ev[0] for ev in stream])
def test_xhtml_namespace_prefix(self): text = """<div xmlns="http://www.w3.org/1999/xhtml"> <strong>Hello</strong> </div>""" output = XML(text).render(XHTMLSerializer) self.assertEqual(text, output)
def test_style_escaping_with_namespace(self): text = """<style xmlns="http://www.w3.org/1999/xhtml">/*<![CDATA[*/ html > body { display: none; } /*]]>*/</style>""" output = XML(text).render(XHTMLSerializer) self.assertEqual(text, output)
def test_style_escaping(self): text = """<style>/*<![CDATA[*/ html > body { display: none; } /*]]>*/</style>""" output = XML(text).render(XHTMLSerializer) self.assertEqual(text, output)
def test_script_escaping_with_namespace(self): text = """<script xmlns="http://www.w3.org/1999/xhtml">/*<![CDATA[*/ if (1 < 2) { alert("Doh"); } /*]]>*/</script>""" output = XML(text).render(XHTMLSerializer) self.assertEqual(text, output)
def test_script_escaping(self): text = """<script>/*<![CDATA[*/ if (1 < 2) { alert("Doh"); } /*]]>*/</script>""" output = XML(text).render(XHTMLSerializer) self.assertEqual(text, output)
def test_empty(self): stream = XML('<elem></elem>') | EmptyTagFilter() self.assertEqual([EmptyTagFilter.EMPTY], [ev[0] for ev in stream])
def test_textarea_whitespace(self): content = '\nHey there. \n\n I am indented.\n' stream = XML('<textarea name="foo">%s</textarea>' % content) output = stream.render(HTMLSerializer) self.assertEqual('<textarea name="foo">%s</textarea>' % content, output)
def test_elem_content(self): stream = XML('<elem><sub /><sub /></elem>') | EmptyTagFilter() self.assertEqual([Stream.START, EmptyTagFilter.EMPTY, EmptyTagFilter.EMPTY, Stream.END], [ev[0] for ev in stream])
def test_pre_whitespace(self): content = '\nHey <em>there</em>. \n\n I am indented.\n' stream = XML('<pre>%s</pre>' % content) output = stream.render(HTMLSerializer) self.assertEqual('<pre>%s</pre>' % content, output)