tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

generate.py (2130B)


      1 #!/usr/bin/python
      2 
      3 import os
      4 import sys
      5 
      6 THIS_NAME = u"generate.py"
      7 
      8 # Note: these lists must be kept in sync with the lists in
      9 # Document-createElement-namespace.html, and this script must be run whenever
     10 # the lists are updated.  (We could keep the lists in a shared JSON file, but
     11 # seems like too much effort.)
     12 FILES = (
     13    (u"empty", u""),
     14    (u"minimal_html", u"<!doctype html><title></title>"),
     15 
     16    (u"xhtml", u'<html xmlns="http://www.w3.org/1999/xhtml"></html>'),
     17    (u"svg", u'<svg xmlns="http://www.w3.org/2000/svg"></svg>'),
     18    (u"mathml", u'<mathml xmlns="http://www.w3.org/1998/Math/MathML"></mathml>'),
     19 
     20    (u"bare_xhtml", u"<html></html>"),
     21    (u"bare_svg", u"<svg></svg>"),
     22    (u"bare_mathml", u"<math></math>"),
     23 
     24    (u"xhtml_ns_removed", u"""\
     25 <html xmlns="http://www.w3.org/1999/xhtml">
     26  <head><script>
     27    var newRoot = document.createElementNS(null, "html");
     28    document.removeChild(document.documentElement);
     29    document.appendChild(newRoot);
     30  </script></head>
     31 </html>
     32 """),
     33    (u"xhtml_ns_changed", u"""\
     34 <html xmlns="http://www.w3.org/1999/xhtml">
     35  <head><script>
     36    var newRoot = document.createElementNS("http://www.w3.org/2000/svg", "abc");
     37    document.removeChild(document.documentElement);
     38    document.appendChild(newRoot);
     39  </script></head>
     40 </html>
     41 """),
     42 )
     43 
     44 EXTENSIONS = (
     45    u"html",
     46    u"xhtml",
     47    u"xml",
     48    u"svg",
     49    # Was not able to get server MIME type working properly :(
     50    #"mml",
     51 )
     52 
     53 def __main__():
     54    if len(sys.argv) > 1:
     55        print(u"No arguments expected, aborting")
     56        return
     57 
     58    if not os.access(THIS_NAME, os.F_OK):
     59        print(u"Must be run from the directory of " + THIS_NAME + u", aborting")
     60        return
     61 
     62    for name in os.listdir(u"."):
     63        if name == THIS_NAME:
     64            continue
     65        os.remove(name)
     66 
     67    manifest = open(u"MANIFEST", u"w")
     68 
     69    for name, contents in FILES:
     70        for extension in EXTENSIONS:
     71            f = open(name + u"." + extension, u"w")
     72            f.write(contents)
     73            f.close()
     74            manifest.write(u"support " + name + u"." + extension + u"\n")
     75 
     76    manifest.close()
     77 
     78 __main__()