1#!/usr/bin/python 2 3from __future__ import print_function 4 5import os 6import sys 7 8THIS_NAME = u"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 (u"empty", u""), 16 (u"minimal_html", u"<!doctype html><title></title>"), 17 18 (u"xhtml", u'<html xmlns="http://www.w3.org/1999/xhtml"></html>'), 19 (u"svg", u'<svg xmlns="http://www.w3.org/2000/svg"></svg>'), 20 (u"mathml", u'<mathml xmlns="http://www.w3.org/1998/Math/MathML"></mathml>'), 21 22 (u"bare_xhtml", u"<html></html>"), 23 (u"bare_svg", u"<svg></svg>"), 24 (u"bare_mathml", u"<math></math>"), 25 26 (u"xhtml_ns_removed", u"""\ 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 (u"xhtml_ns_changed", u"""\ 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 u"html", 48 u"xhtml", 49 u"xml", 50 u"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(u"No arguments expected, aborting") 58 return 59 60 if not os.access(THIS_NAME, os.F_OK): 61 print(u"Must be run from the directory of " + THIS_NAME + u", aborting") 62 return 63 64 for name in os.listdir(u"."): 65 if name == THIS_NAME: 66 continue 67 os.remove(name) 68 69 manifest = open(u"MANIFEST", u"w") 70 71 for name, contents in FILES: 72 for extension in EXTENSIONS: 73 f = open(name + u"." + extension, u"w") 74 f.write(contents) 75 f.close() 76 manifest.write(u"support " + name + u"." + extension + u"\n") 77 78 manifest.close() 79 80__main__() 81