Latest Version: 0.9.6.2

Warning

This documentation does not refer to the most recent version of Pylons. Current Documentation

/Users/ben/Programming/Python/0.8/pylons/wsgiapp.py
0001"""WSGI App Creator
0002
0003This module is responsible for creating the basic Pylons WSGI application. It's generally
0004assumed that it will be called by Paste, though any WSGI application server could create
0005and call the WSGI app as well.
0006"""
0007from paste.deploy.config import ConfigMiddleware
0008from paste.deploy.converters import asbool
0009
0010from myghty.http import WSGIHandler
0011import myghty
0012import pylons.middleware
0013
0014class PylonsWSGIApp(object):
0015    def __init__(self, global_conf, myghty_config):
0016        """Basic Pylons WSGI Application
0017
0018        This basic WSGI app is provided should a web developer want to
0019        get access to the most basic Myghty WSGI application that Pylons
0020        utilizes.
0021        """
0022        self.app = WSGIHandler.WSGIHandler(**myghty_config)
0023        self.global_conf = global_conf
0024
0025    def __call__(self, environ, start_response):
0026        if asbool(self.global_conf.get('debug', 'true')):
0027            try:
0028                return self.app.handle(environ, start_response)
0029            except myghty.exception.Error, e:
0030                tback = e.raw_excinfo
0031                delattr(e, 'raw_excinfo')
0032                if tback[1]: tback[1].mtrace = e
0033                raise tback[0], tback[1], tback[2]
0034        else:
0035            return self.app.handle(environ, start_response)
0036
0037def make_app(config):
0038    app = PylonsWSGIApp(config.global_conf, config.myghty)
0039    app = ConfigMiddleware(app, {
0040        'default':config.global_conf,
0041        'app':config.app_conf,
0042        'app_conf':config.app_conf,
0043        'global_conf':config.global_conf
0044    })
0045    g = pylons.middleware.Globals()
0046    try:
0047        package = __import__(config.package + '.lib.app_globals', globals(), locals(), ['Globals'])
0048    except ImportError:
0049        pass
0050    else:
0051        g = package.Globals(config.global_conf, config.app_conf, config=config)
0052    g.pylons_config = config
0053    app = pylons.middleware.register_app_globals(app, g)
0054    return app

Top