Ejemplo n.º 1
0
def make_app(global_conf, **kw):
    conf = global_conf.copy()
    conf.update(kw)

    # configure by entrypoint
    app = make_whitstyle_api(conf)
    app = ConfigMiddleware(app, conf)
    return app
def test_error():
    # This import is conditional due to Paste not yet working on py3k
    try:
        from paste.fixture import TestApp
    except ImportError:
        raise SkipTest

    wrapped = ConfigMiddleware(app_with_exception, {'test': 1})
    test_app = TestApp(wrapped)
    assert_raises(Bug, test_app.get, '/')
Ejemplo n.º 3
0
def make_app(global_conf, full_stack=True, **app_conf):
    """Create a WSGI application and return it
    
    global_conf is a dict representing the Paste configuration options, the
    paste.deploy.converters should be used when parsing Paste config options
    to ensure they're treated properly.
    
    """
    # Setup the Paste CONFIG object
    CONFIG.push_process_config({'app_conf': app_conf,
                                'global_conf': global_conf})

    # Load our Pylons configuration defaults
    config = load_environment(global_conf, app_conf)
    config.init_app(global_conf, app_conf, package='web')
        
    # Load our default Pylons WSGI app and make g available
    app = pylons.wsgiapp.PylonsApp(config, helpers=web.lib.helpers,
                                   g=app_globals.Globals)
    g = app.globals
    app = ConfigMiddleware(app, {'app_conf':app_conf,
        'global_conf':global_conf})
    
    # YOUR MIDDLEWARE
    # Put your own middleware here, so that any problems are caught by the error
    # handling middleware underneath
    
    # If errror handling and exception catching will be handled by middleware
    # for multiple apps, you will want to set full_stack = False in your config
    # file so that it can catch the problems.
    if asbool(full_stack):
        # Change HTTPExceptions to HTTP responses
        app = httpexceptions.make_middleware(app, global_conf)
    
        # Error Handling
        app = ErrorHandler(app, global_conf, error_template=error_template, **config.errorware)
    
        # Display error documents for 401, 403, 404 status codes (if debug is disabled also
        # intercepts 500)
        app = ErrorDocuments(app, global_conf, mapper=error_mapper, **app_conf)
    
    # Establish the Registry for this application
    app = RegistryManager(app)
    
    static_app = StaticURLParser(config.paths['static_files'])
    javascripts_app = StaticJavascripts()
    app = Cascade([static_app, javascripts_app, app])
    return app
Ejemplo n.º 4
0
def make_app(global_conf, full_stack=True, **app_conf):
    """Create a WSGI application and return it
    
    global_conf is a dict representing the Paste configuration options, the
    paste.deploy.converters should be used when parsing Paste config options
    to ensure they're treated properly.
    
    """
    load_environment(global_conf, app_conf)

    # Pull the other engine and put a new one up first
    config.template_engines.pop()
    kidopts = {'kid.assume_encoding': 'utf-8', 'kid.encoding': 'utf-8'}
    pylons.config.add_template_engine('kid', 'projectname.kidtemplates',
                                      kidopts)

    # Load our default Pylons WSGI app and make g available
    app = pylons.wsgiapp.PylonsApp(helpers=projectname.lib.helpers,
                                   g=app_globals.Globals)
    app = ConfigMiddleware(app, config._current_obj())

    # If errror handling and exception catching will be handled by middleware
    # for multiple apps, you will want to set full_stack = False in your config
    # file so that it can catch the problems.
    if asbool(full_stack):
        # Change HTTPExceptions to HTTP responses
        app = httpexceptions.make_middleware(app, global_conf)

        # Error Handling
        app = ErrorHandler(app,
                           global_conf,
                           error_template=error_template,
                           **config['pylons.errorware'])

        # Display error documents for 401, 403, 404 status codes (if debug is disabled also
        # intercepts 500)
        app = ErrorDocuments(app, global_conf, mapper=error_mapper, **app_conf)

    # Establish the Registry for this application
    app = RegistryManager(app)

    static_app = StaticURLParser(config['pylons.paths']['static_files'])
    javascripts_app = StaticJavascripts()
    app = Cascade([static_app, javascripts_app, app])
    return app
Ejemplo n.º 5
0
def factory(global_config, **local_config):
    app = application
    conf = global_config.copy()
    conf.update(**local_config)
    return ConfigMiddleware(app, conf)
