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:
parent
22529d41b2
commit
dfa29161e2
|
@ -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='/',
|
||||
|
|
|
@ -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):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue