diff options
| author | ianb <devnull@localhost> | 2005-05-14 18:29:02 +0000 |
|---|---|---|
| committer | ianb <devnull@localhost> | 2005-05-14 18:29:02 +0000 |
| commit | 8c4dca8221e17bd36c3fe6d05ab576cd5e08c001 (patch) | |
| tree | a138e0fb759e6ce7db1a628781eca7d7f863689c /paste | |
| parent | 5c6364392f92a72e7b27c19d425fff888a966960 (diff) | |
| download | paste-8c4dca8221e17bd36c3fe6d05ab576cd5e08c001.tar.gz | |
Added functions for converting strings to values
Diffstat (limited to 'paste')
| -rw-r--r-- | paste/pyconfig.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/paste/pyconfig.py b/paste/pyconfig.py index b6c9005..2f408f9 100644 --- a/paste/pyconfig.py +++ b/paste/pyconfig.py @@ -342,3 +342,29 @@ class DispatchingConfig(object): "No configuration has been registered for this process " "or thread") return conf[key] + +def make_bool(option): + """ + Convert a string option to a boolean, e.g. yes/no, true/false + """ + if not isinstance(option, (str, unicode)): + return option + if option.lower() in ('y', 'yes', 't', 'true', '1', 'on'): + return True + if option.lower() in ('n', 'no', 'f', 'false', '0', 'off'): + return False + raise ValueError( + "Boolean (yes/no) value expected (got: %r)" % option) + +def make_list(option): + """ + Convert a string to a list, with commas for separators. + """ + if not option: + return [] + if not isinstance(option, (str, unicode)): + if not isinstance(option, (list, tuple)): + return [option] + else: + return option + return [s.strip() for s in option.split(',')] |
