This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: make wsgiref.headers.Headers accept empty constructor
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: berker.peksag Nosy List: BreamoreBoy, SilentGhost, berker.peksag, eric.araujo, pje, ptn, python-dev, r.david.murray, ramiroluz, tarek
Priority: normal Keywords: easy, needs review, patch

Created on 2009-04-20 16:01 by tarek, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
patch ptn, 2009-06-17 15:00
issue5800.diff SilentGhost, 2011-03-06 13:37 review
issue5800.diff berker.peksag, 2014-06-22 11:07 review
issue5800_v2.diff berker.peksag, 2014-06-26 21:28 review
issue5800_v3.diff berker.peksag, 2014-07-01 09:13 review
Messages (26)
msg86199 - (view) Author: Tarek Ziadé (tarek) * (Python committer) Date: 2009-04-20 16:01
wsgiref.headers.Headers will let you manage a collection of HTTP
response headers, but the constructor forces you to provide a list:

  >>> from wsgiref.headers import Headers
  >>> headers = Headers([])
  >>> headers.add_header('Content-Type', 'text/plain')

A logical change would be to allowed creating an empty Headers instance:

  >>> from wsgiref.headers import Headers
  >>> headers = Headers()
  >>> headers.add_header('Content-Type', 'text/plain')
msg89458 - (view) Author: Pablo Torres Navarrete (ptn) Date: 2009-06-17 15:00
Patch attached.  While I was at it, I also removed stupid whitespace and 
generally made the module more PEP8-compliant.
msg89459 - (view) Author: Tarek Ziadé (tarek) * (Python committer) Date: 2009-06-17 15:03
I have added another issue for PEP 8 compliancy at #5801
msg89484 - (view) Author: Pablo Torres Navarrete (ptn) Date: 2009-06-17 21:22
Added a pointer from #5801 to here.
msg121680 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2010-11-20 16:42
Correct and update patch + update test case
msg121681 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2010-11-20 16:43
here is the updated test case
msg121690 - (view) Author: Ramiro Batista da Luz (ramiroluz) Date: 2010-11-20 17:29
I applied the patches for wsgiref.headers and test_headers.py, ran the test with runtests.sh test_headers.py and it passed.

I also tried the code in the description: 

>>> from wsgiref.headers import Headers
>>> headers = Headers()
>>> headers.add_header('Content-Type', 'text/plain')
>>>
msg121829 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-11-21 01:40
FTR, note that “svn diff file1 file2...” will give you one file for many edits.  It’s easier to review and apply.

Regarding the change, I don’t know if wsgiref 3.2 has to be compatible with Python 2.1, which would exclude using the ternary operation.

The change from type to isinstance will probably be rejected, since WSGI does not accept subclasses for the things it defines.
msg121958 - (view) Author: PJ Eby (pje) * (Python committer) Date: 2010-11-21 18:38
Yes, please consider the type->isinstance part of the change rejected.  I just got done reverting a bunch of those in 3.2.  Where WSGI specifies types, it means "type() is", not "isinstance".

