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
#
python类lib import import_module()的实例源码
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
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
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)
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)
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]
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')