diff options
-rw-r--r-- | NEWS.txt | 3 | ||||
-rw-r--r-- | bs4/__init__.py | 10 | ||||
-rw-r--r-- | bs4/tests/test_lxml.py | 13 | ||||
-rw-r--r-- | bs4/tests/test_soup.py | 11 |
4 files changed, 35 insertions, 2 deletions
@@ -5,6 +5,9 @@ * In HTML5-style <meta charset="foo"> tags, the value of the "charset" attribute is now replaced with the appropriate encoding on output. +* For backwards compatibility, brought back the BeautifulStoneSoup + class as a deprecated wrapper around BeautifulSoup. + = 4.0.0b9 (20110228) = * Fixed the string representation of DOCTYPEs that have both a public diff --git a/bs4/__init__.py b/bs4/__init__.py index 7a36493..c66cc65 100644 --- a/bs4/__init__.py +++ b/bs4/__init__.py @@ -329,6 +329,16 @@ class BeautifulSoup(Tag): return prefix + super(BeautifulSoup, self).decode( indent_level, eventual_encoding, formatter) +class BeautifulStoneSoup(BeautifulSoup): + """Deprecated interface to an XML parser.""" + + def __init__(self, *args, **kwargs): + kwargs['features'] = 'xml' + warnings.warn( + 'The BeautifulStoneSoup class is deprecated. Instead of using ' + 'it, pass features="xml" into the BeautifulSoup constructor.') + super(BeautifulStoneSoup, self).__init__(*args, **kwargs) + class StopParsing(Exception): pass diff --git a/bs4/tests/test_lxml.py b/bs4/tests/test_lxml.py index 27ec570..4e0b12e 100644 --- a/bs4/tests/test_lxml.py +++ b/bs4/tests/test_lxml.py @@ -1,6 +1,7 @@ """Tests to ensure that the lxml tree builder generates good trees.""" import re +import warnings try: from bs4.builder import LXMLTreeBuilder, LXMLTreeBuilderForXML @@ -8,7 +9,10 @@ try: except ImportError, e: LXML_PRESENT = False -from bs4 import BeautifulSoup +from bs4 import ( + BeautifulSoup, + BeautifulStoneSoup, + ) from bs4.element import Comment, Doctype, SoupStrainer from bs4.testing import skipIf from bs4.tests import test_htmlparser @@ -37,6 +41,13 @@ class LXMLTreeBuilderSmokeTest(SoupTest, HTMLTreeBuilderSmokeTest): self.assertSoupEquals( "<p>foo�bar</p>", "<p>foobar</p>") + def test_beautifulstonesoup_is_xml_parser(self): + # Make sure that the deprecated BSS class uses an xml builder + # if one is installed. + with warnings.catch_warnings(record=False) as w: + soup = BeautifulStoneSoup("<b />") + self.assertEqual(u"<b/>", unicode(soup.b)) + @skipIf( not LXML_PRESENT, "lxml seems not to be present, not testing its XML tree builder.") diff --git a/bs4/tests/test_soup.py b/bs4/tests/test_soup.py index 10a7e55..d826b25 100644 --- a/bs4/tests/test_soup.py +++ b/bs4/tests/test_soup.py @@ -2,7 +2,10 @@ """Tests of Beautiful Soup as a whole.""" import unittest -from bs4 import BeautifulSoup +from bs4 import ( + BeautifulSoup, + BeautifulStoneSoup, +) from bs4.element import ( SoupStrainer, NamespacedAttribute, @@ -44,6 +47,12 @@ class TestDeprecatedConstructorArguments(SoupTest): self.assertRaises( TypeError, self.soup, "<a>", no_such_argument=True) + def test_beautifulstonesoup(self): + with warnings.catch_warnings(record=True) as w: + soup = BeautifulStoneSoup("<markup>") + self.assertTrue(isinstance(soup, BeautifulSoup)) + self.assertTrue("BeautifulStoneSoup class is deprecated") + class TestSelectiveParsing(SoupTest): def test_parse_with_soupstrainer(self): |