summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeonard Richardson <leonard.richardson@canonical.com>2011-02-28 12:25:51 -0500
committerLeonard Richardson <leonard.richardson@canonical.com>2011-02-28 12:25:51 -0500
commit5c7ff8e02ac0a2fe2966b04cb6862940face28c0 (patch)
tree3b832c107233b60e57c8199a8141d6fe7738073d
parent270cc37956de4ed1c4025b0d56aaf34a75d080d5 (diff)
Renamed replaceWith to replace_with.
-rw-r--r--CHANGELOG1
-rw-r--r--TODO5
-rw-r--r--bs4/element.py8
-rw-r--r--tests/test_tree.py8
4 files changed, 14 insertions, 8 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 6d05ae4..00d80da 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -22,6 +22,7 @@ version of the API is in use, the module is now called 'bs4':
Methods have been renamed to comply with PEP 8. The old names still
work. Here are the renames:
+ * replaceWith -> replace_with
* findAll -> find_all
* findAllNext -> find_all_next
* findAllPrevious -> find_all_previous
diff --git a/TODO b/TODO
index a6f444f..a876494 100644
--- a/TODO
+++ b/TODO
@@ -1,3 +1,8 @@
+define a setter for Tag.string which replaces the tag's contents with
+a string.
+
+Tag.text: concatenate all strings and return them
+
Bare ampersands should be converted to HTML entities upon output.
Add namespace support.
diff --git a/bs4/element.py b/bs4/element.py
index 315ee63..f75145c 100644
--- a/bs4/element.py
+++ b/bs4/element.py
@@ -27,19 +27,19 @@ class PageElement(object):
self.previousSibling = self.parent.contents[-1]
self.previousSibling.nextSibling = self
- def replaceWith(self, replaceWith):
+ def replace_with(self, replaceWith):
oldParent = self.parent
myIndex = self.parent.contents.index(self)
- if hasattr(replaceWith, 'parent') and replaceWith.parent == self.parent:
+ if hasattr(replace_with, 'parent') and replaceWith.parent == self.parent:
# We're replacing this element with one of its siblings.
- index = self.parent.contents.index(replaceWith)
+ index = self.parent.contents.index(replace_with)
if index and index < myIndex:
# Furthermore, it comes before this element. That
# means that when we extract it, the index of this
# element will change.
myIndex = myIndex - 1
self.extract()
- oldParent.insert(myIndex, replaceWith)
+ oldParent.insert(myIndex, replace_with)
def extract(self):
"""Destructively rips this element out of the tree."""
diff --git a/tests/test_tree.py b/tests/test_tree.py
index c61b326..f2989fe 100644
--- a/tests/test_tree.py
+++ b/tests/test_tree.py
@@ -557,12 +557,12 @@ class TestTreeModification(SoupTest):
text = "<a><b></b><c>Foo<d></d></c></a><a><e></e></a>"
soup = self.soup(text)
c = soup.c
- soup.c.replaceWith(c)
+ soup.c.replace_with(c)
self.assertEquals(soup.decode(), self.document_for(text))
def test_replace_final_node(self):
soup = self.soup("<b>Argh!</b>")
- soup.find(text="Argh!").replaceWith("Hooray!")
+ soup.find(text="Argh!").replace_with("Hooray!")
new_text = soup.find(text="Hooray!")
b = soup.b
self.assertEqual(new_text.previous, b)
@@ -635,7 +635,7 @@ class TestTreeModification(SoupTest):
soup = self.soup(
"<p>There's <b>no</b> business like <b>show</b> business</p>")
no, show = soup.find_all('b')
- show.replaceWith(no)
+ show.replace_with(no)
self.assertEquals(
soup.decode(),
self.document_for(
@@ -654,7 +654,7 @@ class TestTreeModification(SoupTest):
# right") with the <f> tag ("refuse").
remove_tag = soup.b
move_tag = soup.f
- remove_tag.replaceWith(move_tag)
+ remove_tag.replace_with(move_tag)
self.assertEqual(
soup.decode(), self.document_for(