Issue #5800: headers parameter of wsgiref.headers.Headers is now optional.

Patch by Pablo Torres Navarrete and SilentGhost.
This commit is contained in:
Berker Peksag 2014-07-02 08:37:22 +03:00
parent 09db75fcd6
commit 3e887222aa
5 changed files with 21 additions and 7 deletions

View File

@ -184,10 +184,11 @@ This module provides a single class, :class:`Headers`, for convenient
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 @@ manipulation of WSGI response headers using a mapping-like interface.
Content-Disposition: attachment; filename="bud.gif"
.. versionchanged:: 3.5
*headers* parameter is optional.
:mod:`wsgiref.simple_server` -- a simple WSGI HTTP server
---------------------------------------------------------

View File

@ -230,6 +230,12 @@ socket
: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
------

View File

@ -338,6 +338,7 @@ class HeaderTests(TestCase):
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 @@ class HeaderTests(TestCase):
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 @@ class HeaderTests(TestCase):
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")

View File

@ -26,10 +26,10 @@ def _formatparam(param, value=None, quote=1):
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

View File

@ -103,6 +103,9 @@ Core and Builtins
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