From dfa29161e2eff676eb4aa187f76c157556dfc5db Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Thu, 16 Jun 2011 16:34:46 +0000 Subject: [PATCH] Fixed #14020 -- Made the `HttpResponse` class slightly more behave like a dictionary, allowing the alternative argument to be unset. Serious thanks to schmichael and moopet. git-svn-id: http://code.djangoproject.com/svn/django/trunk@16417 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/http/__init__.py | 2 +- tests/regressiontests/httpwrappers/tests.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/django/http/__init__.py b/django/http/__init__.py index 7f198a7b08e..2a88ee19504 100644 --- a/django/http/__init__.py +++ b/django/http/__init__.py @@ -615,7 +615,7 @@ class HttpResponse(object): def items(self): return self._headers.values() - def get(self, header, alternate): + def get(self, header, alternate=None): return self._headers.get(header.lower(), (None, alternate))[1] def set_cookie(self, key, value='', max_age=None, expires=None, path='/', diff --git a/tests/regressiontests/httpwrappers/tests.py b/tests/regressiontests/httpwrappers/tests.py index fbed94413bb..493109a38ea 100644 --- a/tests/regressiontests/httpwrappers/tests.py +++ b/tests/regressiontests/httpwrappers/tests.py @@ -243,6 +243,13 @@ class HttpResponseTests(unittest.TestCase): self.assertRaises(BadHeaderError, r.__setitem__, 'test\rstr', 'test') self.assertRaises(BadHeaderError, r.__setitem__, 'test\nstr', 'test') + def test_dict_behavior(self): + """ + Test for bug #14020: Make HttpResponse.get work like dict.get + """ + r = HttpResponse() + self.assertEqual(r.get('test'), None) + class CookieTests(unittest.TestCase): def test_encode(self): """