--- /dev/null
+This example demonstrates how the shipped Python module ashd.wsgidir
+can be used to call WSGI scripts in dirplex-served directories as
+easily as PHP scripts or mod_python scripts under Apache.
+
+To try this example, run it on your local machine and request
+<http://localhost:8080/> or <http://127.0.0.1:8080/>.
--- /dev/null
+import sys, ashd.wsgiutil
+
+n = 0
+
+def application(env, startreq):
+ global n
+ startreq("200 OK", [("Content-Type", "text/html")])
+ yield "<html>\n"
+ yield "<head><title>Hello world from Python!</title></head>\n"
+ yield "<body>\n"
+ yield "<h1>Hello world from Python/WSGI!</h1>\n"
+ yield "<p>Do note how the single-process nature of <code>ashd-wsgi</code> "
+ yield "allows data to be kept in memory persistently across requests, and "
+ yield "how the following counter increases by one for each request: " + str(n) + "</p>\n"
+ n += 1
+ yield "<p>This script is a very raw WSGI example, using no glue code "
+ yield "whatever, but you should be able to use whatever WSGI middleware "
+ yield "you like in order to make it easier to code WSGI. If you have no "
+ yield "particular preference, I might recommend "
+ yield "<a href=\"http://www.dolda2000.com/gitweb/?p=wrw.git;a=summary\">WRW</a>, "
+ yield "my WSGI Request Wrapper library, which is particularly made for "
+ yield "<code>ashd-wsgi</code> and therefore, for instance, allows "
+ yield "non-pickleble objects (like sockets) to be stored in sessions.</p>"
+ yield "<p>If you have installed the Python3 utilities as well, there is "
+ yield "also a <a href=\"py3\">Python3 script</a> to demonstrate that "
+ yield "Python3 is supported as well.\n"
+ yield "<p>The current Python interpreter is <code>" + ashd.wsgiutil.htmlquote(sys.version) + "</code>.</p>"
+ yield "</body>\n"
+ yield "</html>\n"
--- /dev/null
+import sys, ashd.wsgiutil
+
+def application(env, startreq):
+ startreq("200 OK", [("Content-Type", "text/html")])
+ # Note that WSGI 3 requires returned data to be bytes, not strings.
+ yield b"<html>\n"
+ yield b"<head><title>Hello world from Python3!</title></head>\n"
+ yield b"<body>\n"
+ yield b"<h1>Hello world from Python3!</h1>\n"
+ yield b"<p>This example does nothing in particular except demonstrating "
+ yield b"that there is support for Python3 as well.</p>\n"
+ yield b"<p>The current Python interpreter is <code>" + ashd.wsgiutil.htmlquote(sys.version).encode("utf-8") + b"</code>.</p>"
+ yield b"</body>\n"
+ yield b"</html>\n"
--- /dev/null
+#!/bin/sh
+
+# Change to the directory containing this script
+set -e
+cd "$(dirname "$0")"
+
+# Invoke dirplex running in this directory, loading the wsgidir.rc
+# configuration file. The same configuration can be put in
+# e.g. /etc/ashd/dirplex.d or in any .htrc file.
+
+# The setsid command ensures that SIGINT is only received by htparser
+# and not by dirplex or its children; it is not of any importance, but
+# makes shutdown slightly cleaner, and hides the KeyboardInterrupt
+# otherwise raised by Python.
+htparser plain:port=8080 -- setsid dirplex -c ./wsgidir.rc .
--- /dev/null
+# Python 2 handler process
+child wsgidir
+ exec ashd-wsgi ashd.wsgidir
+# Python 3 scripts can also be served, using ashd-wsgi3
+child wsgidir3
+ exec ashd-wsgi3 ashd.wsgidir
+
+# Dispatch any *.wsgi files to wsgidir
+# See the Python documention for the ashd.wsgidir module for the
+# meaning of the "xset python-handler chain" directive and what other
+# values it can take.
+match
+ filename *.wsgi
+ xset python-handler chain
+ handler wsgidir
+# Do the same for Python3 scripts names *.wsgi3
+match
+ filename *.wsgi3
+ xset python-handler chain
+ handler wsgidir3