# # # add_file "wrapper.py" # content [51003ba637da665d7ab13ca2d44415cf6fdb502a] # # patch ".htaccess" # from [a3628e6a2fb29932a69c3aee9941d77f3fd140ea] # to [32f18fb3ae3287627ec6cba1a5ab8513ec58b06a] # ============================================================ --- wrapper.py 51003ba637da665d7ab13ca2d44415cf6fdb502a +++ wrapper.py 51003ba637da665d7ab13ca2d44415cf6fdb502a @@ -0,0 +1,33 @@ + + +from mod_python import apache, psp +import os +import re + +# paranoid +sane_uri_re = re.compile('^\w+$') + +def raw_wrapper(req): + req.write("raw file output") + return apache.OK + +handlers = { + 'raw.py' : raw_wrapper +} + +def handler(req): + req.content_type = "text/plain" + uri = req.uri + slash = uri.rfind('/') + if slash <> -1: uri = uri[slash+1:] + if handlers.has_key(uri): + return handlers[uri](req) + if uri.endswith('.psp') and sane_uri_re.match(uri[:-4]): + req.content_type = "text/html" + template = psp.PSP(req, filename=uri) + template.run() + return apache.OK + req.content_type = "text/plain" + req.write("URI refers to unknown content handler: %s" % (uri)) + return apache.OK + ============================================================ --- .htaccess a3628e6a2fb29932a69c3aee9941d77f3fd140ea +++ .htaccess 32f18fb3ae3287627ec6cba1a5ab8513ec58b06a @@ -1,3 +1,5 @@ AddHandler mod_python .psp -PythonHandler mod_python.psp +#PythonHandler mod_python.psp +PythonHandler wrapper +AddHandler mod_python .py DirectoryIndex index.psp