#!/usr/local/Python-2.4/bin/python
#!/usr/bin/env python
"""
CGI interface to xsltproc
Share and Enjoy.
"""
import cgi, sys, os, urllib
import cgitb; cgitb.enable()
from urlparse import urlparse, urlunparse
XSLTPROC='/usr/bin/xsltproc'
#XSLTPROC='/usr/bin/env xsltproc'
#XSLTPROC='/Users/deusx/local/bin/xsltproc'
Page = """
xsltproc service
Process your XSLT
"""
Page2 = """
"""
def serveRequest():
if os.environ.get('PATH_INFO','') != '' and os.environ.get('QUERY_STRING','') == '':
os.environ['QUERY_STRING'] = os.environ['PATH_INFO'][1:]
fields = cgi.FieldStorage()
docAddr = fields.has_key('docAddr') and urlunparse(urlparse(fields['docAddr'].value)) or ''
xslAddr = fields.has_key('xslAddr') and urlunparse(urlparse(fields['xslAddr'].value)) or ''
if not fields.has_key('docAddr'):
print "Content-Type: text/html"
print
print Page
print Page2 % (xslAddr, docAddr)
else:
print "Content-Type: text/xml"
print ""
sys.stdout.flush()
os.system(" ".join((XSLTPROC, '"%s"' % xslAddr, '"%s"' % docAddr)))
if __name__ == '__main__':
if os.environ.has_key('SCRIPT_NAME'):
serveRequest()