Merge pull request #1844 from ilvalle/fix_STYLE_py3

fix py3 STYLE and SCRIPT tags
This commit is contained in:
mdipierro
2018-02-09 12:27:01 -06:00
committed by GitHub
2 changed files with 14 additions and 10 deletions
+9 -7
View File
@@ -1419,20 +1419,21 @@ class LINK(DIV):
class SCRIPT(DIV): class SCRIPT(DIV):
tag = 'script' tag = b'script'
tagname = to_bytes(tag)
def xml(self): def xml(self):
(fa, co) = self._xml() (fa, co) = self._xml()
fa = to_native(fa) fa = to_bytes(fa)
# no escaping of subcomponents # no escaping of subcomponents
co = '\n'.join([str(component) for component in co = b'\n'.join([to_bytes(component) for component in
self.components]) self.components])
if co: if co:
# <script [attributes]><!--//--><![CDATA[//><!-- # <script [attributes]><!--//--><![CDATA[//><!--
# script body # script body
# //--><!]]></script> # //--><!]]></script>
# return '<%s%s><!--//--><![CDATA[//><!--\n%s\n//--><!]]></%s>' % (self.tag, fa, co, self.tag) # return '<%s%s><!--//--><![CDATA[//><!--\n%s\n//--><!]]></%s>' % (self.tag, fa, co, self.tag)
return '<%s%s><!--\n%s\n//--></%s>' % (self.tag, fa, co, self.tag) return b'<%s%s><!--\n%s\n//--></%s>' % (self.tagname, fa, co, self.tagname)
else: else:
return DIV.xml(self) return DIV.xml(self)
@@ -1440,18 +1441,19 @@ class SCRIPT(DIV):
class STYLE(DIV): class STYLE(DIV):
tag = 'style' tag = 'style'
tagname = to_bytes(tag)
def xml(self): def xml(self):
(fa, co) = self._xml() (fa, co) = self._xml()
fa = to_native(fa) fa = to_bytes(fa)
# no escaping of subcomponents # no escaping of subcomponents
co = '\n'.join([str(component) for component in co = b'\n'.join([to_bytes(component) for component in
self.components]) self.components])
if co: if co:
# <style [attributes]><!--/*--><![CDATA[/*><!--*/ # <style [attributes]><!--/*--><![CDATA[/*><!--*/
# style body # style body
# /*]]>*/--></style> # /*]]>*/--></style>
return '<%s%s><!--/*--><![CDATA[/*><!--*/\n%s\n/*]]>*/--></%s>' % (self.tag, fa, co, self.tag) return b'<%s%s><!--/*--><![CDATA[/*><!--*/\n%s\n/*]]>*/--></%s>' % (self.tagname, fa, co, self.tagname)
else: else:
return DIV.xml(self) return DIV.xml(self)
+5 -3
View File
@@ -340,18 +340,20 @@ class TestBareHelpers(unittest.TestCase):
def test_SCRIPT(self): def test_SCRIPT(self):
self.assertEqual(SCRIPT('<>', _a='1', _b='2').xml(), self.assertEqual(SCRIPT('<>', _a='1', _b='2').xml(),
'''<script a="1" b="2"><!-- b'''<script a="1" b="2"><!--
<> <>
//--></script>''') //--></script>''')
self.assertEqual(SCRIPT('<>').xml(), self.assertEqual(SCRIPT('<>').xml(),
'''<script><!-- b'''<script><!--
<> <>
//--></script>''') //--></script>''')
self.assertEqual(SCRIPT().xml(), b'<script></script>') self.assertEqual(SCRIPT().xml(), b'<script></script>')
self.assertEqual(SCRIPT(';').xml() + DIV().xml(),
b'<script><!--\n;\n//--></script><div></div>')
def test_STYLE(self): def test_STYLE(self):
self.assertEqual(STYLE('<>', _a='1', _b='2').xml(), self.assertEqual(STYLE('<>', _a='1', _b='2').xml(),
'<style a="1" b="2"><!--/*--><![CDATA[/*><!--*/\n<>\n/*]]>*/--></style>') b'<style a="1" b="2"><!--/*--><![CDATA[/*><!--*/\n<>\n/*]]>*/--></style>')
# Try to hit : return DIV.xml(self) # Try to hit : return DIV.xml(self)
self.assertEqual(STYLE().xml(), b'<style></style>') self.assertEqual(STYLE().xml(), b'<style></style>')