[wwwsearch-commits] r29657 - in wwwsearch/mechanize/trunk: mechanize test
jjlee at codespeak.net
jjlee at codespeak.net
Wed Jul 5 22:54:42 CEST 2006
Author: jjlee
Date: Wed Jul 5 22:54:41 2006
New Revision: 29657
Modified:
wwwsearch/mechanize/trunk/mechanize/_http.py
wwwsearch/mechanize/trunk/test/test_urllib2.py
Log:
Fix UnboundLocalError for Refresh with URL but no '=' (titus)
Modified: wwwsearch/mechanize/trunk/mechanize/_http.py
==============================================================================
--- wwwsearch/mechanize/trunk/mechanize/_http.py (original)
+++ wwwsearch/mechanize/trunk/mechanize/_http.py Wed Jul 5 22:54:41 2006
@@ -433,9 +433,10 @@
if ii != -1:
pause, newurl_spec = float(refresh[:ii]), refresh[ii+1:]
jj = newurl_spec.find("=")
+ key = None
if jj != -1:
key, newurl = newurl_spec[:jj], newurl_spec[jj+1:]
- if key.strip().lower() != "url":
+ if key is None or key.strip().lower() != "url":
debug("bad Refresh header: %r" % refresh)
return response
else:
Modified: wwwsearch/mechanize/trunk/test/test_urllib2.py
==============================================================================
--- wwwsearch/mechanize/trunk/test/test_urllib2.py (original)
+++ wwwsearch/mechanize/trunk/test/test_urllib2.py Wed Jul 5 22:54:41 2006
@@ -778,14 +778,20 @@
# XXX test processor constructor optional args
h = HTTPRefreshProcessor(max_time=None, honor_time=False)
- for val in ['0; url="http://example.com/foo/"', "2"]:
+ for val, valid in [
+ ('0; url="http://example.com/foo/"', True),
+ ("2", True),
+ # in the past, this failed with UnboundLocalError
+ ('0; "http://example.com/foo/"', False),
+ ]:
o = h.parent = MockOpener()
req = Request("http://example.com/")
headers = MockHeaders({"refresh": val})
r = MockResponse(200, "OK", headers, "")
newr = h.http_response(req, r)
- self.assertEqual(o.proto, "http")
- self.assertEqual(o.args, (req, r, "refresh", "OK", headers))
+ if valid:
+ self.assertEqual(o.proto, "http")
+ self.assertEqual(o.args, (req, r, "refresh", "OK", headers))
def test_redirect(self):
from_url = "http://example.com/a.html"
More information about the wwwsearch-commits
mailing list