W3C home > Mailing lists > Public > public-webapps@w3.org > October to December 2009

Re: [XHR][XHR2] single source file

From: Anne van Kesteren <annevk@opera.com>
Date: Thu, 24 Dec 2009 14:41:20 +0100
To: marcosc@opera.com
Cc: "WebApps WG" <public-webapps@w3.org>
Message-ID: <op.u5f2y1x864w2qv@annevk-t60>
On Thu, 24 Dec 2009 14:21:11 +0100, Marcos Caceres <marcosc@opera.com>  
wrote:
> Nice idea; the idea of using a single source to output various docs
> seems very useful. Can you give us a brief description of what tools
> you are using to output the different sources?

Just a simple Python script (quite dirty and some duplicate code, but it  
works and is trivial):

# GENERATE XHR

import urllib
import urllib2
import re

def generate_specs():
     source = open("./XMLHttpRequest-2/xhr-source", "r").read()
     generate_xhr1(source)
     generate_xhr2(source)

def generate_xhr1(source):
     find_xhr2 = re.compile("<!--START xhr2-->.+?<!--END xhr2-->",  
re.DOTALL)
     find_markers = re.compile("<!--(START|END).*?-->", re.DOTALL)
     newsource = find_markers.sub("", find_xhr2.sub("", source))

     file = open("./XMLHttpRequest/Overview.src.html", "w")
     file.write(newsource)
     file.close()

     file = open("./XMLHttpRequest/Overview.html", "w")
     file.write(generate_output(newsource))
     file.close()

def generate_xhr2(source):
     # XXX pre-process source
     find_xhr1 = re.compile("<!--START xhr1-->.+?<!--END xhr1-->",  
re.DOTALL)
     find_markers = re.compile("<!--(START|END).*?-->", re.DOTALL)
     newsource = find_markers.sub("", find_xhr1.sub("", source))

     file = open("./XMLHttpRequest-2/Overview.src.html", "w")
     file.write(newsource)
     file.close()

     file = open("./XMLHttpRequest-2/Overview.html", "w")
     file.write(generate_output(newsource))
     file.close()

def generate_output(source):
     url = "http://cgi.w3.org/member-bin/process.cgi"
     username = "youcanprobablyfigurethisoneout"
     password = "butiamnotsharingitwithyou"
     params = urllib.urlencode({
	    "file": source,
	    "group": "none",
	    "output": "html",
	    "method": "file"
     })

     password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm()
     password_manager.add_password(None, "http://cgi.w3.org/", username,  
password)
     auth_handler = urllib2.HTTPBasicAuthHandler(password_manager)
     opener = urllib2.build_opener(auth_handler)
     urllib2.install_opener(opener)

     return urllib2.urlopen(url, params).read()

if __name__ == '__main__':
     generate_specs()


-- 
Anne van Kesteren
http://annevankesteren.nl/
Received on Thursday, 24 December 2009 13:41:54 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 18:49:35 GMT