Web Gateway Modules

wsgiref.handlers

Base handler classes adapt WSGI requests to application calls and serialize responses. SimpleHandler accepts input, output and error streams, so trusted applications can be tested without binding a socket. WSGI response bodies are bytes; status and headers use strings.

Formal Syntax & Structure

python syntaxpython
import wsgiref.handlers

Return Value

module

Module namespace available through import; import is a statement, not a value-returning expression.

Working Example

Example Snippetpython
from io import BytesIO, StringIOfrom wsgiref.handlers import SimpleHandlerdef app(env, start_response):    start_response("200 OK", [("Content-Type", "text/plain")])    return [b"ready"]out = BytesIO()handler = SimpleHandler(BytesIO(), out, StringIO(), {"SERVER_PROTOCOL": "HTTP/1.1"})handler.run(app)print(out.getvalue().endswith(b"ready"))
Python Reference