summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfuzzyman <devnull@localhost>2009-04-13 22:37:10 +0000
committerfuzzyman <devnull@localhost>2009-04-13 22:37:10 +0000
commit152ecea88f5c432a63cef5186e5ac47e90a2eb61 (patch)
tree774b2b4caf4a8023e5b7c72f248a1c87904ff659
parent108e4e2b5101dd4b2a6ea1556bbad6bd8b8cf93d (diff)
downloadconfigobj-152ecea88f5c432a63cef5186e5ac47e90a2eb61.tar.gz
addition of force_list validation option plus as_list ConfigObj method.
-rw-r--r--configobj.py2
-rw-r--r--docs/configobj.txt2
-rw-r--r--docs/validate.txt3
-rw-r--r--validate.py26
4 files changed, 29 insertions, 4 deletions
diff --git a/configobj.py b/configobj.py
index 90fcdc8..cf3a891 100644
--- a/configobj.py
+++ b/configobj.py
@@ -113,7 +113,7 @@ except NameError:
# Sentinel for use in getattr calls to replace hasattr
MISSING = object()
-__version__ = '4.6.0 alpha'
+__version__ = '4.6.0'
__revision__ = '$Id: configobj.py 156 2006-01-31 14:57:08Z fuzzyman $'
diff --git a/docs/configobj.txt b/docs/configobj.txt
index 1cb79c5..1d23578 100644
--- a/docs/configobj.txt
+++ b/docs/configobj.txt
@@ -2325,7 +2325,7 @@ From version 4 it lists all releases and changes.
* A section that was supplied as a value (or vice-versa) in the actual config file would cause an exception during validation (the config file is still broken of course, but it is now handled gracefully)
* Added ``as_list`` method
* Removed the deprecated ``istrue``, ``encode`` and ``decode`` methods
-* Running test_configobj now also runs the doctests in the configobj module
+* Running test_configobj.py now also runs the doctests in the configobj module
As a consequence of the changes to configspec handling, when you create a ConfigObj instance and provide a configspec, the configspec attribute is only set on the ConfigObj instance - it isn't set on the sections until you validate. You also can't set the configspec attribute to be a dictionary. This wasn't documented but did work previously.
diff --git a/docs/validate.txt b/docs/validate.txt
index 45522a9..93cc1db 100644
--- a/docs/validate.txt
+++ b/docs/validate.txt
@@ -617,7 +617,8 @@ CHANGELOG
2009/04/13 - Version 1.0.0
--------------------------
-BUGFIX: can now handle multiline strings.
+* BUGFIX: can now handle multiline strings.
+* Addition of 'force_list' validation option.
As there are no known bugs or outstanding feature requests I am marking this 1.0.
diff --git a/validate.py b/validate.py
index aeba0dc..30bdfac 100644
--- a/validate.py
+++ b/validate.py
@@ -130,7 +130,7 @@
__docformat__ = "restructuredtext en"
-__version__ = '1.0.0 alpha'
+__version__ = '1.0.0'
__revision__ = '$Id: validate.py 123 2005-09-08 08:54:28Z fuzzyman $'
@@ -558,6 +558,7 @@ class Validator(object):
'mixed_list': is_mixed_list,
'pass': self._pass,
'option': is_option,
+ 'force_list': force_list,
}
if functions is not None:
self.functions.update(functions)
@@ -1210,6 +1211,29 @@ def is_ip_addr_list(value, min=None, max=None):
return [is_ip_addr(mem) for mem in is_list(value, min, max)]
+def force_list(value, min=None, max=None):
+ """
+ Check that a value is a list, coercing strings into
+ a list with one member. Useful where users forget the
+ trailing comma that turns a single value into a list.
+
+ You can optionally specify the minimum and maximum number of members.
+ A minumum of greater than one will fail if the user only supplies a
+ string.
+
+ >>> vtor.check('force_list', ())
+ []
+ >>> vtor.check('force_list', [])
+ []
+ >>> vtor.check('force_list', 'hello')
+ ['hello']
+ """
+ if not isinstance(value, (list, tuple)):
+ value = [value]
+ return is_list(value, min, max)
+
+
+
fun_dict = {
'integer': is_integer,
'float': is_float,