[Zope3-checkins] SVN: Zope3/trunk/src/zope/testbrowser/ Fix some
bugs in mechanize.
Stephan Richter
srichter at cosmos.phy.tufts.edu
Fri Oct 28 12:20:58 EDT 2005
Log message for revision 39691:
Fix some bugs in mechanize.
Changed:
A Zope3/trunk/src/zope/testbrowser/BUGFIXES.txt
U Zope3/trunk/src/zope/testbrowser/mechanize/_mechanize.py
-=-
Added: Zope3/trunk/src/zope/testbrowser/BUGFIXES.txt
===================================================================
--- Zope3/trunk/src/zope/testbrowser/BUGFIXES.txt 2005-10-28 14:44:39 UTC (rev 39690)
+++ Zope3/trunk/src/zope/testbrowser/BUGFIXES.txt 2005-10-28 16:20:57 UTC (rev 39691)
@@ -0,0 +1,31 @@
+===================
+Mechanize Bug Fixes
+===================
+
+This file contains bug fixes to the mechanize framework that have not yet been
+reported to mechanize authors.
+
+``mechanize``
+-------------
+
+- The ``Browser.close()`` method fails to close the current response using
+ ``Browser._response.close()``. If you are opening a lot of pages, then you
+ will end up witha "too many files opnened" error eventually.
+
+- The ``update_history`` argument of ``Browser._mech_open()`` was unused.
+
+- In the ``Browser.close()`` method, the ``Browser._history`` attribute is set
+ to ``None``, but is should be ``[]`` (an empty list).
+
+- Related to the entry above, when the history is reset, none of the stored
+ responses is closed.
+
+- Due to the poor design of the history implementation, you can still get "too
+ many files opened" if you use the rest of the ``Browser`` API. The ideal
+ solution would be to close the previous response just before you use
+ ``Browser._mech_open()``. In fact this method should be responsible of the
+ cleanup.
+
+- URLs that are retrieved using pullparser might be unclean, meaning they
+ might contain leading and trailing whitespace. The ``Link`` class should
+ thus strip the base and link url.
Property changes on: Zope3/trunk/src/zope/testbrowser/BUGFIXES.txt
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: Zope3/trunk/src/zope/testbrowser/mechanize/_mechanize.py
===================================================================
--- Zope3/trunk/src/zope/testbrowser/mechanize/_mechanize.py 2005-10-28 14:44:39 UTC (rev 39690)
+++ Zope3/trunk/src/zope/testbrowser/mechanize/_mechanize.py 2005-10-28 16:20:57 UTC (rev 39691)
@@ -51,6 +51,8 @@
class Link:
def __init__(self, base_url, url, text, tag, attrs):
assert None not in [url, tag, attrs]
+ url = url.strip()
+ base_url = base_url.strip()
self.base_url = base_url
self.absolute_url = urlparse.urljoin(base_url, url)
self.url, self.text, self.tag, self.attrs = url, text, tag, attrs
@@ -96,17 +98,23 @@
self._history = [] # LIFO
self.request = self._response = None
self.form = None
- self._forms = None
- self._title = None
- self._links = None
+ self._forms = self._title = self._links = None
UserAgent.__init__(self) # do this last to avoid __getattr__ problems
def close(self):
UserAgent.close(self)
- self._history = self._forms = self._title = self._links = None
+ if self._response:
+ self._response.close()
self.request = self._response = None
+ self.form = None
+ [response.close()
+ for request, response in self._history
+ if response is not None]
+ self._history = []
+ self._forms = self._title = self._links = None
- def open(self, url, data=None): return self._mech_open(url, data)
+ def open(self, url, data=None):
+ return self._mech_open(url, data)
def _mech_open(self, url, data=None, update_history=True):
if not hasattr(url, 'get_full_url'):
@@ -120,8 +128,6 @@
"can't fetch relative URL: not viewing any document")
url = urlparse.urljoin(self._response.geturl(), url)
- if self.request is not None:
- self._history.append((self.request, self._response))
self._response = None
# we want self.request to be assigned even if OpenerDirector.open fails
self.request = self._request(url, data)
@@ -133,6 +139,9 @@
self._response = response_seek_wrapper(self._response)
self._parse_html(self._response)
+ if (self.request is not None) and update_history:
+ self._history.append((self.request, self._response))
+
return self._response
def response(self):
More information about the Zope3-Checkins
mailing list