From 3e887222aa758ac5a3fb61c8e77e909372462d00 Mon Sep 17 00:00:00 2001 From: Berker Peksag Date: Wed, 2 Jul 2014 08:37:22 +0300 Subject: Issue #5800: headers parameter of wsgiref.headers.Headers is now optional. Patch by Pablo Torres Navarrete and SilentGhost. --- 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 index 1cef2e9..2238140 100644 --- a/Doc/library/wsgiref.rst +++ b/Doc/library/wsgiref.rst @@ -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 --------------------------------------------------------- diff --git a/Doc/whatsnew/3.5.rst b/Doc/whatsnew/3.5.rst index 9fff48c..0842143 100644 --- a/Doc/whatsnew/3.5.rst +++ b/Doc/whatsnew/3.5.rst @@ -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 ------ diff --git a/Lib/test/test_wsgiref.py b/Lib/test/test_wsgiref.py index 901f3c9..190f3ba 100644 --- a/Lib/test/test_wsgiref.py +++ b/Lib/test/test_wsgiref.py @@ -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") diff --git a/Lib/wsgiref/headers.py b/Lib/wsgiref/headers.py index d939628..7931bc7 100644 --- a/Lib/wsgiref/headers.py +++ b/Lib/wsgiref/headers.py @@ -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 diff --git a/Misc/NEWS b/Misc/NEWS index ad521b5..0428775 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -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 -- cgit v0.12