Revision: 6660 Author: nicdumz Date: 2009-04-22 10:47:49 +0000 (Wed, 22 Apr 2009)
Log Message: ----------- Using __import__ instead of exec "import ..." for dynamic imports
Modified Paths: -------------- branches/rewrite/pywikibot/__init__.py branches/rewrite/pywikibot/bot.py branches/rewrite/pywikibot/site.py
Modified: branches/rewrite/pywikibot/__init__.py =================================================================== --- branches/rewrite/pywikibot/__init__.py 2009-04-22 10:00:57 UTC (rev 6659) +++ branches/rewrite/pywikibot/__init__.py 2009-04-22 10:47:49 UTC (rev 6660) @@ -160,7 +160,8 @@ if interface is None: interface = config.site_interface try: - exec "from site import %s as __Site" % interface + tmp = __import__('pywikibot.site', fromlist=[interface]) + __Site = getattr(tmp, interface) except ImportError: raise ValueError("Invalid interface name '%(interface)s'" % locals()) key = '%s:%s:%s' % (fam, code, user)
Modified: branches/rewrite/pywikibot/bot.py =================================================================== --- branches/rewrite/pywikibot/bot.py 2009-04-22 10:00:57 UTC (rev 6659) +++ branches/rewrite/pywikibot/bot.py 2009-04-22 10:47:49 UTC (rev 6660) @@ -51,8 +51,9 @@
# User interface initialization # search for user interface module in the 'userinterfaces' subdirectory -exec ("import pywikibot.userinterfaces.%s_interface as uiModule" - % config.userinterface) +uiModule = __import__("pywikibot.userinterfaces.%s_interface" + % config.userinterface, + fromlist=['UI', 'TerminalHandler'] ) ui = uiModule.UI() TerminalHandler = uiModule.TerminalHandler
@@ -439,7 +440,7 @@
''' % modname try: - exec('import %s as module' % modname) + module = __import__('%s' % modname) helpText = module.__doc__.decode('utf-8') if hasattr(module, 'docuReplacements'): for key, value in module.docuReplacements.iteritems():
Modified: branches/rewrite/pywikibot/site.py =================================================================== --- branches/rewrite/pywikibot/site.py 2009-04-22 10:00:57 UTC (rev 6659) +++ branches/rewrite/pywikibot/site.py 2009-04-22 10:47:49 UTC (rev 6660) @@ -50,12 +50,14 @@ fam = config.family try: # first try the built-in families - exec "import pywikibot.families.%s_family as myfamily" % fam + name = "pywikibot.families.%s_family" % fam + __import__(name) + myfamily = sys.modules[name] except ImportError: # next see if user has defined a local family module try: sys.path.append(config.datafilepath('families')) - exec "import %s_family as myfamily" % fam + myfamily = __import__("%s_family" % fam) except ImportError: if fatal: logger.exception(u"""\