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