summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--beautifulsoup/builder/__init__.py21
-rw-r--r--tests/test_lxml.py18
2 files changed, 29 insertions, 10 deletions
diff --git a/beautifulsoup/builder/__init__.py b/beautifulsoup/builder/__init__.py
index d6c750c..5e55f7f 100644
--- a/beautifulsoup/builder/__init__.py
+++ b/beautifulsoup/builder/__init__.py
@@ -1,4 +1,5 @@
import re
+import sys
from beautifulsoup.element import Entities
__all__ = [
@@ -163,5 +164,21 @@ class HTMLTreeBuilder(TreeBuilder):
pass
return False
-from _lxml import *
-from _html5lib import *
+
+def register_builders_from(module):
+ # I'm fairly sure this is not the best way to do this.
+
+ # Copy everything mentioned in the builder module's __all__ into
+ # this module.
+ this_module = sys.modules[__package__]
+ for name in module.__all__:
+ setattr(this_module, name, getattr(module, name))
+
+ # Add all names from the builder module's __all__ to this module's
+ # __all__.
+ this_module.__all__ += module.__all__
+
+import _lxml
+register_builders_from(_lxml)
+import _html5lib
+register_builders_from(_html5lib)
diff --git a/tests/test_lxml.py b/tests/test_lxml.py
index de2ce7b..9d08aef 100644
--- a/tests/test_lxml.py
+++ b/tests/test_lxml.py
@@ -9,14 +9,16 @@ from beautifulsoup.testing import SoupTest
class TestLXMLBuilder(SoupTest):
- """A smoke test for the LXML tree builders.
-
- Subclass this to test some other tree builder. Subclasses of this
- test ensure that all of Beautiful Soup's tree builders generate
- more or less the same trees. It's okay for trees to differ--just
- override the appropriate test method to demonstrate how one tree
- builder differs from the LXML builder. But in general, all tree
- builders should generate trees that make most of these tests pass.
+ """A smoke test for the LXML tree builder.
+
+ Subclass this to test some other HTML tree builder. Subclasses of
+ this test ensure that all of Beautiful Soup's tree builders
+ generate more or less the same trees.
+
+ It's okay for trees to differ--just override the appropriate test
+ method to demonstrate how one tree builder differs from the LXML
+ builder. But in general, all HTML tree builders should generate
+ trees that make most of these tests pass.
"""
def test_bare_string(self):