(The 3.x version of wsgiref does not need to be executable on 2.x versions, but this doesn't mean the protocol itself can be altered in backwards-incompatible ways, just the implementation.)
msg121959 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2010-11-21 18:42
Do I have to resubmit the patch or can you use the existing one?
msg122276 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2010-11-24 13:37
Re-submitting the patch for Lib/wsgiref/headers.py w/o the isinstance change
msg122318 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2010-11-24 22:51
Here is the correction for the docs. I would love to see this making it into 3.2 release.
msg122323 - (view) Author: Ramiro Batista da Luz (ramiroluz) Date: 2010-11-25 01:32
I reviewed the patch.

 - I applied all the patchs(3 files).
 - Ran make and make html in the Doc directory.
 - Ran the test_wsgiref.py
 - Ran the python interpreter and typed the suggested code:

>>> from wsgiref.headers import Headers
>>> headers = Headers([])
>>> headers.add_header('Content-Type', 'text/plain')
>>> headers = Headers()
>>> headers.add_header('Content-Type', 'text/plain')
>>> 

 - Read the documentation in a web browser.

All in the revision 86742.
msg122352 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-11-25 11:30
LGTM.
msg130169 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2011-03-06 13:37
Here's the single-file patch against the revision.
msg130181 - (view) Author: PJ Eby (pje) * (Python committer) Date: 2011-03-06 17:58
Looks good to me.
msg130752 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2011-03-13 17:53
> Looks good to me.
Would you mind committing it then?
msg131578 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-03-21 00:15
I think the doc should say something like “default value is an empty list”, for maximum clarity.
msg221243 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-06-22 10:11
This shouldn't be languishing, work has been committed against revision 86742 and there's another patch that apparently just needs a little tweak.
msg221247 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2014-06-22 11:07
The patch is not committed yet.

$ ./python
Python 3.5.0a0 (default:979aaa08c067+, Jun 19 2014, 13:01:36) 
[GCC 4.6.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from wsgiref.headers import Headers
>>> h = Headers()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: __init__() missing 1 required positional argument: 'headers'

Here's an updated patch that addresses Éric's review (and without cosmetic changes to make review easier).
msg221248 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-06-22 11:43
Just for the record clicking on "revision 86742" gives "Specified revision r86742 not found".
msg221650 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2014-06-26 21:28
Here's a new patch with a whatsnew entry. David, could you review the patch?
msg222020 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2014-07-01 09:13
Patch updated. If there's no objections, I'll commit this patch in the next couple of days.
msg222033 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-07-01 14:18
Since we don't need to avoid new language features, using the ternary would be better than using the or.  This is exactly the sort of situation the ternary was introduced for: making sure the input really is None before applying the default.

Otherwise the patch looks good.
msg222069 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-07-02 05:37
New changeset a91f0d4a2381 by Berker Peksag in branch 'default':
Issue #5800: headers parameter of wsgiref.headers.Headers is now optional.
http://hg.python.org/cpython/rev/a91f0d4a2381
msg222070 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2014-07-02 05:38
Thanks for the patch and review.
History
Date User Action Args
2022-04-11 14:56:48adminsetgithub: 50050
2014-07-02 05:38:54berker.peksagsetstatus: open -> closed
resolution: fixed
messages: + msg222070

stage: commit review -> resolved
2014-07-02 05:37:28python-devsetnosy: + python-dev
messages: + msg222069
2014-07-01 14:18:22r.david.murraysetmessages: + msg222033
2014-07-01 09:13:13berker.peksagsetfiles: + issue5800_v3.diff
assignee: pje -> berker.peksag
messages: + msg222020

stage: patch review -> commit review
2014-06-26 21:28:14berker.peksagsetfiles: + issue5800_v2.diff
nosy: + r.david.murray
messages: + msg221650

2014-06-22 11:43:19BreamoreBoysetmessages: + msg221248
2014-06-22 11:07:02berker.peksagsetstatus: languishing -> open
files: + issue5800.diff
versions: + Python 3.5, - Python 3.3
nosy: + berker.peksag

messages: + msg221247
2014-06-22 10:11:57BreamoreBoysetnosy: + BreamoreBoy
messages: + msg221243
2011-03-21 00:15:52eric.araujosetnosy: pje, tarek, eric.araujo, ptn, SilentGhost, ramiroluz
messages: + msg131578
versions: + Python 3.3, - Python 3.2
2011-03-13 17:53:45SilentGhostsetnosy: pje, tarek, eric.araujo, ptn, SilentGhost, ramiroluz
messages: + msg130752
2011-03-06 17:58:41pjesetnosy: pje, tarek, eric.araujo, ptn, SilentGhost, ramiroluz
messages: + msg130181
2011-03-06 13:37:41SilentGhostsetfiles: - wsgiref.rst.diff
nosy: pje, tarek, eric.araujo, ptn, SilentGhost, ramiroluz
2011-03-06 13:37:28SilentGhostsetfiles: - headers.py.diff
nosy: pje, tarek, eric.araujo, ptn, SilentGhost, ramiroluz
2011-03-06 13:37:21SilentGhostsetfiles: - test_wsgiref.py.diff
nosy: pje, tarek, eric.araujo, ptn, SilentGhost, ramiroluz
2011-03-06 13:37:06SilentGhostsetfiles: + issue5800.diff
nosy: pje, tarek, eric.araujo, ptn, SilentGhost, ramiroluz
messages: + msg130169
2011-01-15 15:22:59SilentGhostsetstatus: open -> languishing
nosy: pje, tarek, eric.araujo, ptn, SilentGhost, ramiroluz
2010-11-25 11:30:26eric.araujosetassignee: pje
messages: + msg122352
2010-11-25 01:32:58ramiroluzsetmessages: + msg122323
2010-11-24 22:51:52SilentGhostsetfiles: + wsgiref.rst.diff

messages: + msg122318
2010-11-24 13:47:07djcsetkeywords: + needs review
2010-11-24 13:37:35SilentGhostsetfiles: + headers.py.diff
keywords: + patch
messages: + msg122276
2010-11-24 13:36:56SilentGhostsetfiles: - headers.py.diff
2010-11-21 18:42:56SilentGhostsetmessages: + msg121959
2010-11-21 18:38:51pjesetmessages: + msg121958
2010-11-21 01:40:30eric.araujosetnosy: + eric.araujo
messages: + msg121829
2010-11-20 17:29:00ramiroluzsetnosy: + ramiroluz
messages: + msg121690
2010-11-20 17:13:24r.david.murraysetkeywords: - patch
stage: test needed -> patch review
versions: - Python 2.7
2010-11-20 16:43:05SilentGhostsetfiles: + test_wsgiref.py.diff

messages: + msg121681
2010-11-20 16:42:34SilentGhostsetfiles: + headers.py.diff

nosy: + SilentGhost
messages: + msg121680

keywords: + patch
2009-06-17 21:22:49ptnsetmessages: + msg89484
2009-06-17 15:03:35tareksetmessages: + msg89459
versions: + Python 3.2, - Python 3.1
2009-06-17 15:00:00ptnsetfiles: + patch
nosy: + ptn
messages: + msg89458

2009-04-22 05:06:35ajaksu2setkeywords: + easy
stage: test needed
2009-04-20 16:01:04tarekcreate