Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
32e8fea3
Commit
32e8fea3
authored
Jan 07, 2011
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update the digest of PEP 3333 based on comments for Phillip Eby.
parent
2f2a9f77
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
9 deletions
+23
-9
Doc/whatsnew/3.2.rst
Doc/whatsnew/3.2.rst
+23
-9
No files found.
Doc/whatsnew/3.2.rst
View file @
32e8fea3
...
...
@@ -376,18 +376,32 @@ the bodies of requests and responses.
The *native strings* are always of type :class:`str` but are restricted to code
points between *u0000* through *u00FF* which are translatable to bytes using
*Latin-1* encoding. These strings are used with :func:`start_response` as
response headers or statuses and must follow :rfc:`2616` with respect to
*Latin-1* encoding. These strings are used for the keys and values in the
environ dictionary and for response headers and statuses in the
:func:`start_response` function. They must follow :rfc:`2616` with respect to
encoding. That is, they must either be *ISO-8859-1* characters or use
:rfc:`2047` MIME encoding.
To make the environment accessible using native strings, the :mod:`wsgiref`
module has a new function, :func:`wsgiref.handlers.read_environ` which
transcodes CGI variables from :attr:`os.environ` into native strings and returns
a new dictionary. This function provides a WSGI native string friendly
abstraction which is especially helpful given that the environment variables are
handled differently on various operating systems (native unicode on Windows or
UTF-8 encoded bytes on some Unix installations).
For developers porting WSGI applications from Python 2, here are the salient
points:
* If the app already used strings for headers in Python 2, no change is needed.
* If instead, the app encoded output headers or decoded input headers, then the
headers will need to be re-encoded to Latin-1. For example, an output header
encoded in utf-8 was using ``h.encode('utf-8')`` now needs to convert from
bytes to native strings using ``h.encode('utf-8').decode('latin-1')``.
* Values yielded by an application or sent using the :meth:`write` method
must be byte strings. The :func:`start_response` function and environ
must use native strings. The two cannot be mixed.
For server implementers writing CGI-to-WSGI pathways or other CGI-style
protocols, the users must to be able access the environment using native strings
eventhough the underlying platform may have a different convention. To bridge
this gap, the :mod:`wsgiref` module has a new function,
:func:`wsgiref.handlers.read_environ` for transcoding CGI variables from
:attr:`os.environ` into native strings and returning a new dictionary.
.. seealso::
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment