diff options
-rw-r--r-- | CHANGELOG | 3 | ||||
-rw-r--r-- | beautifulsoup/element.py | 11 | ||||
-rw-r--r-- | tests/test_tree.py | 18 |
3 files changed, 18 insertions, 14 deletions
@@ -6,6 +6,9 @@ Methods have been renamed to comply with PEP 8. The old names still work. Here are the renames: * findAll -> find_all + * findNext -> find_next + +== Generators are now properties == The generators have been given more sensible names, and turned into properties: diff --git a/beautifulsoup/element.py b/beautifulsoup/element.py index 80ab7ba..768618e 100644 --- a/beautifulsoup/element.py +++ b/beautifulsoup/element.py @@ -161,10 +161,11 @@ class PageElement: """Appends the given tag to the contents of this tag.""" self.insert(len(self.contents), tag) - def findNext(self, name=None, attrs={}, text=None, **kwargs): + def find_next(self, name=None, attrs={}, text=None, **kwargs): """Returns the first item that matches the given criteria and appears after this Tag in the document.""" return self._findOne(self.find_allNext, name, attrs, text, **kwargs) + findNext = find_next # Compatibility with BS3. def find_allNext(self, name=None, attrs={}, text=None, limit=None, **kwargs): @@ -173,19 +174,19 @@ class PageElement: return self._find_all(name, attrs, text, limit, self.next_elements, **kwargs) - def findNextSibling(self, name=None, attrs={}, text=None, **kwargs): + def find_nextSibling(self, name=None, attrs={}, text=None, **kwargs): """Returns the closest sibling to this Tag that matches the given criteria and appears after this Tag in the document.""" - return self._findOne(self.findNextSiblings, name, attrs, text, + return self._findOne(self.find_nextSiblings, name, attrs, text, **kwargs) - def findNextSiblings(self, name=None, attrs={}, text=None, limit=None, + def find_nextSiblings(self, name=None, attrs={}, text=None, limit=None, **kwargs): """Returns the siblings of this Tag that match the given criteria and appear after this Tag in the document.""" return self._find_all(name, attrs, text, limit, self.next_siblings, **kwargs) - fetchNextSiblings = findNextSiblings # Compatibility with pre-3.x + fetchNextSiblings = find_nextSiblings # Compatibility with BS2 def findPrevious(self, name=None, attrs={}, text=None, **kwargs): """Returns the first item that matches the given criteria and diff --git a/tests/test_tree.py b/tests/test_tree.py index 87bd154..e023cc7 100644 --- a/tests/test_tree.py +++ b/tests/test_tree.py @@ -322,12 +322,12 @@ class TestNextOperations(ProximityTest): self.assertSelects(self.start.find_allNext(id=3), ["Three"]) def test_find_next(self): - self.assertEquals(self.start.findNext('b')['id'], '2') - self.assertEquals(self.start.findNext(text="Three"), "Three") + self.assertEquals(self.start.find_next('b')['id'], '2') + self.assertEquals(self.start.find_next(text="Three"), "Three") def test_find_next_for_text_element(self): text = self.tree.find(text="One") - self.assertEquals(text.findNext("b").string, "Two") + self.assertEquals(text.find_next("b").string, "Two") self.assertSelects(text.find_allNext("b"), ["Two", "Three"]) def test_next_generator(self): @@ -447,13 +447,13 @@ class TestNextSibling(SiblingTest): self.assertEquals(last_span.nextSibling, None) def test_find_next_sibling(self): - self.assertEquals(self.start.findNextSibling('span')['id'], '2') + self.assertEquals(self.start.find_nextSibling('span')['id'], '2') def test_next_siblings(self): - self.assertSelectsIDs(self.start.findNextSiblings("span"), + self.assertSelectsIDs(self.start.find_nextSiblings("span"), ['2', '3', '4']) - self.assertSelectsIDs(self.start.findNextSiblings(id='3'), ['3']) + self.assertSelectsIDs(self.start.find_nextSiblings(id='3'), ['3']) def test_next_sibling_for_text_element(self): soup = self.soup("Foo<b>bar</b>baz") @@ -461,9 +461,9 @@ class TestNextSibling(SiblingTest): self.assertEquals(start.nextSibling.name, 'b') self.assertEquals(start.nextSibling.nextSibling, 'baz') - self.assertSelects(start.findNextSiblings('b'), ['bar']) - self.assertEquals(start.findNextSibling(text="baz"), "baz") - self.assertEquals(start.findNextSibling(text="nonesuch"), None) + self.assertSelects(start.find_nextSiblings('b'), ['bar']) + self.assertEquals(start.find_nextSibling(text="baz"), "baz") + self.assertEquals(start.find_nextSibling(text="nonesuch"), None) class TestPreviousSibling(SiblingTest): |