summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorianb <ianb@localhost>2005-08-22 22:46:28 +0000
committerianb <ianb@localhost>2005-08-22 22:46:28 +0000
commit2f46fd3925a56490de67a07a7674bd2921803ca2 (patch)
treea3c12083116062378a0125d8b431e2c6291db3cd
parent8d2f559f5b40851440fbaecb288bb273379e7c1f (diff)
downloadpastedeploy-git-2f46fd3925a56490de67a07a7674bd2921803ca2.tar.gz
Converters for handling the string keys we get
-rw-r--r--paste/deploy/converters.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/paste/deploy/converters.py b/paste/deploy/converters.py
new file mode 100644
index 0000000..f329174
--- /dev/null
+++ b/paste/deploy/converters.py
@@ -0,0 +1,24 @@
+def asbool(obj):
+ if isinstance(obj, (str, unicode)):
+ obj = obj.strip().lower()
+ if obj in ['true', 'yes', 'on', 'y', 't', '1']:
+ return True
+ elif obj in ['false', 'no', 'off', 'n', 'f', '0']:
+ return False
+ else:
+ raise ValueError(
+ "String is not true/false: %r" % obj)
+ return bool(obj)
+
+def aslist(obj, sep=None, strip=True):
+ if isinstance(obj, (str, unicode)):
+ lst = obj.split(sep)
+ if strip:
+ lst = [v.strip() for v in lst]
+ return lst
+ elif isinstance(obj, (list, tuple)):
+ return obj
+ elif obj is None:
+ return []
+ else:
+ return [obj]