def js_obfuscate(content): """Obfuscate data in a Javascript tag. Example:: >>> js_obfuscate("<input type='hidden' name='check' value='valid' />") literal(u'<script type="text/javascript">\\n//<![CDATA[\\neval(unescape(\\'%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%69%6e%70%75%74%20%74%79%70%65%3d%27%68%69%64%64%65%6e%27%20%6e%61%6d%65%3d%27%63%68%65%63%6b%27%20%76%61%6c%75%65%3d%27%76%61%6c%69%64%27%20%2f%3e%27%29%3b\\'))\\n//]]>\\n</script>') """ doc_write = "document.write('%s');" % content obfuscated = ''.join(['%%%x' % ord(x) for x in doc_write]) complete = "eval(unescape('%s'))" % obfuscated cdata = HTML.cdata("\n", complete, "\n//") return HTML.script("\n//", cdata, "\n", type="text/javascript")
def js_obfuscate(content): """Obfuscate data in a Javascript tag. Example:: >>> js_obfuscate("<input type='hidden' name='check' value='valid' />") literal(u'<script type="text/javascript">\\n//<![CDATA[\\neval(unescape(\\'%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%69%6e%70%75%74%20%74%79%70%65%3d%27%68%69%64%64%65%6e%27%20%6e%61%6d%65%3d%27%63%68%65%63%6b%27%20%76%61%6c%75%65%3d%27%76%61%6c%69%64%27%20%2f%3e%27%29%3b\\'))\\n//]]>\\n</script>') """ doc_write = "document.write(%s);" % js_quote_string(content) obfuscated = ''.join(['%%%x' % ord(x) for x in doc_write]) complete = "eval(unescape('%s'))" % obfuscated cdata = HTML.cdata("\n", complete, "\n//") return HTML.tag("script", "\n//", cdata, "\n", type="text/javascript")
def test_cdata2(self): a = HTML.cdata(u"<p>") b = literal("<![CDATA[<p>]]>") self.check(a, b)
def test_cdata(self): a = HTML.cdata("Foo") b = literal("<![CDATA[Foo]]>") self.check(a, b)