fix get_meta_refresh bug raised for TextResponses without encoding

This commit is contained in:
Daniel Grana 2009-10-21 13:57:06 -02:00
parent 6405efa507
commit 3d7a4c890e
2 changed files with 7 additions and 1 deletions

View File

@ -93,6 +93,12 @@ class ResponseUtilsTest(unittest.TestCase):
response = Response(url='http://example.com', body=body)
self.assertEqual(get_meta_refresh(response), (3, 'http://example.com/thisTHAT'))
# responses without refresh tag should return None None
response = Response(url='http://example.org')
self.assertEqual(get_meta_refresh(response), (None, None))
response = TextResponse(url='http://example.org')
self.assertEqual(get_meta_refresh(response), (None, None))
def test_response_httprepr(self):
r1 = Response("http://www.example.com")
self.assertEqual(response_httprepr(r1), 'HTTP/1.1 200 OK\r\n\r\n')

View File

@ -47,7 +47,7 @@ def get_meta_refresh(response):
If no meta redirect is found, (None, None) is returned.
"""
if response not in _metaref_cache:
encoding = getattr(response, 'encoding', 'utf-8')
encoding = getattr(response, 'encoding', None) or 'utf-8'
body_chunk = remove_entities(unicode(response.body[0:4096], encoding, \
errors='ignore'))
match = META_REFRESH_RE.search(body_chunk)