Ejemplo n.º 6
0
def make_middleware(app, global_conf, **local_conf):
    """
    Based on the configuration wrap `app` in a set of common and useful 
    middleware.
    """
    # Merge the global and local configurations
    conf = global_conf.copy()
    conf.update(local_conf)
    debug = asbool(conf.get('debug', False))
    # First put into place httpexceptions, which must be most closely
    # wrapped around the application (it can interact poorly with
    # other middleware):
    app = httpexceptions.make_middleware(app, conf)
    log.debug("Enabling 'httpexceptions' middleware")
    # The recursive middleware allows for including requests in other
    # requests or forwarding of requests, all on the server side.
    if asbool(conf.get('use_recursive', True)):
        from paste import recursive
        app = recursive.RecursiveMiddleware(app, conf)
        log.debug("Enabling 'recursive' middleware")
    # Session middleware puts a session factory into the environment
    if asbool(conf.get('use_session', True)):
        store = flup_session.MemorySessionStore()
        app = flup_session.SessionMiddleware(store, app)
        log.debug("Enabling 'flup session' middleware")
    # Beaker session middleware
    if asbool(conf.get('use_beaker_session', False)):
        pkg_resources.require("Beaker")
        import beaker.session
        app = beaker.session.SessionMiddleware(app, conf)
        log.debug("Enabling 'beaker session' middleware")
    # Various debug middleware that can only be turned on if the debug
    # flag is set, either because they are insecure or greatly hurt
    # performance
    if debug:
        # Middleware to check for WSGI compliance
        if asbool(conf.get('use_lint', True)):
            from paste import lint
            app = lint.make_middleware(app, conf)
            log.debug("Enabling 'lint' middleware")
        # Middleware to run the python profiler on each request
        if asbool(conf.get('use_profile', False)):
            from paste.debug import profile
            app = profile.ProfileMiddleware(app, conf)
            log.debug("Enabling 'profile' middleware")
        # Interactive exception debugging, scary dangerous if publicly
        # accessible, if not enabled we'll use the regular error printing
        # middleware.
        if asbool(conf.get('use_interactive', False)):
            from paste import evalexception
            app = evalexception.EvalException(app, conf)
            log.debug("Enabling 'eval exceptions' middleware")
        else:
            from paste.exceptions import errormiddleware
            app = errormiddleware.ErrorMiddleware(app, conf)
            log.debug("Enabling 'error' middleware")
        # Middleware that intercepts print statements and shows them on the
        # returned page
        if asbool(conf.get('use_printdebug', True)):
            from paste.debug import prints
            app = prints.PrintDebugMiddleware(app, conf)
            log.debug("Enabling 'print debug' middleware")
    else:
        # Not in debug mode, just use the regular error middleware
        from paste.exceptions import errormiddleware
        app = errormiddleware.ErrorMiddleware(app, conf)
        log.debug("Enabling 'error' middleware")
    # Transaction logging (apache access.log style)
    if asbool(conf.get('use_translogger', True)):
        from paste.translogger import TransLogger
        app = TransLogger(app)
        log.debug("Enabling 'trans logger' middleware")
    # Config middleware just stores the paste config along with the request,
    # not sure we need this but useful
    from paste.deploy.config import ConfigMiddleware
    app = ConfigMiddleware(app, conf)
    log.debug("Enabling 'config' middleware")
    # X-Forwarded-Host handling
    app = XForwardedHostMiddleware(app)
    log.debug("Enabling 'x-forwarded-host' middleware")
    return app
Ejemplo n.º 7
0
def factory(global_config, **local_config):
    """Aplication factory to expand configs"""
    conf = global_config.copy()
    conf.update(**local_config)
    return ConfigMiddleware(application, conf)
