[Zope3-checkins] SVN: Zope3/trunk/src/ Fix the mechanize and ClientCookie bugs. external tests pass and patch has been sent to maintainer. Eliminates libssl dependency.

Gary Poster gary at zope.com
Tue Nov 1 14:38:02 EST 2005


Log message for revision 39822:
  Fix the mechanize and ClientCookie bugs.  external tests pass and patch has been sent to maintainer.  Eliminates libssl dependency.
  
  

Changed:
  U   Zope3/trunk/src/ClientCookie/_Util.py
  U   Zope3/trunk/src/mechanize/_mechanize.py
  U   Zope3/trunk/src/mechanize/_useragent.py
  U   Zope3/trunk/src/zope/testbrowser/browser.py

-=-
Modified: Zope3/trunk/src/ClientCookie/_Util.py
===================================================================
--- Zope3/trunk/src/ClientCookie/_Util.py	2005-11-01 19:21:26 UTC (rev 39821)
+++ Zope3/trunk/src/ClientCookie/_Util.py	2005-11-01 19:38:02 UTC (rev 39822)
@@ -541,10 +541,13 @@
     """
 
     def close(self):
-        self.headers = self.wrapped.headers
-        self.url = self.wrapped.url
-        self.wrapped.close()
-        self.wrapped = eoffile()
+        if not isinstance(self.wrapped, eoffile):
+            headers = self.wrapped.headers
+            url = self.wrapped.url
+            self.wrapped.close()
+            self.wrapped = eoffile()
+            self.wrapped.headers = headers
+            self.wrapped.url = url
 
     def __getstate__(self):
         # There are three obvious options here:

Modified: Zope3/trunk/src/mechanize/_mechanize.py
===================================================================
--- Zope3/trunk/src/mechanize/_mechanize.py	2005-11-01 19:21:26 UTC (rev 39821)
+++ Zope3/trunk/src/mechanize/_mechanize.py	2005-11-01 19:38:02 UTC (rev 39822)
@@ -306,7 +306,7 @@
         """
         if self._response is not None:
             self._response.close()
-        while n:
+        while n > 0 or self._response is None:
             try:
                 self.request, self._response = self._history.pop()
             except IndexError:

Modified: Zope3/trunk/src/mechanize/_useragent.py
===================================================================
--- Zope3/trunk/src/mechanize/_useragent.py	2005-11-01 19:21:26 UTC (rev 39821)
+++ Zope3/trunk/src/mechanize/_useragent.py	2005-11-01 19:38:02 UTC (rev 39822)
@@ -17,7 +17,11 @@
 if sys.version_info[:2] >= (2, 4):
     import cookielib
     from urllib2 import OpenerDirector, BaseHandler, \
-         HTTPHandler, HTTPSHandler, HTTPErrorProcessor
+         HTTPHandler, HTTPErrorProcessor
+    try:
+        from urllib2 import HTTPSHandler
+    except ImportError:
+        pass
     class SaneHTTPCookieProcessor(ClientCookie.HTTPCookieProcessor):
         # 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
@@ -31,7 +35,11 @@
     HTTPCookieProcessor = SaneHTTPCookieProcessor
 else:
     from ClientCookie import OpenerDirector, BaseHandler, \
-         HTTPHandler, HTTPSHandler, HTTPErrorProcessor, HTTPCookieProcessor
+         HTTPHandler, HTTPErrorProcessor, HTTPCookieProcessor
+    try:
+        from ClientCookie import HTTPSHandler
+    except ImportError:
+        pass
 
 class HTTPRefererProcessor(BaseHandler):
     def http_request(self, request):

Modified: Zope3/trunk/src/zope/testbrowser/browser.py
===================================================================
--- Zope3/trunk/src/zope/testbrowser/browser.py	2005-11-01 19:21:26 UTC (rev 39821)
+++ Zope3/trunk/src/zope/testbrowser/browser.py	2005-11-01 19:38:02 UTC (rev 39822)
@@ -234,18 +234,7 @@
         """See zope.testbrowser.interfaces.IBrowser"""
         self._start_timer()
         self.mech_browser.back(count)
-        # we want to ignore history of 302 redirects.  If we go back to far,
-        # mechanize will raise a BrowserStateError as usual
-        while self.mech_browser.response() is None:
-            self.mech_browser.back()
         self._stop_timer()
-        # TODO this is a hack to get around a bug in mechanize
-        response = self.mech_browser.response()
-        if response is not None:
-            response.wrapped.url = response.url
-            response.wrapped.headers = response.headers
-            response.close = lambda: None
-        # end hack
         self._changed()
 
     def addHeader(self, key, value):



More information about the Zope3-Checkins mailing list