summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS.txt7
-rw-r--r--bs4/__init__.py2
-rw-r--r--bs4/element.py7
-rw-r--r--bs4/tests/test_tree.py6
4 files changed, 20 insertions, 2 deletions
diff --git a/NEWS.txt b/NEWS.txt
index 02ff7a8..440869c 100644
--- a/NEWS.txt
+++ b/NEWS.txt
@@ -1,4 +1,9 @@
-= 4.2.1 (Unreleased) =
+= 4.3.0 (Unreleased) =
+
+* A NavigableString object now has an immutable '.name' property whose
+ value is always None. This makes it easier to iterate over a mixed
+ list of tags and strings without having to check whether each
+ element is a tag or a string.
* Gave new_string() the ability to create subclasses of
NavigableString. [bug=1181986]
diff --git a/bs4/__init__.py b/bs4/__init__.py
index 03b2416..a949d6d 100644
--- a/bs4/__init__.py
+++ b/bs4/__init__.py
@@ -17,7 +17,7 @@ http://www.crummy.com/software/BeautifulSoup/bs4/doc/
"""
__author__ = "Leonard Richardson (leonardr@segfault.org)"
-__version__ = "4.2.1"
+__version__ = "4.3.0"
__copyright__ = "Copyright (c) 2004-2013 Leonard Richardson"
__license__ = "MIT"
diff --git a/bs4/element.py b/bs4/element.py
index f6864f2..538f6b6 100644
--- a/bs4/element.py
+++ b/bs4/element.py
@@ -672,6 +672,13 @@ class NavigableString(unicode, PageElement):
output = self.format_string(self, formatter)
return self.PREFIX + output + self.SUFFIX
+ @property
+ def name(self):
+ return None
+
+ @name.setter
+ def name(self, name):
+ raise AttributeError("A NavigableString cannot be given a name.")
class PreformattedString(NavigableString):
"""A NavigableString not subject to the normal formatting rules.
diff --git a/bs4/tests/test_tree.py b/bs4/tests/test_tree.py
index c39b3f7..fc0e2c6 100644
--- a/bs4/tests/test_tree.py
+++ b/bs4/tests/test_tree.py
@@ -1187,6 +1187,12 @@ class TestElementObjects(SoupTest):
soup = self.soup("foo<!--IGNORE-->bar")
self.assertEqual(['foo', 'bar'], list(soup.strings))
+ def test_string_has_immutable_name_property(self):
+ string = self.soup("s").string
+ self.assertEqual(None, string.name)
+ def t():
+ string.name = 'foo'
+ self.assertRaises(AttributeError, t)
class TestCDAtaListAttributes(SoupTest):