summaryrefslogtreecommitdiff
path: root/configobj.py
diff options
context:
space:
mode:
authorfuzzyman <devnull@localhost>2009-11-22 23:46:38 +0000
committerfuzzyman <devnull@localhost>2009-11-22 23:46:38 +0000
commitfba246701628e365bac82c7926e964adbd457967 (patch)
treeb94618feca9e3a13d2c557258a530718be3bdb45 /configobj.py
parent4dbe21e088aa09c19a248e74e27296c86419766f (diff)
downloadconfigobj-fba246701628e365bac82c7926e964adbd457967.tar.gz
Addition of get_extra_values function and test.
Diffstat (limited to 'configobj.py')
-rw-r--r--configobj.py27
1 files changed, 24 insertions, 3 deletions
diff --git a/configobj.py b/configobj.py
index 10f4759..e4cffbc 100644
--- a/configobj.py
+++ b/configobj.py
@@ -115,6 +115,7 @@ __all__ = (
'UnreprError',
'UnknownType',
'flatten_errors',
+ 'get_extra_values'
)
DEFAULT_INTERPOLATION = 'configparser'
@@ -2366,9 +2367,7 @@ def flatten_errors(cfg, res, levels=None, results=None):
(This is a recursive function, so you shouldn't use the ``levels`` or
``results`` arguments - they are used by the function.)
- Returns a list of keys that failed. Each member of the list is a tuple :
-
- ::
+ Returns a list of keys that failed. Each member of the list is a tuple::
([list of sections...], key, result)
@@ -2478,4 +2477,26 @@ def flatten_errors(cfg, res, levels=None, results=None):
return results
+def get_extra_values(conf, _prepend=None):
+ """
+ Find all the values and sections not in the configspec from a validated
+ ConfigObj.
+
+ It returns a list of tuples where each tuple
+
+ NOTE: If you call ``get_extra_values`` on a ConfigObj instance that hasn't
+ been validated it will return an empty list.
+ """
+ out = []
+
+ if _prepend is None:
+ _prepend = ()
+
+ out.extend(_prepend + (name,) for name in conf.extra_values)
+ for name in conf.sections:
+ if name not in conf.extra_values:
+ out.extend(get_extra_values(conf[name], _prepend + (name,)))
+ return out
+
+
"""*A programming language is a medium of expression.* - Paul Graham"""