def import_plugin(self, plugin):
names = [<EOL>'<STR_LIT>' % (namespace, '<STR_LIT>' if namespace[-<NUM_LIT:1>] == '<STR_LIT:_>' else '<STR_LIT:.>', plugin)<EOL>if namespace else<EOL>plugin<EOL>for namespace in self.namespaces<EOL>]<EOL>for name in names:<EOL><INDENT>if name in sys.modules:<EOL><INDENT>return sys.modules[name]<EOL><DEDENT><DEDENT>for name in names:<EOL><INDENT>try:<EOL><INDENT>__import__(name)<EOL>return sys.modules[name]<EOL><DEDENT>except (ImportError, KeyError):<EOL><INDENT>pass<EOL><DEDENT><DEDENT>raise PluginNotFoundError(<EOL>'<STR_LIT>' % (plugin, names),<EOL>plugin, names)<EOL>
Import plugin by given name, looking at :attr:`namespaces`.

:param plugin: plugin module name
:type plugin: str
:raises PluginNotFoundError: if not found on any namespace