Update a couple of code samples for Python 3
This commit is contained in:
parent
ccff4c88ca
commit
0e2443644e
12
pep-3333.txt
12
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)
|
||||
|
|
Loading…
Reference in New Issue