[Python-checkins] r87725 - peps/trunk/pep-3333.txt
phillip.eby
python-checkins at python.org
Tue Jan 4 01:50:39 CET 2011
Author: phillip.eby
Date: Tue Jan 4 01:50:38 2011
New Revision: 87725
Log:
Update a couple of code samples for Python 3
Modified:
peps/trunk/pep-3333.txt
Modified: peps/trunk/pep-3333.txt
==============================================================================
--- peps/trunk/pep-3333.txt (original)
+++ peps/trunk/pep-3333.txt Tue Jan 4 01:50:38 2011
@@ -230,8 +230,7 @@
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 @@
import os, sys
- def run_with_cgi(application):
+ enc, esc = sys.getfilesystemencoding(), 'surrogateescape'
+
+ def wsgi_string(u):
+ # Convert an environment variable to a WSGI "bytes-as-unicode" string
+ return u.encode(enc, esc).decode('iso-8859-1')
- environ = dict(os.environ.items())
+ 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)
More information about the Python-checkins
mailing list