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

jjlee at codespeak.net jjlee at codespeak.net
Sat Dec 30 02:15:13 CET 2006


Author: jjlee
Date: Sat Dec 30 02:15:11 2006
New Revision: 36053

Modified:
   wwwsearch/ClientForm/trunk/ClientForm.py
   wwwsearch/ClientForm/trunk/test.py
Log:
Don't allow underlying parser errors (e.g. SGMLParseError) through -- always raise ClientForm.ParseError

Modified: wwwsearch/ClientForm/trunk/ClientForm.py
==============================================================================
--- wwwsearch/ClientForm/trunk/ClientForm.py	(original)
+++ wwwsearch/ClientForm/trunk/ClientForm.py	Sat Dec 30 02:15:11 2006
@@ -765,6 +765,12 @@
             HTMLParser.HTMLParser.__init__(self)
             _AbstractFormParser.__init__(self, entitydefs, encoding)
 
+        def feed(self, data):
+            try:
+                HTMLParser.HTMLParser.feed(self, data)
+            except HTMLParser.HTMLParseError, exc:
+                raise ParseError(exc)
+
         def start_option(self, attrs):
             _AbstractFormParser._start_option(self, attrs)
 
@@ -836,6 +842,13 @@
         sgmllib.SGMLParser.__init__(self)
         _AbstractFormParser.__init__(self, entitydefs, encoding)
 
+    def feed(self, data):
+        try:
+            sgmllib.SGMLParser.feed(self, data)
+        except sgmllib.SGMLParseError, exc:
+            raise ParseError(exc)
+
+
 
 # sigh, must support mechanize by allowing dynamic creation of classes based on
 # its bundled copy of BeautifulSoup (which was necessary because of dependency
@@ -852,6 +865,12 @@
         def handle_data(self, data):
             _AbstractFormParser.handle_data(self, data)
             self.bs_base_class.handle_data(self, data)
+        def feed(self, data):
+            try:
+                self.bs_base_class.feed(self, data)
+            except sgmllib.SGMLParseError, exc:
+                raise ParseError(exc)
+
 
     class RobustFormParser(_AbstractBSFormParser, bs):
         """Tries to be highly tolerant of incorrect HTML."""

Modified: wwwsearch/ClientForm/trunk/test.py
==============================================================================
--- wwwsearch/ClientForm/trunk/test.py	(original)
+++ wwwsearch/ClientForm/trunk/test.py	Sat Dec 30 02:15:11 2006
@@ -222,6 +222,17 @@
         return getattr(self._file, name)
 
 class ParseTests(TestCase):
+
+    def test_failing_parse(self):
+        # XXX couldn't provoke an error from BeautifulSoup (!), so this has not
+        # been tested with RobuststFormParser
+        f = StringIO("<!!!!>")
+        base_uri = "http://localhost/"
+        self.assertRaises(
+            ClientForm.ParseError,
+            ClientForm.ParseFile, f, base_uri, backwards_compat=False,
+            )
+
     def test_unknown_control(self):
         f = StringIO(
 """<form action="abc">
@@ -372,7 +383,9 @@
         self.assert_(len(forms) == 1)
         form = forms[0]
         self.assert_(form.name is None)
-        self.assertEqual(form.action, "http://localhost/abc&amp;"+u"\u2014".encode('utf8')+"d")
+        self.assertEqual(
+            form.action,
+            "http://localhost/abc&amp;"+u"\u2014".encode('utf8')+"d")
         control = form.find_control(type="textarea", nr=0)
         self.assert_(control.name is None)
         self.assert_(control.value == "blah, blah,\r\nRhubarb.\r\n\r\n")


More information about the wwwsearch-commits mailing list