diff --git a/pep-3333.txt b/pep-3333.txt index 0eda2832a..241321245 100644 --- a/pep-3333.txt +++ b/pep-3333.txt @@ -230,8 +230,7 @@ support application developers.) Here are two example application objects; one is a function, and the other is a class:: - # this would need to be a byte string in Python 3: - HELLO_WORLD = "Hello world!\n" + HELLO_WORLD = b"Hello world!\n" def simple_app(environ, start_response): """Simplest possible application object""" @@ -281,9 +280,14 @@ server. import os, sys - def run_with_cgi(application): + enc, esc = sys.getfilesystemencoding(), 'surrogateescape' - environ = dict(os.environ.items()) + def wsgi_string(u): + # Convert an environment variable to a WSGI "bytes-as-unicode" string + return u.encode(enc, esc).decode('iso-8859-1') + + def run_with_cgi(application): + environ = {k: wsgi_string(v) for k,v in os.environ.items()} environ['wsgi.input'] = sys.stdin environ['wsgi.errors'] = sys.stderr environ['wsgi.version'] = (1, 0)