diff options
-rw-r--r-- | bs4/diagnose.py | 2 | ||||
-rw-r--r-- | bs4/element.py | 7 | ||||
-rw-r--r-- | bs4/tests/test_tree.py | 6 |
3 files changed, 14 insertions, 1 deletions
diff --git a/bs4/diagnose.py b/bs4/diagnose.py index 7c7ea7a..df72f65 100644 --- a/bs4/diagnose.py +++ b/bs4/diagnose.py @@ -202,5 +202,5 @@ def profile(num_elements=100000, parser="lxml"): if __name__ == '__main__': #diagnose(sys.stdin.read()) - profile(10000, parser="html5lib") + profile(100000, parser="lxml") # benchmark_parsers() diff --git a/bs4/element.py b/bs4/element.py index 742624d..f248895 100644 --- a/bs4/element.py +++ b/bs4/element.py @@ -674,6 +674,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 2d09f96..0acc092 100644 --- a/bs4/tests/test_tree.py +++ b/bs4/tests/test_tree.py @@ -1219,6 +1219,12 @@ class TestCDAtaListAttributes(SoupTest): # attribute for any other tag. self.assertEqual('ISO-8859-1 UTF-8', soup.a['accept-charset']) + 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 TestPersistence(SoupTest): "Testing features like pickle and deepcopy." |