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
This commit is contained in:
Jannis Leidel 2011-06-16 16:34:46 +00:00
parent 22529d41b2
commit dfa29161e2
2 changed files with 8 additions and 1 deletions

View File

@ -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='/',

View File

@ -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):
"""