Advertisement
NickG

Untitled

Oct 17th, 2013
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.89 KB | None | 0 0
  1. class PluginLoader:
  2.     def __init__(self, client, plugins):
  3.         self.client = client
  4.         self.plugins = plugins
  5.         self.extensions = {'client': self.client}
  6.         self.announce = {}
  7.  
  8.         for plugin in self.plugins:
  9.             if hasattr(plugin, 'pl_announce'):
  10.                 for ident in plugin.pl_announce:
  11.                     self.announce[ident] = plugin
  12.         while self.plugins:
  13.             plugin = self.plugins.pop()
  14.             plugin(self, self.client.plugin_settings.get(plugin, None))
  15.  
  16.     def requires(self, ident):
  17.         if ident not in self.extensions:
  18.             if ident in self.announce:
  19.                 plugin = self.announce[ident]
  20.                 self.plugins.remove(plugin)
  21.                 plugin(self, self.client.plugin_settings.get(plugin, None))
  22.             else:
  23.                 return None
  24.  
  25.         return self.extensions[ident]
  26.  
  27.     def provides(self, plugin, ident):
  28.         self.extensions[ident] = plugin
  29.  
  30.     def reg_event_handler(self, events, handlers):
  31.         self.client.reg_event_handler(events, handlers)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement