Scrapy, a fast high-level web crawling & scraping framework for Python.
Fixed bug with float values in meta refresh
Martin Olveyrab258fc3305dd
diff --git a/scrapy/tests/test_utils_response.py b/scrapy/tests/test_utils_response.pyindex 3337b80d6..99f1d0ea8 100644--- a/scrapy/tests/test_utils_response.py+++ b/scrapy/tests/test_utils_response.py@@ -122,6 +122,15 @@ class ResponseUtilsTest(unittest.TestCase):response = TextResponse(url='http://example.com', body=body)self.assertEqual(get_meta_refresh(response), (3, 'http://example.com/'))+ # float refresh intervals+ body = """<meta http-equiv="refresh" content=".1;URL=index.html" />"""+ response = TextResponse(url='http://example.com', body=body)+ self.assertEqual(get_meta_refresh(response), (0.1, 'http://example.com/index.html'))++ body = """<meta http-equiv="refresh" content="3.1;URL=index.html" />"""+ response = TextResponse(url='http://example.com', body=body)+ self.assertEqual(get_meta_refresh(response), (3.1, 'http://example.com/index.html'))+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')diff --git a/scrapy/utils/response.py b/scrapy/utils/response.pyindex a691d8875..0f44a6f5a 100644--- a/scrapy/utils/response.py+++ b/scrapy/utils/response.py@@ -36,7 +36,7 @@ def get_base_url(response):_baseurl_cache[response] = urljoin_rfc(response.url, match.group(1)) if match else response.urlreturn _baseurl_cache[response]-META_REFRESH_RE = re.compile(ur'<meta[^>]*http-equiv[^>]*refresh[^>]*content\s*=\s*(?P<quote>["\'])(?P<int>\d+)\s*;\s*url=(?P<url>.*?)(?P=quote)', \+META_REFRESH_RE = re.compile(ur'<meta[^>]*http-equiv[^>]*refresh[^>]*content\s*=\s*(?P<quote>["\'])(?P<int>(\d*\.)?\d+)\s*;\s*url=(?P<url>.*?)(?P=quote)', \re.DOTALL | re.IGNORECASE)_metaref_cache = weakref.WeakKeyDictionary()def get_meta_refresh(response):@@ -51,7 +51,7 @@ def get_meta_refresh(response):body_chunk = remove_comments(remove_entities(response.body_as_unicode()[0:4096]))match = META_REFRESH_RE.search(body_chunk)if match:- interval = int(match.group('int'))+ interval = float(match.group('int'))url = safe_url_string(match.group('url').strip(' "\''))url = urljoin_rfc(response.url, url)_metaref_cache[response] = (interval, url)