[wwwsearch-commits] r33622 - wwwsearch/ClientForm/trunk

jjlee at codespeak.net jjlee at codespeak.net
Tue Oct 24 01:35:26 CEST 2006


Author: jjlee
Date: Tue Oct 24 01:35:23 2006
New Revision: 33622

Modified:
   wwwsearch/ClientForm/trunk/ClientForm.py
   wwwsearch/ClientForm/trunk/test.py
Log:
Fix usage of urlunparse to use None instead of empty string for missing fragment, since that's required for RFC 3986 urlunparse (i.e. when mechanize passes mechanize._rfc3986.urlunparse as _urlunparse parameter).  Note the test added here passed before this change; the real test is (will be, in a minute or two) in mechanize.

Modified: wwwsearch/ClientForm/trunk/ClientForm.py
==============================================================================
--- wwwsearch/ClientForm/trunk/ClientForm.py	(original)
+++ wwwsearch/ClientForm/trunk/ClientForm.py	Tue Oct 24 01:35:23 2006
@@ -1444,7 +1444,7 @@
         # Submission of ISINDEX is explained in the HTML 3.2 spec, though.
         parts = self._urlparse(form.action)
         rest, (query, frag) = parts[:-2], parts[-2:]
-        parts = rest + (urllib.quote_plus(self.value), "")
+        parts = rest + (urllib.quote_plus(self.value), None)
         url = self._urlunparse(parts)
         req_data = url, None, []
 
@@ -3239,11 +3239,11 @@
             if self.enctype != "application/x-www-form-urlencoded":
                 raise ValueError(
                     "unknown GET form encoding type '%s'" % self.enctype)
-            parts = rest + (urlencode(self._pairs()), "")
+            parts = rest + (urlencode(self._pairs()), None)
             uri = self._urlunparse(parts)
             return uri, None, []
         elif method == "POST":
-            parts = rest + (query, "")
+            parts = rest + (query, None)
             uri = self._urlunparse(parts)
             if self.enctype == "application/x-www-form-urlencoded":
                 return (uri, urlencode(self._pairs()),

Modified: wwwsearch/ClientForm/trunk/test.py
==============================================================================
--- wwwsearch/ClientForm/trunk/test.py	(original)
+++ wwwsearch/ClientForm/trunk/test.py	Tue Oct 24 01:35:23 2006
@@ -3036,6 +3036,26 @@
             self.assertEqual(bar.value, [])
             self.assertEqual(form.click_pairs(), [])
 
+    def test_action_with_fragment(self):
+        for method in ["GET", "POST"]:
+            data = ('<form action="" method="%s">'
+                    '<input type="submit" name="s"/></form>' % method
+                    )
+            f = StringIO(data)
+            form = ClientForm.ParseFile(f, "http://example.com/",
+                                        backwards_compat=False)[0]
+            self.assertEqual(
+                form.click().get_full_url(),
+                "http://example.com/"+(method=="GET" and "?s=" or ""),
+                )
+        data = '<form action=""><isindex /></form>'
+        f = StringIO(data)
+        form = ClientForm.ParseFile(f, "http://example.com/",
+                                    backwards_compat=False)[0]
+        form.find_control(type="isindex").value = "blah"
+        self.assertEqual(form.click(type="isindex").get_full_url(),
+                         "http://example.com/?blah")
+
 
 class ContentTypeTests(TestCase):
     def test_content_type(self):


More information about the wwwsearch-commits mailing list