summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bs4/__init__.py8
-rw-r--r--bs4/doc/source/index.rst10
-rw-r--r--bs4/element.py4
-rw-r--r--bs4/tests/test_tree.py28
4 files changed, 25 insertions, 25 deletions
diff --git a/bs4/__init__.py b/bs4/__init__.py
index ea6dd25..e6ad425 100644
--- a/bs4/__init__.py
+++ b/bs4/__init__.py
@@ -203,11 +203,11 @@ class BeautifulSoup(Tag):
navigable.setup()
return navigable
- def move_before(self, successor):
- raise ValueError("BeautifulSoup objects don't support move_before().")
+ def insert_before(self, successor):
+ raise ValueError("BeautifulSoup objects don't support insert_before().")
- def move_after(self, successor):
- raise ValueError("BeautifulSoup objects don't support move_after().")
+ def insert_after(self, successor):
+ raise ValueError("BeautifulSoup objects don't support insert_after().")
def popTag(self):
tag = self.tagStack.pop()
diff --git a/bs4/doc/source/index.rst b/bs4/doc/source/index.rst
index ad1dbf7..3cf96f0 100644
--- a/bs4/doc/source/index.rst
+++ b/bs4/doc/source/index.rst
@@ -1525,23 +1525,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>]
-``move_before()`` and ``move_after()``
+``insert_before()`` and ``insert_after()``
------------------------------------------
-The ``move_before()`` method moves a tag or string so that it
+The ``insert_before()`` method moves a tag or string so that it
immediately precedes something else in the parse tree::
soup = BeautifulSoup("<b>stop</b>")
tag = soup.new_tag("i")
tag.string = "Don't"
- tag.move_before(soup.b.string)
+ tag.insert_before(soup.b.string)
soup.b
# <b><i>Don't</i>stop</b>
-The ``move_after()`` method moves a tag or string so that it
+The ``insert_after()`` method moves a tag or string so that it
immediately follows something else in the parse tree::
- soup.new_string(" ever ").move_after(soup.b.i)
+ soup.new_string(" ever ").insert_after(soup.b.i)
soup.b
# <b><i>Don't</i> ever stop</b>
soup.b.contents
diff --git a/bs4/element.py b/bs4/element.py
index 3ee957f..478d285 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 move_before(self, successor):
+ def insert_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 move_after(self, predecessor):
+ def insert_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 692260c..1d6d612 100644
--- a/bs4/tests/test_tree.py
+++ b/bs4/tests/test_tree.py
@@ -702,43 +702,43 @@ class TestTreeModification(SoupTest):
soup.br.insert(1, "Contents")
self.assertEqual(str(soup.br), "<br>Contents</br>")
- def test_move_before(self):
+ def test_insert_before(self):
soup = self.soup("<a>foo</a><b>bar</b>")
- soup.new_string("BAZ").move_before(soup.b)
- soup.new_string("QUUX").move_before(soup.a)
+ soup.new_string("BAZ").insert_before(soup.b)
+ soup.new_string("QUUX").insert_before(soup.a)
self.assertEqual(
soup.decode(), self.document_for("QUUX<a>foo</a>BAZ<b>bar</b>"))
- soup.b.move_before(soup.a)
+ soup.b.insert_before(soup.a)
self.assertEqual(
soup.decode(), self.document_for("QUUX<b>bar</b><a>foo</a>BAZ"))
- def test_move_after(self):
+ def test_insert_after(self):
soup = self.soup("<a>foo</a><b>bar</b>")
- soup.new_string("BAZ").move_after(soup.b)
- soup.new_string("QUUX").move_after(soup.a)
+ soup.new_string("BAZ").insert_after(soup.b)
+ soup.new_string("QUUX").insert_after(soup.a)
self.assertEqual(
soup.decode(), self.document_for("<a>foo</a>QUUX<b>bar</b>BAZ"))
- soup.a.move_after(soup.b)
+ soup.a.insert_after(soup.b)
self.assertEqual(
soup.decode(), self.document_for("QUUX<b>bar</b><a>foo</a>BAZ"))
- def test_move_after_raises_valueerror_if_after_has_no_meaning(self):
+ def test_insert_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.move_after, tag)
+ self.assertRaises(ValueError, string.insert_after, tag)
- self.assertRaises(ValueError, soup.move_after, tag)
+ self.assertRaises(ValueError, soup.insert_after, tag)
- def test_move_before_raises_valueerror_if_before_has_no_meaning(self):
+ def test_insert_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.move_before, tag)
+ self.assertRaises(ValueError, string.insert_before, tag)
- self.assertRaises(ValueError, soup.move_before, tag)
+ self.assertRaises(ValueError, soup.insert_before, tag)
def test_replace_with(self):
soup = self.soup(