Ejemplo n.º 8
0
def wrap_in_middleware( app, global_conf, **local_conf ):
    """
    Based on the configuration wrap `app` in a set of common and useful 
    middleware.
    """
    # Merge the global and local configurations
    conf = global_conf.copy()
    conf.update(local_conf)
    debug = asbool( conf.get( 'debug', False ) )
    # First put into place httpexceptions, which must be most closely
    # wrapped around the application (it can interact poorly with
    # other middleware):
    app = httpexceptions.make_middleware( app, conf )
    log.debug( "Enabling 'httpexceptions' middleware" )
    # If we're using remote_user authentication, add middleware that
    # protects Galaxy from improperly configured authentication in the
    # upstream server
    if asbool(conf.get( 'use_remote_user', False )):
        from galaxy.web.framework.middleware.remoteuser import RemoteUser
        app = RemoteUser( app, maildomain=conf.get( 'remote_user_maildomain', None ), ucsc_display_sites=conf.get( 'ucsc_display_sites', [] ) )
        log.debug( "Enabling 'remote user' middleware" )
    # The recursive middleware allows for including requests in other 
    # requests or forwarding of requests, all on the server side.
    if asbool(conf.get('use_recursive', True)):
        from paste import recursive
        app = recursive.RecursiveMiddleware( app, conf )
        log.debug( "Enabling 'recursive' middleware" )
    # Various debug middleware that can only be turned on if the debug
    # flag is set, either because they are insecure or greatly hurt
    # performance
    if debug:
        # Middleware to check for WSGI compliance
        if asbool( conf.get( 'use_lint', True ) ):
            from paste import lint
            app = lint.make_middleware( app, conf )
            log.debug( "Enabling 'lint' middleware" )
        # Middleware to run the python profiler on each request
        if asbool( conf.get( 'use_profile', False ) ):
            import profile
            app = profile.ProfileMiddleware( app, conf )
            log.debug( "Enabling 'profile' middleware" )
        # Middleware that intercepts print statements and shows them on the
        # returned page
        if asbool( conf.get( 'use_printdebug', True ) ):
            from paste.debug import prints
            app = prints.PrintDebugMiddleware( app, conf )
            log.debug( "Enabling 'print debug' middleware" )
    if debug and asbool( conf.get( 'use_interactive', False ) ):
        # Interactive exception debugging, scary dangerous if publicly
        # accessible, if not enabled we'll use the regular error printing
        # middleware.
        pkg_resources.require( "WebError" )
        from weberror import evalexception
        app = evalexception.EvalException( app, conf,
                                           templating_formatters=build_template_error_formatters() )
        log.debug( "Enabling 'eval exceptions' middleware" )
    else:
        # Not in interactive debug mode, just use the regular error middleware
        if sys.version_info[:2] >= ( 2, 6 ):
            warnings.filterwarnings( 'ignore', '.*', DeprecationWarning, '.*serial_number_generator', 11, True )
            from paste.exceptions import errormiddleware
            warnings.filters.pop()
        else:
            from paste.exceptions import errormiddleware
        app = errormiddleware.ErrorMiddleware( app, conf )
        log.debug( "Enabling 'error' middleware" )
    # Transaction logging (apache access.log style)
    if asbool( conf.get( 'use_translogger', True ) ):
        from paste.translogger import TransLogger
        app = TransLogger( app )
        log.debug( "Enabling 'trans logger' middleware" )
    # Config middleware just stores the paste config along with the request,
    # not sure we need this but useful
    from paste.deploy.config import ConfigMiddleware
    app = ConfigMiddleware( app, conf )
    log.debug( "Enabling 'config' middleware" )
    # X-Forwarded-Host handling
    from galaxy.web.framework.middleware.xforwardedhost import XForwardedHostMiddleware
    app = XForwardedHostMiddleware( app )
    log.debug( "Enabling 'x-forwarded-host' middleware" )
    return app
