[wwwsearch-commits] r19801 - in wwwsearch/mechanize/trunk: . mechanize

jjlee at codespeak.net jjlee at codespeak.net
Sat Nov 12 19:31:56 CET 2005


Author: jjlee
Date: Sat Nov 12 19:31:55 2005
New Revision: 19801

Modified:
   wwwsearch/mechanize/trunk/mechanize/_mechanize.py
   wwwsearch/mechanize/trunk/mechanize/_useragent.py
   wwwsearch/mechanize/trunk/test.py
Log:
Fix history; Close responses on reload; Don't depend on SSL support (Gary Poster)

Modified: wwwsearch/mechanize/trunk/mechanize/_mechanize.py
==============================================================================
--- wwwsearch/mechanize/trunk/mechanize/_mechanize.py	(original)
+++ wwwsearch/mechanize/trunk/mechanize/_mechanize.py	Sat Nov 12 19:31:55 2005
@@ -244,7 +244,8 @@
         if self._response is not None:
             self._response.close()    
         UserAgent.close(self)
-        self._history = self._forms = self._title = self._links = None
+        del self._history[:]
+        self._forms = self._title = self._links = None
         self.request = self._response = None
 
     def open(self, url, data=None):
@@ -296,6 +297,8 @@
         """Reload current document, and return response object."""
         if self.request is None:
             raise BrowserStateError("no URL has yet been .open()ed")
+        if self._response is not None:
+            self._response.close()
         return self._mech_open(self.request, update_history=False)
 
     def back(self, n=1):
@@ -306,7 +309,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: wwwsearch/mechanize/trunk/mechanize/_useragent.py
==============================================================================
--- wwwsearch/mechanize/trunk/mechanize/_useragent.py	(original)
+++ wwwsearch/mechanize/trunk/mechanize/_useragent.py	Sat Nov 12 19:31:55 2005
@@ -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: wwwsearch/mechanize/trunk/test.py
==============================================================================
--- wwwsearch/mechanize/trunk/test.py	(original)
+++ wwwsearch/mechanize/trunk/test.py	Sat Nov 12 19:31:55 2005
@@ -175,10 +175,18 @@
         # .geturl() gets fed through to b.response
         self.assertEquals(b.geturl(), "http://example.com/")
         # can go back n times
-        r6 = b.open("http://example.com/spam")
-        r7 = b.open("http://example.com/spam")
+        r6 = b.open("spam")
+        self.assertEquals(b.geturl(), "http://example.com/spam")
+        r7 = b.open("/spam")
+        self.assertEquals(b.geturl(), "http://example.com/spam")
         self.assert_(b.back(2) is r5)
+        self.assertEquals(b.geturl(), "http://example.com/")
         self.assertRaises(mechanize.BrowserStateError, b.back, 2)
+        b.close() # history should work after close
+        r8 = b.open("http://example.com/")
+        r9 = b.open("http://example.com/foo")
+        self.assert_(b.back() is r8)
+        
 
     def test_viewing_html(self):
         # XXX not testing multiple Content-Type headers


More information about the wwwsearch-commits mailing list