Skip to content

Commit

Permalink
Improve CustomConfig documentation
Browse files Browse the repository at this point in the history
Improve documentation about what CustomConfigHelperMixin does,
it was not very clear without a close look to the code before.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
  • Loading branch information
spaetz authored and nicolas33 committed Jan 20, 2011
1 parent d9a72c3 commit c5d49ce
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
1 change: 1 addition & 0 deletions Changelog.draft.rst
Expand Up @@ -20,6 +20,7 @@ New Features
Changes
-------

* Improve CustomConfig documentation.
* Imply single threading mode in debug mode exept for "-d thread".
* Code and import cleanups.
* Allow UI to have arbitrary names.
Expand Down
28 changes: 21 additions & 7 deletions offlineimap/CustomConfig.py
Expand Up @@ -71,18 +71,33 @@ def getsectionlist(self, key):
if x.startswith(key)]

def CustomConfigDefault():
"""Just a sample constant that won't occur anywhere else to use for the
default."""
"""Just a constant that won't occur anywhere else.
This allows us to differentiate if the user has passed in any
default value to the getconf* functions in ConfigHelperMixin
derived classes."""
pass

class ConfigHelperMixin:
"""Allow comfortable retrieving of config values pertaining to a section.
If a class inherits from this cls:`ConfigHelperMixin`, it needs
to provide 2 functions: meth:`getconfig` (returning a
ConfigParser object) and meth:`getsection` (returning a string
which represents the section to look up). All calls to getconf*
will then return the configuration values for the ConfigParser
object in the specific section."""

def _confighelper_runner(self, option, default, defaultfunc, mainfunc):
if default != CustomConfigDefault:
return apply(defaultfunc, [self.getsection(), option, default])
else:
"""Return config value for getsection()"""
if default == CustomConfigDefault:
return apply(mainfunc, [self.getsection(), option])
else:
return apply(defaultfunc, [self.getsection(), option, default])

def getconf(self, option, default = CustomConfigDefault):

def getconf(self, option,
default = CustomConfigDefault):
return self._confighelper_runner(option, default,
self.getconfig().getdefault,
self.getconfig().get)
Expand All @@ -101,4 +116,3 @@ def getconffloat(self, option, default = CustomConfigDefault):
return self._confighelper_runner(option, default,
self.getconfig().getdefaultfloat,
self.getconfig().getfloat)

0 comments on commit c5d49ce

Please sign in to comment.