Python importlib._bootstrap 模块,lib import import_module() 实例源码

我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用importlib._bootstrap.lib import import_module()

项目:imperative    作者:yaroslavvb    | 项目源码 | 文件源码
def __getattribute__(self, name):
        if name == '__dct__':
            return super(_LazyModule, self).__getattribute__(name)
        dct = self.__dct__
        mod = dct['mod']
        if dct['loaded']:
            m = _modules[mod]
        else:
            m = _import_module(mod)
            glbs = globals()
            pkg = dct['pkg']
            asname = dct['asname']
            if asname is None:
                glbs[pkg] = m = _modules[pkg]
            else:
                glbs[asname] = m
            dct['loaded'] = True
        return getattr(m, name)

#
# itensor
#
项目:SiDBot    作者:TiagoDanin    | 项目源码 | 文件源码
def get_str(self, text):
    l = import_lang('languages.{}'.format(self.user_lang))
    if text in l.lang:
        return l.lang[text]
    else:
        new_str(self, text)
        return text
项目:SiDBot    作者:TiagoDanin    | 项目源码 | 文件源码
def run(self, input, matches):
    if input == 'help':
        t = []
        for plugin in plugins_list:
            p = import_plugin('plugins.{}'.format(plugin))
            t.append(p.name)
        sendList(self, title='List of Plugins', text=False, results=t)
        return
    else:
        if input in plugins_list:
            p = import_plugin('plugins.{}'.format(input))
            if 'hide' in p.config:
                if p.config['hide']:
                    sendFalid(self, title='Plugin', reason='results')
                    return

            sendAbout(self,
                title=p.name,
                about=p.description,
                more_about=p.usage,
                title_url=False,
                url=False,
                img=False
            )
            return
        else:
            sendFalid(self, title='Plugin', reason='results')
            return
    return
项目:python-terrascript    作者:mjuenema    | 项目源码 | 文件源码
def test_resources(self):
        r = importm(self.import_r)
        for k in dir(r):
            if k.startswith(self.provider):
                # Find short name 'aws_instance' -> 'instance'
                assert k[len(self.provider)+1:] in dir(r)
项目:python-terrascript    作者:mjuenema    | 项目源码 | 文件源码
def test_data(self):
        d = importm(self.import_d)
        for k in dir(d):
            if k.startswith(self.provider):
                # Find short name 'aws_instance' -> 'instance'
                assert k[len(self.provider)+1:] in dir(d)
项目:wetland    作者:ohmyadd    | 项目源码 | 文件源码
def __init__(self, hacker_ip):
        self.hacker_ip = hacker_ip
        self.plugins = [impt('wetland.output_plugin.'+n).plugin(self.hacker_ip)
                        for n in pname]
项目:SiDBot    作者:TiagoDanin    | 项目源码 | 文件源码
def run(self):
        for plugin in plugins_list:
            res = import_plugin('plugins.{plugin}'.format(plugin=plugin))
            for patt in res.patterns:
                matches = regex(patt, self.msg_text)
                if matches:
                    if 'admin_plugin' in res.config:
                        if res.config['admin_plugin']:
                            if self.chat_id == admins[self.bot_type]:
                                add_log('Safe user' + str(self.chat_id),
                                    'Admin Plugin'
                                )
                    self.plugin = plugin
                    self.matches = matches
                    self.trigger = patt

                    # Status
                    incr_database(table='status', name='allbot_usage')
                    incr_database(table='status',
                        name=str('bot_usage:' + self.bot_type)
                    )
                    incr_database(table='status',
                        name=str('plugin_usage:' + plugin)
                    )
                    if self.bot_type == 'telegram-inline':
                        incr_database(table='status',
                            name=str('inline_usage')
                        )

                    # Get user_lang
                    self.user_lang = get_user_lang(self)

                    if self.debug:
                        add_log('{cmd} - {plugin}: {text} '.format(
                                cmd = patt,
                                plugin = plugin,
                                text = self.msg_text
                            ),
                            '[TRIGGER]'
                        )

                    if self.dev_mode:
                        res.run(self,  matches.group(1), matches)
                    else:
                        try:
                            res.run(self,  matches.group(1), matches)
                        except Exception as err:
                            add_log('Failed run_plugin: {}'.format(err),
                                'Error in bot!',
                                True, True
                            )
                            if self.send_falid_plugin:
                                sendFalid(self, title='BOT', reason='generic')