summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJannis Leidel <jannis@leidel.info>2011-06-16 16:34:46 +0000
committerJannis Leidel <jannis@leidel.info>2011-06-16 16:34:46 +0000
commitdfa29161e2eff676eb4aa187f76c157556dfc5db (patch)
tree7f8ae90d7f8955a0785e3c4b8e9d5a72d828ff4f
parent22529d41b26137ac87c5e08a6c19e6e91552756e (diff)
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
-rw-r--r--django/http/__init__.py2
-rw-r--r--tests/regressiontests/httpwrappers/tests.py7
2 files changed, 8 insertions, 1 deletions
diff --git a/django/http/__init__.py b/django/http/__init__.py
index 7f198a7b08..2a88ee1950 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 fbed94413b..493109a38e 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):
"""