Kaydet (Commit) dfa29161 authored tarafından Jannis Leidel's avatar Jannis Leidel

Fixed #14020 -- Made the `HttpResponse` class slightly more behave like a…

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
üst 22529d41
......@@ -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):
"""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment