[Web-SIG] bytes, strings, and Unicode in Jython,
IronPython, and CPython 3.0
Phillip J. Eby
pje at telecommunity.com
Wed Sep 15 18:01:25 CEST 2004
At 12:33 PM 9/15/04 +0200, Paul Boddie wrote:
>Phillip J. Eby wrote:
> > So, here's what I propose to do about the open issue in PEP 333.
> > and gateways that run under Python implementations where all strings
> > Unicode (e.g. Jython) *may*:
> > * accept Unicode statuses and headers, so long as they properly
> > them for transmission (latin-1 + RFC 2047)
>I think I encode all Unicode objects used in this area as US-ASCII in
> > * accept Unicode for response body segments, so long as each segment
> > be encoded as latin-1 (i.e. only uses chars 0-255)
>It should be possible to be more intelligent about response bodies, but
>can argue that it isn't up to something like WSGI to go through the
>necessary gymnastics to make sure that Unicode objects presented to the
>response stream become encoded appropriately.
> > * produce Unicode input headers and body strings by decoding from
> > latin-1, as long as the produced values are considered type 'str' for
> > Python implementation.
>I think I've left incoming headers as plain strings, but I suppose a
>translation could be performed in WebStack.
You only need to worry about these things in WebStack if it's running under
conditions where 'str' objects may contain any Unicode
character. Currently that's only Jython, and maybe IronPython. As far as
I know, CPython's -U option is broken; that is, not all of the Python
stdlib works correctly with Unicode 'str' objects, so for the time being
it's unlikely you'll need to worry about any of this under CPython.
More information about the Web-SIG