summaryrefslogtreecommitdiff
path: root/sleekxmpp/plugins/base.py
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2012-07-27 10:45:52 -0700
committerLance Stout <lancestout@gmail.com>2012-07-27 10:45:52 -0700
commitc2189b4ecd6b022ed9900a6f411bd7e9d57c47ce (patch)
tree88b7dabe06edbbfeb45403c06628230c18301458 /sleekxmpp/plugins/base.py
parentc9b2cf60431f415584c1d12a7855e0d2ac148ec4 (diff)
parente3fab66dfb27abdd8aa28a8d15367a490d4b42dd (diff)
downloadslixmpp-c2189b4ecd6b022ed9900a6f411bd7e9d57c47ce.tar.gz
slixmpp-c2189b4ecd6b022ed9900a6f411bd7e9d57c47ce.tar.bz2
slixmpp-c2189b4ecd6b022ed9900a6f411bd7e9d57c47ce.tar.xz
slixmpp-c2189b4ecd6b022ed9900a6f411bd7e9d57c47ce.zip
Merge branch 'master' into develop
Diffstat (limited to 'sleekxmpp/plugins/base.py')
-rw-r--r--sleekxmpp/plugins/base.py36
1 files changed, 35 insertions, 1 deletions
diff --git a/sleekxmpp/plugins/base.py b/sleekxmpp/plugins/base.py
index 26f0c827..67675908 100644
--- a/sleekxmpp/plugins/base.py
+++ b/sleekxmpp/plugins/base.py
@@ -14,6 +14,7 @@
"""
import sys
+import copy
import logging
import threading
@@ -272,6 +273,14 @@ class BasePlugin(object):
#: be initialized as needed if this plugin is enabled.
dependencies = set()
+ #: The basic, standard configuration for the plugin, which may
+ #: be overridden when initializing the plugin. The configuration
+ #: fields included here may be accessed directly as attributes of
+ #: the plugin. For example, including the configuration field 'foo'
+ #: would mean accessing `plugin.foo` returns the current value of
+ #: `plugin.config['foo']`.
+ default_config = {}
+
def __init__(self, xmpp, config=None):
self.xmpp = xmpp
if self.xmpp:
@@ -279,7 +288,32 @@ class BasePlugin(object):
#: A plugin's behaviour may be configurable, in which case those
#: configuration settings will be provided as a dictionary.
- self.config = config if config is not None else {}
+ self.config = copy.copy(self.default_config)
+ if config:
+ self.config.update(config)
+
+ def __getattr__(self, key):
+ """Provide direct access to configuration fields.
+
+ If the standard configuration includes the option `'foo'`, then
+ accessing `self.foo` should be the same as `self.config['foo']`.
+ """
+ if key in self.default_config:
+ return self.config.get(key, None)
+ else:
+ return object.__getattribute__(self, key)
+
+ def __setattr__(self, key, value):
+ """Provide direct assignment to configuration fields.
+
+ If the standard configuration includes the option `'foo'`, then
+ assigning to `self.foo` should be the same as assigning to
+ `self.config['foo']`.
+ """
+ if key in self.default_config:
+ self.config[key] = value
+ else:
+ super(BasePlugin, self).__setattr__(key, value)
def _init(self):
"""Initialize plugin state, such as registering event handlers.