diff options
author | Leonard Richardson <leonard.richardson@canonical.com> | 2012-02-07 19:18:03 -0500 |
---|---|---|
committer | Leonard Richardson <leonard.richardson@canonical.com> | 2012-02-07 19:18:03 -0500 |
commit | b0508df41dbc5a848566c659d8882a772366bb84 (patch) | |
tree | 14174c14e4c09084b542fe1538fe9d2755235fa5 | |
parent | 6590573e18a533f30c9635ecbd6af163d6826ef8 (diff) |
Renamed insert_before to move_before, to avoid confusion with the way insert() works.
-rw-r--r-- | bs4/element.py | 4 | ||||
-rw-r--r-- | bs4/tests/test_tree.py | 24 | ||||
-rw-r--r-- | doc/source/index.rst | 10 |
3 files changed, 19 insertions, 19 deletions
diff --git a/bs4/element.py b/bs4/element.py index 478d285..3ee957f 100644 --- a/bs4/element.py +++ b/bs4/element.py @@ -190,7 +190,7 @@ class PageElement(object): """Appends the given tag to the contents of this tag.""" self.insert(len(self.contents), tag) - def insert_before(self, successor): + def move_before(self, successor): """Makes this element the immediate predecessor of the given element. The two elements will have the same parent, and this element @@ -204,7 +204,7 @@ class PageElement(object): index = parent.index(successor) parent.insert(index, self) - def insert_after(self, predecessor): + def move_after(self, predecessor): """Makes this element the immediate successor of the given element. The two elements will have the same parent, and this element diff --git a/bs4/tests/test_tree.py b/bs4/tests/test_tree.py index a457ddc..fe454d8 100644 --- a/bs4/tests/test_tree.py +++ b/bs4/tests/test_tree.py @@ -678,39 +678,39 @@ class TestTreeModification(SoupTest): soup.br.insert(1, "Contents") self.assertEqual(str(soup.br), "<br>Contents</br>") - def test_insert_before(self): + def test_move_before(self): soup = self.soup("<a>foo</a><b>bar</b>") - soup.new_string("BAZ").insert_before(soup.b) - soup.new_string("QUUX").insert_before(soup.a) + soup.new_string("BAZ").move_before(soup.b) + soup.new_string("QUUX").move_before(soup.a) self.assertEquals( soup.decode(), self.document_for("QUUX<a>foo</a>BAZ<b>bar</b>")) - soup.b.insert_before(soup.a) + soup.b.move_before(soup.a) self.assertEquals( soup.decode(), self.document_for("QUUX<b>bar</b><a>foo</a>BAZ")) - def test_insert_after(self): + def test_move_after(self): soup = self.soup("<a>foo</a><b>bar</b>") - soup.new_string("BAZ").insert_after(soup.b) - soup.new_string("QUUX").insert_after(soup.a) + soup.new_string("BAZ").move_after(soup.b) + soup.new_string("QUUX").move_after(soup.a) self.assertEquals( soup.decode(), self.document_for("<a>foo</a>QUUX<b>bar</b>BAZ")) - soup.a.insert_after(soup.b) + soup.a.move_after(soup.b) self.assertEquals( 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_move_after_raises_valueerror_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, string.move_after, tag) - def test_insert_before_raises_valueerror_if_before_has_no_meaning(self): + def test_move_before_raises_valueerror_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, string.move_before, tag) def test_replace_with(self): soup = self.soup( diff --git a/doc/source/index.rst b/doc/source/index.rst index 8e35f0e..75be6da 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -1516,23 +1516,23 @@ say. It works just like ``.insert()`` on a Python list:: tag.contents # [u'I linked to ', u'but did not endorse', <i>example.com</i>] -``insert_before()`` and ``insert_after()`` +``move_before()`` and ``move_after()`` ------------------------------------------ -The ``insert_before()`` method adds a tag or string to the parse tree +The ``move_before()`` method adds a tag or string to the parse tree immediately before something else:: soup = BeautifulSoup("<b>stop</b>") tag = soup.new_tag("i") tag.string = "Don't" - tag.insert_before(soup.b.string) + tag.move_before(soup.b.string) soup.b # <b><i>Don't</i>stop</b> -The ``insert_after()`` method adds a tag or string to the parse tree +The ``move_after()`` method adds a tag or string to the parse tree immediately `after` something else:: - soup.new_string(" ever ").insert_after(soup.b.i) + soup.new_string(" ever ").move_after(soup.b.i) soup.b # <b><i>Don't</i> ever stop</b> soup.b.contents |