Ejemplo n.º 9
0
def wrap_in_middleware(app, global_conf, **local_conf):
    """Based on the configuration wrap `app` in a set of common and useful middleware."""
    # Merge the global and local configurations
    conf = global_conf.copy()
    conf.update(local_conf)
    debug = asbool(conf.get('debug', False))
    # First put into place httpexceptions, which must be most closely
    # wrapped around the application (it can interact poorly with
    # other middleware):
    app = httpexceptions.make_middleware(app, conf)
    log.debug("Enabling 'httpexceptions' middleware")
    # The recursive middleware allows for including requests in other
    # requests or forwarding of requests, all on the server side.
    if asbool(conf.get('use_recursive', True)):
        from paste import recursive
        app = recursive.RecursiveMiddleware(app, conf)
        log.debug("Enabling 'recursive' middleware")
    # Various debug middleware that can only be turned on if the debug
    # flag is set, either because they are insecure or greatly hurt
    # performance
    if debug:
        # Middleware to check for WSGI compliance
        if asbool(conf.get('use_lint', True)):
            from paste import lint
            app = lint.make_middleware(app, conf)
            log.debug("Enabling 'lint' middleware")
        # Middleware to run the python profiler on each request
        if asbool(conf.get('use_profile', False)):
            import profile
            app = profile.ProfileMiddleware(app, conf)
            log.debug("Enabling 'profile' middleware")
        # Middleware that intercepts print statements and shows them on the
        # returned page
        if asbool(conf.get('use_printdebug', True)):
            from paste.debug import prints
            app = prints.PrintDebugMiddleware(app, conf)
            log.debug("Enabling 'print debug' middleware")
    if debug and asbool(conf.get('use_interactive', False)):
        # Interactive exception debugging, scary dangerous if publicly
        # accessible, if not enabled we'll use the regular error printing
        # middleware.
        pkg_resources.require("WebError")
        from weberror import evalexception
        app = evalexception.EvalException(
            app, conf, templating_formatters=build_template_error_formatters())
        log.debug("Enabling 'eval exceptions' middleware")
    else:
        # Not in interactive debug mode, just use the regular error middleware
        from paste.exceptions import errormiddleware
        app = errormiddleware.ErrorMiddleware(
            app, conf, show_exceptions_in_wsgi_errors=True, error_log=log)
        log.debug("Enabling 'error' middleware")
    # Transaction logging (apache access.log style)
    if asbool(conf.get('use_translogger', True)):
        from paste.translogger import TransLogger
        app = TransLogger(app)
        log.debug("Enabling 'trans logger' middleware")
    # Config middleware just stores the paste config along with the request,
    # not sure we need this but useful
    from paste.deploy.config import ConfigMiddleware
    app = ConfigMiddleware(app, conf)
    log.debug("Enabling 'config' middleware")
    # X-Forwarded-Host handling
    from cm.framework.middleware.xforwardedhost import XForwardedHostMiddleware
    app = XForwardedHostMiddleware(app)
    log.debug("Enabling 'x-forwarded-host' middleware")
    # Paste digest authentication
    ud = misc.load_yaml_file(paths.USER_DATA_FILE)
    if ud.get('password', ''):
        from paste.auth.basic import AuthBasicHandler
        app = AuthBasicHandler(app, 'CM Administration', cm_authfunc)
    return app
Ejemplo n.º 10
0
def test_error():
    wrapped = ConfigMiddleware(app_with_exception, {'test': 1})
    test_app = TestApp(wrapped)
    assert_raises(Bug, test_app.get, '/')
Ejemplo n.º 11
0
def app_factory(global_conf, **kwargs):
    conf = global_conf.copy()
    conf.update(kwargs)

    biobench_app = BiobenchApplication(**kwargs)
    webapp = WebApplication(biobench_app)

    webapp.add_controller('ToolExample',
                          biobench.tools.Example.ExampleController(webapp))
    webapp.add_route('/tools/example/:action',
                     controller='ToolExample',
                     action='index')

    webapp.add_controller('JobTest',
                          biobench.tools.JobTest.JobTestController(webapp))
    webapp.add_route('/tools/jobtest/:action',
                     controller='JobTest',
                     action='index')

    webapp.add_controller(
        'EDAstaticHTML',
        biobench.tools.ElectronDensityApplication.StaticHTML(webapp))
    webapp.add_route('/tools/eda/:action',
                     controller='EDAstaticHTML',
                     action='index')

    webapp.add_controller(
        'EDAGenerator',
        biobench.tools.ElectronDensityApplication.Generator(webapp))
    webapp.add_route('/tools/eda/generator/:action',
                     controller='EDAGenerator',
                     action='index')

    webapp.add_controller(
        'EDAConverter',
        biobench.tools.ElectronDensityApplication.Converter(webapp))
    webapp.add_route('/tools/eda/converter/:action',
                     controller='EDAConverter',
                     action='index')

    webapp.add_controller(
        'EDABrixConverter',
        biobench.tools.ElectronDensityApplication.Converter(webapp, brix=True))
    webapp.add_route('/tools/eda/brix_converter/:action',
                     controller='EDABrixConverter',
                     action='index')

    webapp.add_controller('MPlot',
                          biobench.tools.MPlot.MPlotController(webapp))
    webapp.add_route('/tools/mplot/:action',
                     controller='MPlot',
                     action='index')

    webapp.add_controller('V4RNAstaticHTML',
                          biobench.tools.Voronoia4RNA.StaticHTML(webapp))
    webapp.add_route('/tools/v4rna/:action',
                     controller='V4RNAstaticHTML',
                     action='index')

    webapp.add_controller('V4RNAGenerator',
                          biobench.tools.Voronoia4RNA.Generator(webapp))
    webapp.add_route('/tools/v4rna/generator/:action',
                     controller='V4RNAGenerator',
                     action='index')

    webapp = wrap_in_middleware(webapp, global_conf, **kwargs)
    webapp = wrap_in_static(webapp, global_conf, **kwargs)

    from paste.deploy.config import ConfigMiddleware
    webapp = ConfigMiddleware(webapp, global_conf)

    return webapp