How to use the wsgiref.validate.validator function in wsgiref

To help you get started, we’ve selected a few wsgiref examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github benoitc / gunicorn / tests / support.py View on Github external
    @validator
    def app(environ, start_response):
        """Simplest possible application object"""

        status = '200 OK'

        response_headers = [
            ('Content-type', 'text/plain'),
            ('Content-Length', length),
        ]
        start_response(status, response_headers)
        return iter([message])
github gevent / gevent / src / greentest / 3.6pypy / test_wsgiref.py View on Github external
def test_wsgi_input(self):
        def bad_app(e,s):
            e["wsgi.input"].read()
            s("200 OK", [("Content-Type", "text/plain; charset=utf-8")])
            return [b"data"]
        out, err = run_amock(validator(bad_app))
        self.assertTrue(out.endswith(
            b"A server error occurred.  Please contact the administrator."
        ))
        self.assertEqual(
            err.splitlines()[-2], "AssertionError"
        )
github GoogleCloudPlatform / webapp2 / lib / protorpc / webapp_test_util.py View on Github external
def StartWebServer(self, port):
    """Start web server."""
    application = self.CreateWSGIApplication()
    validated_application = validate.validator(application)
    server = simple_server.make_server('localhost', port, validated_application)
    server = ServerThread(server)
    server.start()
    server.wait_until_running()
    return server, application
github publiclab / spectral-workbench / public / lib / bespin-0.9a2 / lib / static.py View on Github external
def test():
    from wsgiref.validate import validator
    magics = StringMagic(title="String Test"), KidMagic(title="Kid Test")
    app = Shock('testdata/pub', magics=magics)
    try:
        make_server('localhost', 9999, validator(app)).serve_forever()
    except KeyboardInterrupt, ki:
        print "Ciao, baby!"
github pquentin / flup-py3 / flup / server / fcgi_single.py View on Github external
name, cgi.escape(`environ[name]`))

        form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ,
                                keep_blank_values=1)
        if form.list:
            yield 'Form data'

        for field in form.list:
            yield '%s%s\n' % (
                field.name, field.value)

        yield '\n' \
              '\n'

    from wsgiref import validate
    test_app = validate.validator(test_app)
    WSGIServer(test_app).run()
github pquentin / flup-py3 / flup / server / ajp.py View on Github external
name, cgi.escape(`environ[name]`))

        form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ,
                                keep_blank_values=1)
        if form.list:
            yield 'Form data'

        for field in form.list:
            yield '%s%s\n' % (
                field.name, field.value)

        yield '\n' \
              '\n'

    from wsgiref import validate
    test_app = validate.validator(test_app)
    # Explicitly set bindAddress to *:8009 for testing.
    WSGIServer(test_app,
               bindAddress=('', 8009), allowedServers=None,
               loggingLevel=logging.DEBUG).run()
github pquentin / flup-py3 / flup / server / scgi_fork.py View on Github external
name, cgi.escape(`environ[name]`))

        form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ,
                                keep_blank_values=1)
        if form.list:
            yield 'Form data'

        for field in form.list:
            yield '%s%s\n' % (
                field.name, field.value)

        yield '\n' \
              '\n'

    from wsgiref import validate
    test_app = validate.validator(test_app)
    WSGIServer(test_app,
               loggingLevel=logging.DEBUG).run()
github galaxyproject / galaxy / lib / galaxy / web / framework / servers / flup / ajp_forkthreaded.py View on Github external
name, cgi.escape(`environ[name]`))

        form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ,
                                keep_blank_values=1)
        if form.list:
            yield 'Form data'

        for field in form.list:
            yield '%s%s\n' % (
                field.name, field.value)

        yield '\n' \
              '\n'

    from wsgiref import validate
    test_app = validate.validator(test_app)
    # Explicitly set bindAddress to *:4001 for testing.
    WSGIServer(test_app,
               bindAddress=('', 4001), allowedServers=None,
               loggingLevel=logging.DEBUG).run()
github kobinpy / wsgicli / wsgicli.py View on Github external
$ wsgicli run hello.py app -h 0.0.0.0 -p 5000 --reload

        $ wsgicli run hello.py app --static --static-root /static/ --static-dirs ./static/
    """
    insert_import_path_to_sys_modules(filepath)
    module = SourceFileLoader('module', filepath).load_module()
    app = getattr(module, wsgiapp)

    if static:
        from wsgi_static_middleware import StaticMiddleware
        app = StaticMiddleware(app, static_root=static_root, static_dirs=static_dirs)

    if validate:
        from wsgiref.validate import validator
        app = validator(app)

    if lineprof:
        # Caution: wsgi-lineprof is still pre-alpha. Except breaking API Changes.
        from wsgi_lineprof.middleware import LineProfilerMiddleware
        from wsgi_lineprof.filters import FilenameFilter, TotalTimeSorter

        if lineprof_file:
            # Now wsgi-lineprof is now supported only 1 file checking.
            lineprof_file = lineprof_file[0]
        else:
            lineprof_file = os.path.basename(filepath)
        filters = [FilenameFilter(lineprof_file), TotalTimeSorter()]
        app = LineProfilerMiddleware(app, filters=filters)

    if reload:
        run_live_reloading_server(interval, app=app, host=host, port=port)