diff options
author | Lance Stout <lancestout@gmail.com> | 2012-07-16 20:13:35 -0700 |
---|---|---|
committer | Lance Stout <lancestout@gmail.com> | 2012-07-16 20:13:35 -0700 |
commit | 78f03253983779673beaf3c102ae315707a49d2c (patch) | |
tree | dd5c031b2fc96c88e3d03b7f21cb275ef937398c /sleekxmpp/plugins/base.py | |
parent | 1efe04995941933e7579efffd8f325d8c4b516ef (diff) | |
parent | f6edaa56a6e91f7104cd63e5d48b39d4ca7e09f2 (diff) | |
download | slixmpp-78f03253983779673beaf3c102ae315707a49d2c.tar.gz slixmpp-78f03253983779673beaf3c102ae315707a49d2c.tar.bz2 slixmpp-78f03253983779673beaf3c102ae315707a49d2c.tar.xz slixmpp-78f03253983779673beaf3c102ae315707a49d2c.zip |
Merge branch 'master' into develop
Diffstat (limited to 'sleekxmpp/plugins/base.py')
-rw-r--r-- | sleekxmpp/plugins/base.py | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/sleekxmpp/plugins/base.py b/sleekxmpp/plugins/base.py index 337db2db..26f0c827 100644 --- a/sleekxmpp/plugins/base.py +++ b/sleekxmpp/plugins/base.py @@ -167,8 +167,7 @@ class PluginManager(object): self._plugins[name] = plugin for dep in plugin.dependencies: self.enable(dep, enabled=enabled) - plugin.plugin_init() - log.debug("Loaded Plugin: %s", plugin.description) + plugin._init() if top_level: for name in enabled: @@ -229,7 +228,7 @@ class PluginManager(object): raise PluginNotFound(name) for dep in PLUGIN_DEPENDENTS[name]: self.disable(dep, _disabled) - plugin.plugin_end() + plugin._end() if name in self._enabled: self._enabled.remove(name) del self._plugins[name] @@ -282,6 +281,28 @@ class BasePlugin(object): #: configuration settings will be provided as a dictionary. self.config = config if config is not None else {} + def _init(self): + """Initialize plugin state, such as registering event handlers. + + Also sets up required event handlers. + """ + if self.xmpp is not None: + self.xmpp.add_event_handler('session_bind', self.session_bind) + if self.xmpp.session_bind_event.is_set(): + self.session_bind(self.xmpp.boundjid.full) + self.plugin_init() + log.debug('Loaded Plugin: %s', self.description) + + def _end(self): + """Cleanup plugin state, and prepare for plugin removal. + + Also removes required event handlers. + """ + if self.xmpp is not None: + self.xmpp.del_event_handler('session_bind', self.session_bind) + self.plugin_end() + log.debug('Disabled Plugin: %s' % self.description) + def plugin_init(self): """Initialize plugin state, such as registering event handlers.""" pass @@ -290,6 +311,10 @@ class BasePlugin(object): """Cleanup plugin state, and prepare for plugin removal.""" pass + def session_bind(self, jid): + """Initialize plugin state based on the bound JID.""" + pass + def post_init(self): """Initialize any cross-plugin state. |