Issue 17349: wsgiref.simple_server.demo_app is not PEP-3333 compatible

Created on 2013-03-04 12:27 by kedder, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
wsgirefbug.py kedder, 2013-03-04 12:27
issue-17349-wsgiref adam-collard, 2013-07-06 13:01 patch to encode hello world as UTF-8
Messages (4)
msg183437 - (view) Author: Andrey Lebedev (kedder) Date: 2013-03-04 12:27
Under certain circumstances, wsgiref.simple_server.demo_app may return unicode data, but that is prohibited by PEP-3333.

This happens if environ with unicode key is passed to demo_app. Unicode keys are then written to StringIO instance, automatically making its value unicode.

Type of environ keys is not strictly mandated by PEP-3333, however output of WSGI application is:

  "When called by the server, the application object must return an iterable yielding zero or more bytestrings.", see http://www.python.org/dev/peps/pep-3333/#specification-details

Test case is attached.
msg192435 - (view) Author: Adam Collard (adam-collard) * Date: 2013-07-06 13:01
Since this bug depends on a __future__ import I was advised to put the test in a separate file.
msg235917 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2015-02-13 19:59
I'm not sure this needs to be fixed in 2.7. I would only use demo_app to test WSGI servers. Otherwise, you need to create your own application. However, the code is correct in Python 3: https://hg.python.org/cpython/file/default/Lib/wsgiref/simple_server.py#l146

(Note: PEP 3333 is for Python 3. In Python 2, the correct quote is "When called by the server, the application object must return an iterable yielding zero or more strings." See PEP 333.)
msg340865 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2019-04-25 22:21
Closing this as 'not a bug' since examples in both branches are correct. Thank you for the report!
History
Date User Action Args
2022-04-11 14:57:42adminsetgithub: 61551
2019-04-25 22:21:59berker.peksagsetstatus: open -> closed
resolution: not a bug
messages: + msg340865

stage: patch review -> resolved

2015-02-13 19:59:08berker.peksagsetnosy: + berker.peksag
messages: + msg235917
2013-07-18 21:10:32ezio.melottisetstage: patch review
2013-07-06 13:01:01adam-collardsetfiles: + issue-17349-wsgiref

messages: + msg192435

2013-07-06 12:17:09adam-collardsetnosy: + adam-collard
2013-03-09 00:13:43tshepangsetnosy: + pje, tshepang
2013-03-04 12:27:33keddercreate