diff options
author | Leonard Richardson <leonardr@segfault.org> | 2015-06-25 20:53:13 -0400 |
---|---|---|
committer | Leonard Richardson <leonardr@segfault.org> | 2015-06-25 20:53:13 -0400 |
commit | 0b9b0976b5219233bee143c09a3f35fc2a44d20e (patch) | |
tree | df6061527e52417c035b9eb72bd41962df1c3a44 /bs4 | |
parent | fdc2bf6d1490d536fb583986b40a34f80ed5a0bc (diff) |
You can now create a NavigableString or a subclass just by invoking
the constructor. [bug=1294315]
Diffstat (limited to 'bs4')
-rw-r--r-- | bs4/__init__.py | 4 | ||||
-rw-r--r-- | bs4/element.py | 6 |
2 files changed, 5 insertions, 5 deletions
diff --git a/bs4/__init__.py b/bs4/__init__.py index c78c54e..4b92152 100644 --- a/bs4/__init__.py +++ b/bs4/__init__.py @@ -241,9 +241,7 @@ class BeautifulSoup(Tag): def new_string(self, s, subclass=NavigableString): """Create a new NavigableString associated with this soup.""" - navigable = subclass(s) - navigable.setup() - return navigable + return subclass(s) def insert_before(self, successor): raise NotImplementedError("BeautifulSoup objects don't support insert_before().") diff --git a/bs4/element.py b/bs4/element.py index 2ea68b3..7fdeb08 100644 --- a/bs4/element.py +++ b/bs4/element.py @@ -674,9 +674,11 @@ class NavigableString(unicode, PageElement): how to handle non-ASCII characters. """ if isinstance(value, unicode): - return unicode.__new__(cls, value) - u = unicode.__new__(cls, value, DEFAULT_OUTPUT_ENCODING) + u = unicode.__new__(cls, value) + else: + u = unicode.__new__(cls, value, DEFAULT_OUTPUT_ENCODING) u.setup() + return u def __copy__(self): return self |