SVN: r25575 - trunk/quixote/demo
Neil Schemenauer <nascheme-fVcApmY9cLvQ3/1i3zOLAti2O/[email protected]> Thu, 11 Nov 2004 11:57:48 -0500
| Newsgroups | gmane.comp.web.quixote.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: nascheme
Date: 2004-11-11 11:56:44 -0500 (Thu, 11 Nov 2004)
New Revision: 25575
Added:
trunk/quixote/demo/altdemo.py
trunk/quixote/demo/extras.ptl
trunk/quixote/demo/integers.ptl
trunk/quixote/demo/root.ptl
Removed:
trunk/quixote/demo/demo1.py
trunk/quixote/demo/demo_scgi.py
trunk/quixote/demo/demo_scgi.sh
trunk/quixote/demo/integer_ui.py
trunk/quixote/demo/pages.ptl
trunk/quixote/demo/q.ico
trunk/quixote/demo/run_cgi.py
trunk/quixote/demo/upload.cgi
Modified:
trunk/quixote/demo/__init__.py
trunk/quixote/demo/demonstrate.py
Log:
Overhaul the demo. Move advanced stuff into 'extras' subdirectory.
Modified: trunk/quixote/demo/__init__.py
===================================================================
--- trunk/quixote/demo/__init__.py 2004-11-11 15:38:44 UTC (rev 25574)
+++ trunk/quixote/demo/__init__.py 2004-11-11 16:56:44 UTC (rev 25575)
@@ -1,60 +1,10 @@
-
-_q_exports = ["simple", "error", "publish_error",
- "form_demo", "dumpreq", "srcdir",
- ("favicon.ico", "q_ico")]
-
-import sys
-import os
-from quixote import get_response, enable_ptl
+"""$URL$
+$Id$
+"""
+from quixote import enable_ptl
from quixote.publish import Publisher
-from quixote.directory import Directory, Resolving
-from quixote.errors import PublishError
-from quixote.util import StaticDirectory, StaticFile
enable_ptl()
-from quixote.demo.pages import _q_index, _q_exception_handler, dumpreq
-from quixote.demo.integer_ui import IntegerUI
-from quixote.demo.session import SessionUI
-from quixote.demo import forms
-class DemoUI(Resolving, Directory):
-
- _q_exports = ["", "simple", "error", "publish_error", "widgets",
- "form_demo", "dumpreq", "srcdir",
- ("favicon.ico", "q_ico")]
-
- def _q_index(self):
- return _q_index()
-
- def simple(self):
- # This function returns a plain text document, not HTML.
- get_response().set_content_type("text/plain")
- return "This is the Python function 'quixote.demo.simple'.\n"
-
- def error(self):
- raise ValueError, "this is a Python exception"
-
- def publish_error(self):
- raise PublishError("Publishing error raised by publish_error")
-
- def dumpreq(self):
- return dumpreq()
-
- def _q_lookup(self, component):
- return IntegerUI(component)
-
- def _q_resolve(self, component):
- # _q_resolve() is a hook that can be used to import only
- # when it's actually accessed. This can be used to make
- # start-up of your application faster, because it doesn't have
- # to import every single module when it starts running.
- if component == 'form_demo':
- from quixote.demo.forms import form_demo
- return form_demo
-
- _curdir = os.path.dirname(forms.__file__)
- srcdir = StaticDirectory(_curdir, list_directory=1)
- q_ico = StaticFile(os.path.join(_curdir, 'q.ico'))
-
-
def create_publisher():
- return Publisher(DemoUI(), display_exceptions='plain')
+ from quixote.demo.root import RootDirectory
+ return Publisher(RootDirectory(), display_exceptions='plain')
Copied: trunk/quixote/demo/altdemo.py (from rev 25574, trunk/quixote/demo/demo1.py)
===================================================================
--- trunk/quixote/demo/demo1.py 2004-11-11 15:38:44 UTC (rev 25574)
+++ trunk/quixote/demo/altdemo.py 2004-11-11 16:56:44 UTC (rev 25575)
@@ -0,0 +1,87 @@
+"""$URL$
+$Id$
+
+An alternative Quixote demo. This version is contained in a single module
+and does not use PTL.
+"""
+from quixote import get_response
+from quixote.directory import Directory
+from quixote.errors import PublishError
+from quixote.html import href
+from quixote.util import dump_request
+
+def format_page(title, content, style_sheet="/base.css"):
+ return ('<html><head><title>%(title)s</title>'
+ '<link rel="stylesheet" href="%(style_sheet)s" type="text/css">'
+ '</head><body>%(content)s</body></html>') % locals()
+
+def format_request():
+ return format_page('Request', dump_request())
+
+def format_link_list(targets):
+ return '<ul>%s</ul>' % ''.join([
+ '<li>%s</li>' % href(target, target) for target in targets])
+
+class SubDirectory(Directory):
+
+ _q_exports = ["", "dumpreq"]
+
+ dumpreq = format_request
+
+ def _q_index(self):
+ return format_page('Lookup', format_link_list(range(5)))
+
+ def _q_lookup(self, component):
+ return format_page(
+ 'Found: %s' % component,
+ '<div style="font-size:x-large">%s</div>' % component)
+
+class RootDirectory(Directory):
+
+ _q_exports = ["",
+ "simple",
+ "error",
+ "publish_error",
+ "dumpreq",
+ ("base.css", "css"),
+ "sub"]
+
+ def _q_index(self):
+ """
+ This is exported as "".
+ """
+ s = ('This demonstation is intended to show the basic '
+ 'Quixote traversal pattern in action. ')
+ s += '<ul>'
+ for item in self._q_exports:
+ if item:
+ if type(item) is tuple:
+ name = item[0]
+ elif callable(getattr(self, item)):
+ name = item
+ else:
+ name = item + '/'
+ s += '<li>%s</li>' % href(name, name)
+ s += '</ul>'
+ return format_page('Demo1', s)
+
+ def simple(self):
+ # This function returns a plain text document, not HTML.
+ get_response().set_content_type("text/plain")
+ return "This is the Python function 'quixote.demo.simple'.\n"
+
+ def error(self):
+ raise ValueError, "this is a Python exception"
+
+ def publish_error(self):
+ raise PublishError("Publishing error raised by publish_error")
+
+ def css(self):
+ get_response().set_content_type("text/css")
+ return 'body { border: thick solid green; padding: 2em; }'
+
+ def dumpreq(self):
+ return format_request()
+
+ sub = SubDirectory()
+
Deleted: trunk/quixote/demo/demo1.py
===================================================================
--- trunk/quixote/demo/demo1.py 2004-11-11 15:38:44 UTC (rev 25574)
+++ trunk/quixote/demo/demo1.py 2004-11-11 16:56:44 UTC (rev 25575)
@@ -1,84 +0,0 @@
-"""$URL$
-$Id$
-"""
-from quixote import get_response
-from quixote.directory import Directory
-from quixote.errors import PublishError
-from quixote.html import href
-from quixote.util import dump_request
-
-def format_page(title, content, style_sheet="/base.css"):
- return ('<html><head><title>%(title)s</title>'
- '<link rel="stylesheet" href="%(style_sheet)s" type="text/css">'
- '</head><body>%(content)s</body></html>') % locals()
-
-def format_request():
- return format_page('Request', dump_request())
-
-def format_link_list(targets):
- return '<ul>%s</ul>' % ''.join([
- '<li>%s</li>' % href(target, target) for target in targets])
-
-class SubDirectory(Directory):
-
- _q_exports = ["", "dumpreq"]
-
- dumpreq = format_request
-
- def _q_index(self):
- return format_page('Lookup', format_link_list(range(5)))
-
- def _q_lookup(self, component):
- return format_page(
- 'Found: %s' % component,
- '<div style="font-size:x-large">%s</div>' % component)
-
-class RootDirectory(Directory):
-
- _q_exports = ["",
- "simple",
- "error",
- "publish_error",
- "dumpreq",
- ("base.css", "css"),
- "sub"]
-
- def _q_index(self):
- """
- This is exported as "".
- """
- s = ('This demonstation is intended to show the basic '
- 'Quixote traversal pattern in action. ')
- s += '<ul>'
- for item in self._q_exports:
- if item:
- if type(item) is tuple:
- name = item[0]
- elif callable(getattr(self, item)):
- name = item
- else:
- name = item + '/'
- s += '<li>%s</li>' % href(name, name)
- s += '</ul>'
- return format_page('Demo1', s)
-
- def simple(self):
- # This function returns a plain text document, not HTML.
- get_response().set_content_type("text/plain")
- return "This is the Python function 'quixote.demo.simple'.\n"
-
- def error(self):
- raise ValueError, "this is a Python exception"
-
- def publish_error(self):
- raise PublishError("Publishing error raised by publish_error")
-
- def css(self):
- get_response().set_content_type("text/css")
- return 'body { border: thick solid green; padding: 2em; }'
-
- def dumpreq(self):
- return format_request()
-
- sub = SubDirectory()
-
Deleted: trunk/quixote/demo/demo_scgi.py
===================================================================
--- trunk/quixote/demo/demo_scgi.py 2004-11-11 15:38:44 UTC (rev 25574)
+++ trunk/quixote/demo/demo_scgi.py 2004-11-11 16:56:44 UTC (rev 25575)
@@ -1,30 +0,0 @@
-#!/www/python/bin/python
-
-# Example SCGI driver script for the Quixote demo: publishes the contents of
-# the quixote.demo package. To use this script with mod_scgi and Apache
-# add the following section of your Apache config file:
-#
-# <Location "^/qdemo/">
-# SCGIServer 127.0.0.1 4000
-# SCGIHandler On
-# </Location>
-
-
-from scgi.quixote_handler import QuixoteHandler, main
-from quixote import enable_ptl
-from quixote.publisher import Publisher
-from quixote.demo import DemoUI
-
-class DemoPublisher(Publisher):
- def __init__(self, *args):
- Publisher.__init__(self, display_exceptions='plain', *args)
-
-class DemoHandler(QuixoteHandler):
- publisher_class = DemoPublisher
- root_directory = DemoUI()
- prefix = "/qdemo"
-
-
-# Install the import hook that enables PTL modules.
-enable_ptl()
-main(DemoHandler)
Deleted: trunk/quixote/demo/demo_scgi.sh
===================================================================
--- trunk/quixote/demo/demo_scgi.sh 2004-11-11 15:38:44 UTC (rev 25574)
+++ trunk/quixote/demo/demo_scgi.sh 2004-11-11 16:56:44 UTC (rev 25575)
@@ -1,52 +0,0 @@
-#!/bin/sh
-#
-# Example init.d script for demo_scgi.py server
-
-PATH=/bin:/usr/bin:/usr/local/bin
-DAEMON=./demo_scgi.py
-PIDFILE=/var/tmp/demo_scgi.pid
-
-NAME=`basename $DAEMON`
-case "$1" in
- start)
- if [ -f $PIDFILE ]; then
- if ps -p `cat $PIDFILE` > /dev/null 2>&1 ; then
- echo "$NAME appears to be already running ($PIDFILE exists)."
- exit 1
- else
- echo "$PIDFILE exists, but appears to be obsolete; removing it"
- rm $PIDFILE
- fi
- fi
-
- echo -n "Starting $NAME: "
- env -i PATH=$PATH \
- $DAEMON -P $PIDFILE -l /var/tmp/quixote-error.log
- echo "done"
- ;;
-
- stop)
- if [ -f $PIDFILE ]; then
- echo -n "Stopping $NAME: "
- kill `cat $PIDFILE`
- echo "done"
- if ps -p `cat $PIDFILE` > /dev/null 2>&1 ; then
- echo "$NAME is still running, not removing $PIDFILE"
- else
- rm -f $PIDFILE
- fi
- else
- echo "$NAME does not appear to be running ($PIDFILE doesn't exist)."
- fi
- ;;
-
- restart)
- $0 stop
- $0 start
- ;;
-
- *)
- echo "Usage: $0 {start|stop|restart}"
- exit 1
- ;;
-esac
Modified: trunk/quixote/demo/demonstrate.py
===================================================================
--- trunk/quixote/demo/demonstrate.py 2004-11-11 15:38:44 UTC (rev 25574)
+++ trunk/quixote/demo/demonstrate.py 2004-11-11 16:56:44 UTC (rev 25575)
@@ -97,7 +97,7 @@
'--port', dest="port", default=default_port,
type="int",
help="Port for the server to listen on. (default=%s)" % default_port)
- default_root_directory = 'quixote.demo.demo1.RootDirectory'
+ default_root_directory = 'quixote.demo.root.RootDirectory'
parser.add_option(
'--directory', dest="root_directory",
default=default_root_directory,
Added: trunk/quixote/demo/extras.ptl
===================================================================
--- trunk/quixote/demo/extras.ptl 2004-11-11 15:38:44 UTC (rev 25574)
+++ trunk/quixote/demo/extras.ptl 2004-11-11 16:56:44 UTC (rev 25575)
@@ -0,0 +1,53 @@
+"""$URL$
+$Id$
+"""
+import os
+from quixote.directory import Directory, Resolving
+from quixote.util import StaticDirectory
+from quixote.demo.integers import IntegerUI
+
+class ExtraDirectory(Resolving, Directory):
+
+ _q_exports = ["", "form", "upload", "src"]
+
+ def _q_index [html] (self):
+ """
+ <html>
+ <head><title>Quixote Demo Extras</title></head>
+ <body>
+ <h1>Extras</h1>
+ <p>
+ Here are some more features of this demo:
+ <ul>
+ <li><a href="12/">12/</a>:
+ A Python object published through <code>_q_lookup()</code>.
+ <li><a href="12/factorial">12/factorial</a>:
+ A method on a published Python object.
+ <li><a href="form">form</a>:
+ A Quixote form in action.
+ <li><a href="upload">upload</a>:
+ A demo of file uploads.
+ <li><a href="src/">src/</a>:
+ A static directory published through Quixote.
+ </ul>
+ """
+
+
+ def _q_resolve(self, component):
+ # _q_resolve() is a hook that can be used to import only
+ # when it's actually accessed. This can be used to make
+ # start-up of your application faster, because it doesn't have
+ # to import every single module when it starts running.
+ if component == 'form':
+ from quixote.demo.forms import form_demo
+ return form_demo
+
+ def _q_lookup(self, component):
+ return IntegerUI(component)
+
+ def upload(self):
+ return 'upload demo unfinished'
+
+ import quixote
+ src = StaticDirectory(os.path.dirname(quixote.__file__),
+ list_directory=True)
Deleted: trunk/quixote/demo/integer_ui.py
===================================================================
--- trunk/quixote/demo/integer_ui.py 2004-11-11 15:38:44 UTC (rev 25574)
+++ trunk/quixote/demo/integer_ui.py 2004-11-11 16:56:44 UTC (rev 25575)
@@ -1,61 +0,0 @@
-import sys
-from quixote import get_response, redirect
-from quixote.directory import Directory
-from quixote.errors import TraversalError
-
-def fact(n):
- f = 1L
- while n > 1:
- f *= n
- n -= 1
- return f
-
-class IntegerUI(Directory):
-
- _q_exports = ["", "factorial", "prev", "next"]
-
- def __init__(self, component):
- try:
- self.n = int(component)
- except ValueError, exc:
- raise TraversalError(str(exc))
-
- def factorial(self):
- if self.n > 10000:
- sys.stderr.write("warning: possible denial-of-service attack "
- "(request for factorial(%d))\n" % self.n)
- get_response().set_content_type("text/plain")
- return "%d! = %d\n" % (self.n, fact(self.n))
-
- def _q_index(self):
- return """\
- <html>
- <head><title>The Number %d</title></head>
- <body>
- You have selected the integer %d.<p>
-
- You can compute its <a href="factorial">factorial</a> (%d!)<p>
-
- Or, you can visit the web page for the
- <a href="../%d/">previous</a> or
- <a href="../%d/">next</a> integer.<p>
-
- Or, you can use redirects to visit the
- <a href="prev">previous</a> or
- <a href="next">next</a> integer. This makes
- it a bit easier to generate this HTML code, but
- it's less efficient -- your browser has to go through
- two request/response cycles. And someone still
- has to generate the URLs for the previous/next
- pages -- only now it's done in the <code>prev()</code>
- and <code>next()</code> methods for this integer.<p>
-
- </body>
- </html>
- """ % (self.n, self.n, self.n, self.n-1, self.n+1)
-
- def prev(self):
- return redirect("../%d/" % (self.n-1))
-
- def next(self):
- return redirect("../%d/" % (self.n+1))
Copied: trunk/quixote/demo/integers.ptl (from rev 25569, trunk/quixote/demo/integer_ui.py)
Deleted: trunk/quixote/demo/pages.ptl
===================================================================
--- trunk/quixote/demo/pages.ptl 2004-11-11 15:38:44 UTC (rev 25574)
+++ trunk/quixote/demo/pages.ptl 2004-11-11 16:56:44 UTC (rev 25575)
@@ -1,85 +0,0 @@
-# quixote.demo.pages
-#
-# Provides miscellaneous pages for the Quixote demo (currently
-# just the index page).
-
-__revision__ = "$Id$"
-
-from quixote.util import dump_request
-
-def _q_index [html] ():
- print "debug message from the index page"
- package_name = str('.').join(__name__.split(str('.'))[:-1])
- module_name = __name__
- """
- <html>
- <head><title>Quixote Demo</title></head>
- <body>
- <h1>Hello, world!</h1>
-
- <p>(This page is generated by the index function for the
- <code>%(package_name)s</code> package. This index function is
- actually a PTL template, <code>_q_index()</code>, in the
- <code>%(module_name)s</code> PTL module. Look in
- <a href="srcdir/pages.ptl">demo/pages.ptl</a> to
- see the source code for this PTL template.)
- </p>
-
- <p>To understand what's going on here, be sure to read the
- <code>doc/demo.txt</code> file included with Quixote.</p>
-
- <p>
- Here are some other features of this demo:
- <ul>
- <li><a href="simple">simple</a>:
- A Python function that generates a very simple document.
- <li><a href="error">error</a>:
- A Python function that raises an exception.
- <li><a href="publish_error">publish_error</a>:
- A Python function that raises
- a <code>PublishError</code> exception. This exception
- will be caught by a <code>_q_exception_handler</code> method.
- <li><a href="12/">12/</a>:
- A Python object published through <code>_q_lookup()</code>.
- <li><a href="12/factorial">12/factorial</a>:
- A method on a published Python object.
- <li><a href="dumpreq">dumpreq</a>:
- Print out the contents of the HTTPRequest object.
- <li><a href="form_demo">form demo</a>:
- A Quixote form in action.
- <li><a href="srcdir/">srcdir</a>:
- A static directory published through Quixote.
- </ul>
- </p>
- </body>
- </html>
- """ % vars()
-
-def _q_exception_handler [html] (exc):
- """
- <html>
- <head><title>Quixote Demo</title></head>
- <body>
- <h1>Exception Handler</h1>
- <p>A <code>_q_exception_handler</code> method, if present, is
- called when a <code>PublishError</code> exception is raised. It
- can do whatever it likes to provide a friendly page.
- </p>
- <p>Here's the exception that was raised:<br />
- <code>%r (%s)</code>.</p>
- </body>
- </html>
- """ % (exc, exc)
-
-def dumpreq [html] ():
- """
- <html>
- <head><title>HTTPRequest Object</title></head>
- <body>
- <h1>HTTPRequest Object</h1>
- """
- dump_request()
- """
- </body>
- </html>
- """
Deleted: trunk/quixote/demo/q.ico
===================================================================
(Binary files differ)
Added: trunk/quixote/demo/root.ptl
===================================================================
--- trunk/quixote/demo/root.ptl 2004-11-11 15:38:44 UTC (rev 25574)
+++ trunk/quixote/demo/root.ptl 2004-11-11 16:56:44 UTC (rev 25575)
@@ -0,0 +1,103 @@
+"""$URL$
+$Id$
+
+The root directory for the Quixote demo.
+"""
+from quixote import get_response
+from quixote.directory import Directory
+from quixote.errors import PublishError
+from quixote.util import dump_request
+from quixote.demo.extras import ExtraDirectory
+
+class RootDirectory(Directory):
+
+ _q_exports = ["", "simple", "plain", "error", "publish_error", "css",
+ "dumpreq", "extras", ("favicon.ico", "favicon_ico")]
+
+ def _q_index [html] (self):
+ print "debug message from the index page"
+ """
+ <html>
+ <head>
+ <title>Quixote Demo</title>
+ <link rel="stylesheet" href="css" type="text/css" />
+ </head>
+ <body>
+ <h1>Hello, world!</h1>
+
+ <p>To understand what's going on here, be sure to read the
+ <code>doc/demo.txt</code> file included with Quixote.</p>
+
+ <p>
+ Here are some features of this demo:
+ <ul>
+ <li><a href="simple">simple</a>:
+ A Python function that generates a very simple document.
+ <li><a href="plain">plain</a>:
+ A Python function that generates a plain text document.
+ <li><a href="error">error</a>:
+ A Python function that raises an exception.
+ <li><a href="publish_error">publish_error</a>:
+ A Python function that raises
+ a <code>PublishError</code> exception. This exception
+ will be caught by a <code>_q_exception_handler</code> method.
+ <li><a href="dumpreq">dumpreq</a>:
+ Print out the contents of the HTTPRequest object.
+ <li><a href="css">css</a>:
+ The stylesheet for this document.
+ <li><a href="extras/">extras/</a>:
+ Demos of some of Quixote's more advanced features.
+ </ul>
+ </p>
+ </body>
+ </html>
+ """
+
+ def simple [html] (self):
+ '<html><body>Hello!</body></html>'
+
+ def plain(self):
+ get_response().set_content_type("text/plain")
+ return "This is a plain text document."
+
+ def error(self):
+ raise ValueError, "this is a Python exception"
+
+ def publish_error(self):
+ raise PublishError("Publishing error raised by publish_error")
+
+ def dumpreq [html] (self):
+ """
+ <html>
+ <head><title>HTTPRequest Object</title></head>
+ <body>
+ <h1>HTTPRequest Object</h1>
+ """
+ dump_request()
+ """
+ </body>
+ </html>
+ """
+
+ def css(self):
+ get_response().set_content_type("text/css")
+ # on a real site we would also set the expires header
+ return 'body { border: thick solid green; padding: 2em; }'
+
+ def favicon_ico(self):
+ response = get_response()
+ response.set_content_type("image/x-icon")
+ response.set_expires(days=1)
+ return FAVICON
+
+ extras = ExtraDirectory()
+
+
+FAVICON = """\
+AAABAAEAEBAQAAEABAAoAQAAFgAAACgAAAAQAAAAIAAAAAEABAAAAAAAAAAAAAAAAAAAAAAAAAAA
+AAAAAADJZmEA4KilAMJQSwDZko8Aujo0AOi9uwDRfHgA9+npAP///wDw1NIAAAAAAAAAAAAAAAAA
+AAAAAAAAAAAAAAAAiIiIiIiIiIiIiIiIiIiIiIiIiIiSQDiIiIiIiGRYSIiIiIYkRFiIiIiFQlhk
+RYiIiIBAeGRAiIiIFEE2aUQYiIhkSHV4RGiIiGRIiIhEaIiIZEiIiERoiIiUSYiJRJiIiIZDiING
+iIiIh2RlEmeIiIiIiBYYiIiIiIiIiIiIiIgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+""".decode('base64')
Deleted: trunk/quixote/demo/run_cgi.py
===================================================================
--- trunk/quixote/demo/run_cgi.py 2004-11-11 15:38:44 UTC (rev 25574)
+++ trunk/quixote/demo/run_cgi.py 2004-11-11 16:56:44 UTC (rev 25575)
@@ -1,30 +0,0 @@
-# This is a simple script that makes it easy to write one file CGI
-# applications that use Quixote. To use, add the following line to the top
-# of your CGI script:
-#
-# #!/usr/local/bin/python <some_path>/run_cgi.py
-#
-# Your CGI script becomes the root namespace and you may use PTL syntax
-# inside the script. Errors will go to stderr and should end up in the server
-# error log.
-#
-# Note that this will be quite slow since the script will be recompiled on
-# every hit. If you are using Apache with mod_fastcgi installed you should be
-# able to use .fcgi as an extension instead of .cgi and get much better
-# performance. Maybe someday I will write code that caches the compiled
-# script on the filesystem. :-)
-
-import sys
-import new
-from quixote import enable_ptl, ptl_compile
-from quixote.publisher import Publisher
-
-enable_ptl()
-filename = sys.argv[1]
-root_code = ptl_compile.compile_template(open(filename), filename)
-root = new.module("root")
-root.__file__ = filename
-root.__name__ = "root"
-exec root_code in root.__dict__
-p = Publisher(root)
-p.publish_cgi()
Deleted: trunk/quixote/demo/upload.cgi
===================================================================
--- trunk/quixote/demo/upload.cgi 2004-11-11 15:38:44 UTC (rev 25574)
+++ trunk/quixote/demo/upload.cgi 2004-11-11 16:56:44 UTC (rev 25575)
@@ -1,61 +0,0 @@
-#!/www/python/bin/python
-
-# Simple demo of HTTP upload with Quixote. Also serves as an example
-# of how to put a (simple) Quixote application into a single file.
-
-__revision__ = "$Id$"
-
-import os
-import stat
-from quixote import Publisher
-from quixote.html import html_quote
-
-_q_exports = ['receive']
-
-def header (title):
- return '''\
- <html><head><title>%s</title></head>
- <body>
- ''' % title
-
-def footer ():
- return '</body></html>\n'
-
-def _q_index (request):
- return header("Quixote Upload Demo") + '''\
- <form enctype="multipart/form-data"
- method="POST"
- action="receive">
- Your name:<br>
- <input type="text" name="name"><br>
- File to upload:<br>
- <input type="file" name="upload"><br>
- <input type="submit" value="Upload">
- </form>
- ''' + footer()
-
-def receive (request):
- result = []
- name = request.form.get("name")
- if name:
- result.append("<p>Thanks, %s!</p>" % html_quote(name))
-
- upload = request.form.get("upload")
- size = os.stat(upload.tmp_filename)[stat.ST_SIZE]
- if not upload.base_filename or size == 0:
- title = "Empty Upload"
- result.append("<p>You appear not to have uploaded anything.</p>")
- else:
- title = "Upload Received"
- result.append("<p>You just uploaded <code>%s</code> (%d bytes)<br>"
- % (html_quote(upload.base_filename), size))
- result.append("which is temporarily stored in <code>%s</code>.</p>"
- % html_quote(upload.tmp_filename))
-
- return header(title) + "\n".join(result) + footer()
-
-def main ():
- pub = Publisher('__main__', display_exceptions='plain')
- pub.publish_cgi()
-
-main()