From 0dcb2c0eca6c348718ff29a0747ca605316610a8 Mon Sep 17 00:00:00 2001 From: Leonard Richardson Date: Thu, 10 Feb 2011 09:47:47 -0500 Subject: Fixed the ability to encode strings. --- beautifulsoup/element.py | 3 --- tests/test_tree.py | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/beautifulsoup/element.py b/beautifulsoup/element.py index bd9bcbf..7ecd482 100644 --- a/beautifulsoup/element.py +++ b/beautifulsoup/element.py @@ -346,9 +346,6 @@ class NavigableString(unicode, PageElement): else: raise AttributeError, "'%s' object has no attribute '%s'" % (self.__class__.__name__, attr) - def encode(self, encoding=DEFAULT_OUTPUT_ENCODING): - return self.decode().encode(encoding) - def decodeGivenEventualEncoding(self, eventualEncoding): return self diff --git a/tests/test_tree.py b/tests/test_tree.py index eac4e72..ed29d76 100644 --- a/tests/test_tree.py +++ b/tests/test_tree.py @@ -815,3 +815,19 @@ class TestPersistence(SoupTest): dumped = pickle.dumps(soup, pickle.HIGHEST_PROTOCOL) loaded = pickle.loads(dumped) self.assertEqual(loaded.decode(), soup.decode()) + + +class TestEncoding(SoupTest): + """Test the ability to encode strings.""" + + def test_unicode_string_can_be_encoded(self): + html = u"\N{SNOWMAN}" + soup = self.soup(html) + self.assertEquals(soup.b.string.encode("utf-8"), + u"\N{SNOWMAN}".encode("utf-8")) + + def test_tag_containing_unicode_string_can_be_encoded(self): + html = u"\N{SNOWMAN}" + soup = self.soup(html) + self.assertEquals(soup.b.encode("utf-8"), + html.encode("utf-8")) -- cgit v1.2.3