[Web-SIG] wsgiref 0.2 dev in svn w/PEP 3333 support

and-py and-py at doxdesk.com
Thu Oct 21 01:48:00 CEST 2010

On Sat, 2010-10-09 at 18:11 -0400, P.J. Eby wrote:

> Ok; if you can submit patches...

Done: http://bugs.python.org/issue10155

> Note, by the way, that just because the environment is unicode on 
> 3.x, doesn't mean it's WSGI-correct: WSGI requires that unicode 
> environment strings be just bytestrings in disguise.

Indeed. On Windows CGI the environment is probably not WSGI-correct. The
only web server I've met that writes bytes-as-code-points
(ISO-8859-1-decoded) to the environ is Apache.

Couple of points on PEP 3333 I noticed whilst adapting this:

> Unicode Issues:
> HTTP does not directly support Unicode, and neither does this
interface. All
> encoding/decoding must be handled by the application; all strings
passed to
> or from the server must be of type str or bytes, never unicode.

This wording probably needs changing now we're going with
bytes-as-code-points unicode environ/status/headers.

> Note also that strings passed to start_response() as a status or as
response headers must
> follow RFC 2616 with respect to encoding. That is, they must either be
> characters, or use RFC 2047 MIME encoding.

They must be ISO-8859-1 period. The mention of RFC2047 in RFC2616 is an
error; HTTPbis work excises this. No browser or server has ever used or
understood RFC2047 encoded-words in HTTP headers; it's questionable
whether RFC2047 can be used in HTTP headers even theoretically. (Since
HTTP headers do not have atoms in the RFC822-family meaning and aren't
defined in terms of RFC822 tokens anyway.)

In the few places you might actually *want* to use encoded-words
(typically quoted-string parameters), RFC2047 explicitly denies that
they may be used (in favour of the even more complicated RFC2231, which
no browser author has even heard of).

Also the Server/Gateway example needs a little more work if it is to be
Python 3 compatible. it would need to use the .buffer properties on
stream IO to get byte IO, and encode to ISO-8859-1. Or just mark the
example as being Python 2-only.

And Clover
mailto:and at doxdesk.com

More information about the Web-SIG mailing list