Beispiel #1
0
def handler(req):
    # Run a startup function if requested.
    global startup
    if not startup:
        func = req.get_options().get('wsgi.startup')
        if func:
            module_name, object_str = func.split('::', 1)
            module = __import__(module_name, globals(), locals(), [''])
            startup = apache.resolve_object(module, object_str)
            startup(req)
    
    # Register a cleanup function if requested.
    global cleanup
    if not cleanup:
        func = req.get_options().get('wsgi.cleanup')
        if func:
            module_name, object_str = func.split('::', 1)
            module = __import__(module_name, globals(), locals(), [''])
            cleanup = apache.resolve_object(module, object_str)
            def cleaner(data):
                cleanup()
            try:
                # apache.register_cleanup wasn't available until 3.1.4.
                apache.register_cleanup(cleaner)
            except AttributeError:
                req.server.register_cleanup(req, cleaner)
    
    # Import the wsgi 'application' callable and pass it to Handler.run
    modname, objname = req.get_options()['wsgi.application'].split('::', 1)
    module = __import__(modname, globals(), locals(), [''])
    app = getattr(module, objname)
    Handler(req).run(app)
    
    # status was set in Handler; always return apache.OK
    return apache.OK
def handler(req):
    options = req.get_options()
    # Run a startup function if requested.
    global startup
    if 'wsgi.startup' in options and not startup:
        func = options['wsgi.startup']
        if func:
            module_name, object_str = func.split('::', 1)
            module = __import__(module_name, globals(), locals(), [''])
            startup = apache.resolve_object(module, object_str)
            startup(req)

    # Register a cleanup function if requested.
    global cleanup
    if 'wsgi.cleanup' in options and not cleanup:
        func = options['wsgi.cleanup']
        if func:
            module_name, object_str = func.split('::', 1)
            module = __import__(module_name, globals(), locals(), [''])
            cleanup = apache.resolve_object(module, object_str)

            def cleaner(data):
                cleanup()

            try:
                # apache.register_cleanup wasn't available until 3.1.4.
                apache.register_cleanup(cleaner)
            except AttributeError:
                req.server.register_cleanup(req, cleaner)

    # Import the wsgi 'application' callable and pass it to Handler.run
    global wsgiapps
    appini = options.get('paste.ini')
    app = None
    if appini:
        if appini not in wsgiapps:
            wsgiapps[appini] = loadapp("config:%s" % appini)
        app = wsgiapps[appini]

    # Import the wsgi 'application' callable and pass it to Handler.run
    appwsgi = options.get('wsgi.application')
    if appwsgi and not appini:
        modname, objname = appwsgi.split('::', 1)
        module = __import__(modname, globals(), locals(), [''])
        app = getattr(module, objname)

    Handler(req).run(app)

    # status was set in Handler; always return apache.OK
    return apache.OK
Beispiel #3
0
def handler(req):
    options = req.get_options()
    # Run a startup function if requested.
    global startup
    if "wsgi.startup" in options and not startup:
        func = options["wsgi.startup"]
        if func:
            module_name, object_str = func.split("::", 1)
            module = __import__(module_name, globals(), locals(), [""])
            startup = apache.resolve_object(module, object_str)
            startup(req)

    # Register a cleanup function if requested.
    global cleanup
    if "wsgi.cleanup" in options and not cleanup:
        func = options["wsgi.cleanup"]
        if func:
            module_name, object_str = func.split("::", 1)
            module = __import__(module_name, globals(), locals(), [""])
            cleanup = apache.resolve_object(module, object_str)

            def cleaner(data):
                cleanup()

            try:
                # apache.register_cleanup wasn't available until 3.1.4.
                apache.register_cleanup(cleaner)
            except AttributeError:
                req.server.register_cleanup(req, cleaner)

    # Import the wsgi 'application' callable and pass it to Handler.run
    global wsgiapps
    appini = options.get("paste.ini")
    app = None
    if appini:
        if appini not in wsgiapps:
            wsgiapps[appini] = loadapp("config:%s" % appini)
        app = wsgiapps[appini]

    # Import the wsgi 'application' callable and pass it to Handler.run
    appwsgi = options.get("wsgi.application")
    if appwsgi and not appini:
        modname, objname = appwsgi.split("::", 1)
        module = __import__(modname, globals(), locals(), [""])
        app = getattr(module, objname)

    Handler(req).run(app)

    # status was set in Handler; always return apache.OK
    return apache.OK