diff options
| author | Jenkins <jenkins@review.openstack.org> | 2013-05-11 20:09:23 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2013-05-11 20:09:23 +0000 |
| commit | c102f7421d3e23ee696698784b82146825041182 (patch) | |
| tree | 0a1d6376cb1d1f51d6d6a5e9c60b0d344fb8ee26 /openstack/common/strutils.py | |
| parent | bfda6841f681613c65a01736946d78f3dec540c6 (diff) | |
| parent | d9b0719f02433b243a20fe705af4799c619f4e28 (diff) | |
| download | oslo-c102f7421d3e23ee696698784b82146825041182.tar.gz oslo-c102f7421d3e23ee696698784b82146825041182.tar.xz oslo-c102f7421d3e23ee696698784b82146825041182.zip | |
Merge "Handle ints passed to `boolean_from_string`"
Diffstat (limited to 'openstack/common/strutils.py')
| -rw-r--r-- | openstack/common/strutils.py | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/openstack/common/strutils.py b/openstack/common/strutils.py index fe8418e..d6dfb13 100644 --- a/openstack/common/strutils.py +++ b/openstack/common/strutils.py @@ -49,12 +49,15 @@ def bool_from_string(subject): Useful for JSON-decoded stuff and config file parsing """ - if isinstance(subject, bool): - return subject - if isinstance(subject, basestring): - if subject.strip().lower() in ('true', 'on', 'yes', '1'): - return True - return False + try: + # True or 1 or '1' -> True + # False or < 1 or > 1 or '0' -> False + return int(subject) == 1 + except TypeError: + # None -> False + return False + except ValueError: + return subject.strip().lower() in ('true', 'on', 'yes') def safe_decode(text, incoming=None, errors='strict'): |
