Added utils.python.universalImport to make the previous idiom cleaner.

This commit is contained in:
Jeremy Fincher 2009-03-09 15:13:16 -05:00 committed by James Vega
parent d6ad5b051f
commit a86b4694d7
2 changed files with 13 additions and 0 deletions

View File

@ -40,6 +40,7 @@ import supybot.utils as utils
from supybot.commands import * from supybot.commands import *
import supybot.callbacks as callbacks import supybot.callbacks as callbacks
convertcore = utils.python.universalImport('convertcore', 'our_convertcore')
try: try:
import convertcore import convertcore
except ImportError: except ImportError:

View File

@ -27,9 +27,21 @@
# POSSIBILITY OF SUCH DAMAGE. # POSSIBILITY OF SUCH DAMAGE.
### ###
import sys
import types import types
import threading import threading
def universalImport(*names):
f = sys._getframe(1)
for name in names:
try:
ret = __import__(name, globals=f.f_globals)
except ImportError:
continue
else:
return ret
raise ImportError, ','.join(names)
def changeFunctionName(f, name, doc=None): def changeFunctionName(f, name, doc=None):
if doc is None: if doc is None:
doc = f.__doc__ doc = f.__doc__