[twill] 0.7.3, assume html patch

James Cameron james.cameron at hp.com
Wed Oct 26 21:43:50 PDT 2005


G'day Titus,

The web server was consistently failing to send a Content-Type if twill
was used to query it during evening hours.  The debug http confirmed it.

Apparently some browsers assume it is text/html and proceed regardless.

The attached patch adds an assume_html() method to mechanize.  I know
you'd rather not take patches for something that is upstream of you, but
I thought I'd mention how it was solved in the end.  I could not find a
way to solve it without this change.

-- 
James Cameron
http://ftp.hp.com.au/sigs/jc/
-------------- next part --------------
--- twill/mechanize/_mechanize.py.orig	2005-10-25 10:24:25.000000000 +1000
+++ twill/mechanize/_mechanize.py	2005-10-25 10:43:40.000000000 +1000
@@ -160,6 +160,7 @@
         self._history = []  # LIFO
         self.request = self._response = None
         self.form = None
+        self.force_html = False
         self._forms = None
         self._title = None
         self._links = None
@@ -274,9 +275,15 @@
         """Return whether the current response contains HTML data."""
         if self._response is None:
             raise BrowserStateError("not viewing any document")
+        if self.force_html:
+            print "viewing_html: forcing html"
+            return True
         ct = self._response.info().getheaders("content-type")
         return ct and ct[0].startswith("text/html")
 
+    def assume_html(self):
+        self.force_html = True
+
     def title(self):
         """Return title, or None if there is no title element in the document.
 


More information about the twill mailing list