diff --git a/Demo/cgi/cgi0.sh b/Demo/cgi/cgi0.sh new file mode 100755 index 00000000000..5cefcd37c44 --- /dev/null +++ b/Demo/cgi/cgi0.sh @@ -0,0 +1,8 @@ +#! /bin/sh + +# If you can't get this to work, your web server isn't set up right + +echo Content-type: text/plain +echo +echo Hello world +echo This is cgi0.sh diff --git a/Demo/cgi/cgi1.py b/Demo/cgi/cgi1.py new file mode 100755 index 00000000000..5dd7d2c0a5d --- /dev/null +++ b/Demo/cgi/cgi1.py @@ -0,0 +1,14 @@ +#!/usr/local/bin/python + +"""CGI test 1 - check server setup.""" + +# Until you get this to work, your web server isn't set up right or +# your Python isn't set up right. + +# If cgi0.sh works but cgi1.py, check the #! line and the file +# permissions. The docs for the cgi.py module have debugging tips. + +print "Content-type: text/html" +print +print "
This is cgi1.py" diff --git a/Demo/cgi/cgi2.py b/Demo/cgi/cgi2.py new file mode 100755 index 00000000000..d956f6538c6 --- /dev/null +++ b/Demo/cgi/cgi2.py @@ -0,0 +1,22 @@ +#!/usr/local/bin/python + +"""CGI test 2 - basic use of cgi module.""" + +import cgitb; cgitb.enable() + +import cgi + +def main(): + form = cgi.FieldStorage() + print "Content-type: text/html" + print + if not form: + print "
", cgi.escape(key), ":", cgi.escape(value) + +if __name__ == "__main__": + main() diff --git a/Demo/cgi/cgi3.py b/Demo/cgi/cgi3.py new file mode 100755 index 00000000000..bdb2cb7aa2a --- /dev/null +++ b/Demo/cgi/cgi3.py @@ -0,0 +1,113 @@ +#!/usr/local/bin/python + +"""CGI test 3 (persistent data).""" + +import cgitb; cgitb.enable() + +import os, re, cgi, sys +escape = cgi.escape + +def main(): + form = cgi.FieldStorage() + print "Content-type: text/html" + print + cmd = form.getvalue("cmd") or "view" + page = form.getvalue("page") or "FrontPage" + wiki = WikiPage(page) + wiki.load() + method = getattr(wiki, 'cmd_' + cmd, None) or wiki.cmd_view + method(form) + +class WikiPage: + + homedir = os.path.dirname(sys.argv[0]) + scripturl = os.path.basename(sys.argv[0]) + + def __init__(self, name): + self.name = name + self.load() + + def cmd_view(self, form): + print "
" + for line in self.data.splitlines(): + line = line.rstrip() + if not line: + print "
" + continue + words = re.split('(\W+)', line) + for i in range(len(words)): + word = words[i] + if self.iswikiword(word): + if os.path.isfile(self.mkfile(word)): + word = self.mklink("view", word, word) + else: + word = self.mklink("new", word, word + "*") + else: + word = escape(word) + words[i] = word + print "".join(words) + print "
", self.mklink("edit", self.name, "Edit this page") + "," + print self.mklink("view", "FrontPage", "go to front page") + "." + + def cmd_edit(self, form, label="Change"): + print "