[wwwsearch-commits] r23244 - wwwsearch/mechanize/trunk/mechanize

jjlee at codespeak.net jjlee at codespeak.net
Sun Feb 12 03:23:25 CET 2006


Author: jjlee
Date: Sun Feb 12 03:23:22 2006
New Revision: 23244

Modified:
   wwwsearch/mechanize/trunk/mechanize/_useragent.py
Log:
Always use ClientCookie.HTTPHandler (urllib2's HTTPHandler doesn't have .code and .msg attributes); Only apply RFC 2109 bug hack to exactly Python 2.4 (fixed in 2.5)

Modified: wwwsearch/mechanize/trunk/mechanize/_useragent.py
==============================================================================
--- wwwsearch/mechanize/trunk/mechanize/_useragent.py	(original)
+++ wwwsearch/mechanize/trunk/mechanize/_useragent.py	Sun Feb 12 03:23:22 2006
@@ -15,31 +15,23 @@
 import urllib2, httplib
 import ClientCookie
 if sys.version_info[:2] >= (2, 4):
-    import cookielib
-    from urllib2 import OpenerDirector, BaseHandler, \
-         HTTPHandler, HTTPErrorProcessor
-    try:
-        from urllib2 import HTTPSHandler
-    except ImportError:
-        pass
-    class SaneHTTPCookieProcessor(ClientCookie.HTTPCookieProcessor):
+    from urllib2 import OpenerDirector, BaseHandler, HTTPErrorProcessor
+    if sys.version_info[:2] == (2, 4):
         # Workaround for RFC 2109 bug http://python.org/sf/1157027 (at least if
         # you don't pass your own CookieJar in: if that's the case, you should
         # pass rfc2965=True to the DefaultCookiePolicy constructor yourself, or
         # set the corresponding attribute).
-        def __init__(self, cookiejar=None):
-            if cookiejar is None:
-                cookiejar = cookielib.CookieJar(
-                    cookielib.DefaultCookiePolicy(rfc2965=True))
-            self.cookiejar = cookiejar
-    HTTPCookieProcessor = SaneHTTPCookieProcessor
+        import cookielib
+        class SaneHTTPCookieProcessor(urllib2.HTTPCookieProcessor):
+            def __init__(self, cookiejar=None):
+                if cookiejar is None:
+                    cookiejar = cookielib.CookieJar(
+                        cookielib.DefaultCookiePolicy(rfc2965=True))
+                self.cookiejar = cookiejar
+        HTTPCookieProcessor = SaneHTTPCookieProcessor
 else:
-    from ClientCookie import OpenerDirector, BaseHandler, \
-         HTTPHandler, HTTPErrorProcessor, HTTPCookieProcessor
-    try:
-        from ClientCookie import HTTPSHandler
-    except ImportError:
-        pass
+    from ClientCookie import OpenerDirector, BaseHandler, HTTPErrorProcessor, \
+         HTTPCookieProcessor
 
 class HTTPRefererProcessor(BaseHandler):
     def http_request(self, request):
@@ -76,7 +68,7 @@
 
     handler_classes = {
         # scheme handlers
-        "http": HTTPHandler,
+        "http": ClientCookie.HTTPHandler,
         "ftp": urllib2.FTPHandler,  # CacheFTPHandler is buggy in 2.3
         "file": urllib2.FileHandler,
         "gopher": urllib2.GopherHandler,
@@ -112,7 +104,7 @@
     default_features = ["_authen", "_redirect", "_cookies", "_refresh",
                         "_referer", "_equiv", "_seek", "_proxy"]
     if hasattr(httplib, 'HTTPS'):
-        handler_classes["https"] = HTTPSHandler
+        handler_classes["https"] = ClientCookie.HTTPSHandler
         default_schemes.append("https")
     if hasattr(ClientCookie, "HTTPRobotRulesProcessor"):
         handler_classes["_robots"] = ClientCookie.HTTPRobotRulesProcessor


More information about the wwwsearch-commits mailing list