From 032b5f464198b27d6163696484314ce19e7083e1 Mon Sep 17 00:00:00 2001 From: Leonard Richardson Date: Sun, 20 Feb 2011 15:44:16 -0500 Subject: Greatly simplified the module import code by making it take a module, not a module name. --- beautifulsoup/builder/__init__.py | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) (limited to 'beautifulsoup/builder/__init__.py') diff --git a/beautifulsoup/builder/__init__.py b/beautifulsoup/builder/__init__.py index 3983d66..1ece168 100644 --- a/beautifulsoup/builder/__init__.py +++ b/beautifulsoup/builder/__init__.py @@ -165,19 +165,8 @@ class HTMLTreeBuilder(TreeBuilder): return False -def register_builders_from(module_name, add_to_all, - local_to_this_package=False): - # I'm sure this is not the best way to do this. - - # Import the module beautifulsoup.builder.foo or some.other.builder.foo - if local_to_this_package: - fqn = __package__ + '.' + module_name - else: - fqn = module_name - __import__(fqn) - - # Look up the module by its fully-qualified name. - module = sys.modules[fqn] +def register_builders_from(module, add_to_all) + # 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. @@ -188,5 +177,7 @@ def register_builders_from(module_name, add_to_all, # Add all names from the builder module's __all__ to these names. add_to_all += module.__all__ -register_builders_from('_lxml', __all__, True) -register_builders_from('_html5lib', __all__, True) +import _lxml +register_builders_from(_lxml, __all__) +import html5lib +register_builders_from(_html5lib, __all__) -- cgit v1.2.3