[Python-checkins] cpython: Issue #5800: headers parameter of wsgiref.headers.Headers is now optional.
berker.peksag
python-checkins at python.org
Wed Jul 2 07:37:29 CEST 2014
http://hg.python.org/cpython/rev/a91f0d4a2381
changeset: 91522:a91f0d4a2381
user: Berker Peksag <berker.peksag at gmail.com>
date: Wed Jul 02 08:37:22 2014 +0300
summary:
Issue #5800: headers parameter of wsgiref.headers.Headers is now optional.
Patch by Pablo Torres Navarrete and SilentGhost.
files:
Doc/library/wsgiref.rst | 9 +++++++--
Doc/whatsnew/3.5.rst | 6 ++++++
Lib/test/test_wsgiref.py | 6 +++---
Lib/wsgiref/headers.py | 4 ++--
Misc/NEWS | 3 +++
5 files changed, 21 insertions(+), 7 deletions(-)
diff --git a/Doc/library/wsgiref.rst b/Doc/library/wsgiref.rst
--- a/Doc/library/wsgiref.rst
+++ b/Doc/library/wsgiref.rst
@@ -184,10 +184,11 @@
manipulation of WSGI response headers using a mapping-like interface.
-.. class:: Headers(headers)
+.. class:: Headers([headers])
Create a mapping-like object wrapping *headers*, which must be a list of header
- name/value tuples as described in :pep:`3333`.
+ name/value tuples as described in :pep:`3333`. The default value of *headers* is
+ an empty list.
:class:`Headers` objects support typical mapping operations including
:meth:`__getitem__`, :meth:`get`, :meth:`__setitem__`, :meth:`setdefault`,
@@ -251,6 +252,10 @@
Content-Disposition: attachment; filename="bud.gif"
+ .. versionchanged:: 3.5
+ *headers* parameter is optional.
+
+
:mod:`wsgiref.simple_server` -- a simple WSGI HTTP server
---------------------------------------------------------
diff --git a/Doc/whatsnew/3.5.rst b/Doc/whatsnew/3.5.rst
--- a/Doc/whatsnew/3.5.rst
+++ b/Doc/whatsnew/3.5.rst
@@ -230,6 +230,12 @@
:meth:`socket.socket.send`.
(contributed by Giampaolo Rodola' in :issue:`17552`)
+wsgiref
+-------
+
+* *headers* parameter of :class:`wsgiref.headers.Headers` is now optional.
+ (Contributed by Pablo Torres Navarrete and SilentGhost in :issue:`5800`.)
+
xmlrpc
------
diff --git a/Lib/test/test_wsgiref.py b/Lib/test/test_wsgiref.py
--- a/Lib/test/test_wsgiref.py
+++ b/Lib/test/test_wsgiref.py
@@ -338,6 +338,7 @@
def testMappingInterface(self):
test = [('x','y')]
+ self.assertEqual(len(Headers()), 0)
self.assertEqual(len(Headers([])),0)
self.assertEqual(len(Headers(test[:])),1)
self.assertEqual(Headers(test[:]).keys(), ['x'])
@@ -345,7 +346,7 @@
self.assertEqual(Headers(test[:]).items(), test)
self.assertIsNot(Headers(test).items(), test) # must be copy!
- h=Headers([])
+ h = Headers()
del h['foo'] # should not raise an error
h['Foo'] = 'bar'
@@ -370,9 +371,8 @@
def testRequireList(self):
self.assertRaises(TypeError, Headers, "foo")
-
def testExtras(self):
- h = Headers([])
+ h = Headers()
self.assertEqual(str(h),'\r\n')
h.add_header('foo','bar',baz="spam")
diff --git a/Lib/wsgiref/headers.py b/Lib/wsgiref/headers.py
--- a/Lib/wsgiref/headers.py
+++ b/Lib/wsgiref/headers.py
@@ -26,10 +26,10 @@
class Headers:
-
"""Manage a collection of HTTP response headers"""
- def __init__(self,headers):
+ def __init__(self, headers=None):
+ headers = headers if headers is not None else []
if type(headers) is not list:
raise TypeError("Headers must be a list of name/value tuples")
self._headers = headers
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -103,6 +103,9 @@
Library
-------
+- Issue #5800: headers parameter of wsgiref.headers.Headers is now optional.
+ Initial patch by Pablo Torres Navarrete and SilentGhost.
+
- Issue #21781: ssl.RAND_add() now supports strings longer than 2 GB.
- Issue #21679: Prevent extraneous fstat() calls during open(). Patch by
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list