[mod_python] mod_python adapter for mod_wsgi in the make

Graham Dumpleton graham.dumpleton at gmail.com
Mon Nov 30 20:13:00 EST 2009


2009/11/26 Graham Dumpleton <graham.dumpleton at gmail.com>:
> I have moved it to:
>
>  http://bitbucket.org/grahamdumpleton/apswigpy/
>
> I'll add some basic documentation on building and usage.

Quick cheat sheet.

1. Do a checkout/pull latest code for apswigpy from bitbucket and
install it. Need this as added a little bridge for WSGI to at least
get things going.

2. Add following configuration to Apache. I had this inside its own VirtualHost.

WSGIHandlerScript python-script (apache.wsgi)

<Directory /Users/grahamd/Testing/modpysfu>
WSGIProcessGroup %{GLOBAL}
WSGIApplicationGroup modpysfu
WSGIPassApacheRequest On

AddHandler python-script .py

Options MultiViews FollowSymLinks
MultiviewsMatch Handlers

Order allow,deny
Allow from all
</Directory>

In my case that directory was what DocumentRoot for host was set to.

You would need to Alias it in some way if don't want to do it for DocumentRoot.

3. Now dump '.py' files in that directory and access URL as if
accessing them as static file. A couple of examples are:

# hello.py

from apache.httpd import *
from apache.http_protocol import *

def handler(r):
    output = '<html><body>Hello World!</body></html>'

    r.status = HTTP_OK
    ap_set_content_type(r, 'text/html')
    #ap_set_content_length(r, len(output))
    ap_rwrite(output, r)
    ap_rflush(r)

    return OK

# echo.py

from apache.httpd import *
from apache.http_protocol import *

def handler(r):
    r.status = HTTP_OK
    ap_set_content_type(r, 'text/plain')

    for (name, value) in r.headers_in.items():
        ap_rwrite('%s: %s\n' % (name, value), r)

    ap_rflush(r)

    return OK

Note that this is raw SWIG binding, no mod_python specific additions
at this point. Some things have had to be Pythonised such as APR
tables as used by headers_in, but otherwise trying to keep truthful to
APR/AP APIs.

I know some things don't work, such as 'ap_set_content_length()'. Some
issue with SWIG bindings type equivalence has to be worked out for
that one and haven't had chance to read SWIG documentation.

Graham



More information about the Mod_python mailing list