""" WSGI application launcher function for Pyblosxom. Dependencies: - Pyblosxom 1.2+ - wsgiref library from http://cvs.eby-sarna.com/wsgiref/ - if run with mod_python: mp_wsgi_handler.py (mod_python wsgi wrapper) from http://www.c-area.ch/code/ - if run with twisted: twisted_wsgi.py (twisted wsgi wrapper) from http://svn.colorstudy.com/trunk/WSGIKit/wsgikit/ Configuration: - put this file in your weblog folder (where pyblosxom.cgi is) - mod_python: Note: If you have a folder in your document root that has the same name as the Location used below, the SCRIPT_NAME and PATH_INFO variables will be broken. You should keep your blog's files outside your document root. PythonDebug On SetHandler python-program # set PythonPath to the folders containing the files. PythonPath "['/path/to/mp_wsgi_handler', '/path/to/wsgi_app']+sys.path" PythonHandler mp_wsgi_handler::wsgi_handler # This should be the same as the Location above PythonOption ApplicationPath /weblog PythonOption application wsgi_app::application Todo: - more documentation - example configuration for twisted Revisions: $Log: wsgi_app.py,v $ Revision 1.3 2005/02/12 16:16:11 sar changed the iterable return value to work as recommended in the PEP Revision 1.2 2005/02/08 19:15:09 sar fixed typo Revision 1.1 2005/02/08 17:51:21 sar cvs server update Revision 1.8 2005/02/05 19:13:55 sar added exception handling $Id: wsgi_app.py,v 1.3 2005/02/12 16:16:11 sar Exp $ """ __author__ = "Steven Armstrong " __version__ = "$Revision: 1.3 $ $Date: 2005/02/12 16:16:11 $" __url__ = "http://www.c-area.ch/code/" __description__ = "WSGI application launcher for Pyblosxom" __license__ = "Pyblosxom" # Python imports import sys # Pyblosxom imports from Pyblosxom.pyblosxom import PyBlosxom from Pyblosxom import tools from config import py as cfg _debug = False def _getExcInfo(): try: from cStringIO import StringIO except ImportError: from StringIO import StringIO import traceback (exc_type, exc_value, tb) = sys.exc_info() exc_file = StringIO() traceback.print_exception(exc_type, exc_value, tb, file=exc_file) exc_string = exc_file.getvalue() return exc_string def application(env, start_response): try: # regular application code here # ensure that PATH_INFO exists. a few plugins break if this is missing. if not 'PATH_INFO' in env: env['PATH_INFO'] = "" p = PyBlosxom(cfg, env) p.run() response = p.getResponse() if _debug: log = tools.getLogger("pyblosxom", "debug") log.debug("status: %s", response.status) log.debug("headers: %s", response.headers) write = start_response(response.status, list(response.headers.items())) response.seek(0) # somehow Firefox doesn't like this #return response # so do it like this return [response.read()] except: # log the exception to //error.log tools.log_exception() status = "500 Oops" response_headers = [("content-type","text/plain")] #start_response(status, response_headers, sys.exc_info()) start_response(status, response_headers) result = ["Pyblosxom WSGI application: A server error occurred. Please contact the administrator."] if _debug: result.append("\n") result.append(_getExcInfo()) return result