[wwwsearch-commits] r21972 - in wwwsearch/ClientCookie/trunk: . ClientCookie test

jjlee at codespeak.net jjlee at codespeak.net
Wed Jan 11 20:41:23 CET 2006


Author: jjlee
Date: Wed Jan 11 20:41:22 2006
New Revision: 21972

Modified:
   wwwsearch/ClientCookie/trunk/ClientCookie/_urllib2_support.py
   wwwsearch/ClientCookie/trunk/functional_tests.py
   wwwsearch/ClientCookie/trunk/test/test_urllib2.py
Log:
Merge all relevant changes from 1.1.1-seek-fix (functional tests and Refresh fix)

Modified: wwwsearch/ClientCookie/trunk/ClientCookie/_urllib2_support.py
==============================================================================
--- wwwsearch/ClientCookie/trunk/ClientCookie/_urllib2_support.py	(original)
+++ wwwsearch/ClientCookie/trunk/ClientCookie/_urllib2_support.py	Wed Jan 11 20:41:22 2006
@@ -18,6 +18,7 @@
 from _Util import isstringlike, startswith, getheaders
 from _HeadersUtil import is_html
 from _Debug import getLogger
+debug = getLogger("ClientCookie.cookies").debug
 
 try: True
 except NameError:
@@ -499,21 +500,25 @@
 
             if code == 200 and hdrs.has_key("refresh"):
                 refresh = getheaders(hdrs, "refresh")[0]
-                i = string.find(refresh, ";")
-                if i != -1:
-                    pause, newurl_spec = refresh[:i], refresh[i+1:]
-                    i = string.find(newurl_spec, "=")
-                    if i != -1:
-                        pause = int(pause)
-                        if (self.max_time is None) or (pause <= self.max_time):
-                            if pause != 0 and self.honor_time:
-                                time.sleep(pause)
-                            newurl = newurl_spec[i+1:]
-                            hdrs["location"] = newurl
-                            # hardcoded http is NOT a bug
-                            response = self.parent.error(
-                                "http", request, response,
-                                "refresh", msg, hdrs)
+                ii = string.find(refresh, ";")
+                if ii != -1:
+                    pause, newurl_spec = int(refresh[:ii]), refresh[ii+1:]
+                    jj = string.find(newurl_spec, "=")
+                    if jj != -1:
+                        key, newurl = newurl_spec[:jj], newurl_spec[jj+1:]
+                    if key.strip() != "url":
+                        debug("bad Refresh header: %r" % refresh)
+                        return response
+                else:
+                    pause, newurl = int(refresh), response.geturl()
+                if (self.max_time is None) or (pause <= self.max_time):
+                    if pause != 0 and self.honor_time:
+                        time.sleep(pause)
+                    hdrs["location"] = newurl
+                    # hardcoded http is NOT a bug
+                    response = self.parent.error(
+                        "http", request, response,
+                        "refresh", msg, hdrs)
 
             return response
 

Modified: wwwsearch/ClientCookie/trunk/functional_tests.py
==============================================================================
--- wwwsearch/ClientCookie/trunk/functional_tests.py	(original)
+++ wwwsearch/ClientCookie/trunk/functional_tests.py	Wed Jan 11 20:41:22 2006
@@ -4,6 +4,7 @@
 
 import unittest, string, os
 from unittest import TestCase
+import urllib2
 
 import ClientCookie
 from ClientCookie import build_opener, install_opener, urlopen, urlretrieve
@@ -48,8 +49,13 @@
         o = apply(build_opener, handlers)
         try:
             install_opener(o)
-            r = urlopen("http://boards.ign.com/help/cookie_test.asp")
+            try:
+                r = urlopen("http://wwwsearch.sf.net/cgi-bin/cookietest.cgi")
+            except URLError, e:
+                print e.read()
+                raise
             data = r.read()
+            print data
             self.assert_(
                 string.find(data, "Your browser supports cookies!") >= 0)
             self.assert_(len(cj) == 1)

Modified: wwwsearch/ClientCookie/trunk/test/test_urllib2.py
==============================================================================
--- wwwsearch/ClientCookie/trunk/test/test_urllib2.py	(original)
+++ wwwsearch/ClientCookie/trunk/test/test_urllib2.py	Wed Jan 11 20:41:22 2006
@@ -688,16 +688,17 @@
         self.assert_(headers["Foo"] == "Bar")
 
     def test_refresh(self):
-        # XXX processor constructor optional args
-        h = HTTPRefreshProcessor()
-        o = h.parent = MockOpener()
+        # XXX test processor constructor optional args
+        h = HTTPRefreshProcessor(max_time=None, honor_time=False)
 
-        req = Request("http://example.com/")
-        headers = MockHeaders({"refresh": '0; url="http://example.com/foo/"'})
-        r = MockResponse(200, "OK", headers, "")
-        newr = h.http_response(req, r)
-        self.assert_(o.proto == "http")
-        self.assert_(o.args == (req, r, "refresh", "OK", headers))
+        for val in ['0; url="http://example.com/foo/"', "2"]:
+            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))
 
     def test_redirect(self):
         from_url = "http://example.com/a.html"


More information about the wwwsearch-commits mailing list