diff options
author | Leonard Richardson <leonardr@segfault.org> | 2012-08-20 14:10:29 -0400 |
---|---|---|
committer | Leonard Richardson <leonardr@segfault.org> | 2012-08-20 14:10:29 -0400 |
commit | 0f1e8f4a18ea9e48bc05abdb0a0eb2a75c46f714 (patch) | |
tree | 9df818fd3afe7c135fc3ffc9204508ca02f6e3e8 | |
parent | 84088ed20f516366b272e05f7f7ccd55c446c178 (diff) |
Raise a more specific error (FeatureNotFound) when a requested
parser or parser feature is not installed. Raise NotImplementedError
instead of ValueError when the user calls insert_before() or
insert_after() on the BeautifulSoup object itself. Patch by Aaron
Devore. [bug=1038301]
-rw-r--r-- | NEWS.txt | 6 | ||||
-rw-r--r-- | bs4/__init__.py | 10 | ||||
-rw-r--r-- | bs4/tests/test_tree.py | 8 |
3 files changed, 16 insertions, 8 deletions
@@ -2,7 +2,11 @@ * Skipped a test under Python 2.6 to avoid a spurious test failure. [bug=1038503] -* +* Raise a more specific error (FeatureNotFound) when a requested + parser or parser feature is not installed. Raise NotImplementedError + instead of ValueError when the user calls insert_before() or + insert_after() on the BeautifulSoup object itself. Patch by Aaron + Devore. [bug=1038301] = 4.1.2 (20120817) = diff --git a/bs4/__init__.py b/bs4/__init__.py index 64f8df9..23afa91 100644 --- a/bs4/__init__.py +++ b/bs4/__init__.py @@ -149,7 +149,7 @@ class BeautifulSoup(Tag): features = self.DEFAULT_BUILDER_FEATURES builder_class = builder_registry.lookup(*features) if builder_class is None: - raise ValueError( + raise FeatureNotFound( "Couldn't find a tree builder with the features you " "requested: %s. Do you need to install a parser library?" % ",".join(features)) @@ -208,10 +208,10 @@ class BeautifulSoup(Tag): return navigable def insert_before(self, successor): - raise ValueError("BeautifulSoup objects don't support insert_before().") + raise NotImplementedError("BeautifulSoup objects don't support insert_before().") def insert_after(self, successor): - raise ValueError("BeautifulSoup objects don't support insert_after().") + raise NotImplementedError("BeautifulSoup objects don't support insert_after().") def popTag(self): tag = self.tagStack.pop() @@ -348,6 +348,10 @@ class StopParsing(Exception): pass +class FeatureNotFound(ValueError): + pass + + #By default, act as an HTML pretty-printer. if __name__ == '__main__': import sys diff --git a/bs4/tests/test_tree.py b/bs4/tests/test_tree.py index 9397f24..5f3395b 100644 --- a/bs4/tests/test_tree.py +++ b/bs4/tests/test_tree.py @@ -886,20 +886,20 @@ class TestTreeModification(SoupTest): self.assertEqual( soup.decode(), self.document_for("QUUX<b>bar</b><a>foo</a>BAZ")) - def test_insert_after_raises_valueerror_if_after_has_no_meaning(self): + def test_insert_after_raises_exception_if_after_has_no_meaning(self): soup = self.soup("") tag = soup.new_tag("a") string = soup.new_string("") self.assertRaises(ValueError, string.insert_after, tag) - self.assertRaises(ValueError, soup.insert_after, tag) + self.assertRaises(NotImplementedError, soup.insert_after, tag) self.assertRaises(ValueError, tag.insert_after, tag) - def test_insert_before_raises_valueerror_if_before_has_no_meaning(self): + def test_insert_before_raises_notimplementederror_if_before_has_no_meaning(self): soup = self.soup("") tag = soup.new_tag("a") string = soup.new_string("") self.assertRaises(ValueError, string.insert_before, tag) - self.assertRaises(ValueError, soup.insert_before, tag) + self.assertRaises(NotImplementedError, soup.insert_before, tag) self.assertRaises(ValueError, tag.insert_before, tag) def test_replace_with(self): |