[node-patches] Change in ovirt-node[master]: utils: Make parse_bool a bit more strict

fabiand at fedoraproject.org fabiand at fedoraproject.org
Wed Aug 28 07:30:54 UTC 2013


Fabian Deutsch has uploaded a new change for review.

Change subject: utils: Make parse_bool a bit more strict
......................................................................

utils: Make parse_bool a bit more strict

Oly allow definite True values: y, 1, True, true, Yes, yes.
Previously also strings like Yes? would be interpreted as true, but
that's a bit to liberal.

Change-Id: Ie5524550f5444752840f07aac4c3d8d3905750ac
Signed-off-by: Fabian Deutsch <fabiand at fedoraproject.org>
---
M src/ovirt/node/utils/__init__.py
1 file changed, 7 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/37/18637/1

diff --git a/src/ovirt/node/utils/__init__.py b/src/ovirt/node/utils/__init__.py
index ec52d36..22cabdd 100644
--- a/src/ovirt/node/utils/__init__.py
+++ b/src/ovirt/node/utils/__init__.py
@@ -118,12 +118,14 @@
     >>> parse_bool(True)
     True
 
-    >>> txts = ["yes", "YES!", "1", 1, "y"]
-    >>> all((parse_bool(txt) for txt in txts))
+    >>> txts = ["yes", "YES", "1", 1, "y"]
+    >>> rs = [parse_bool(txt) for txt in txts]
+    >>> all(rs)
     True
 
-    >>> txts = ["no", "NO!", "0", 0, False, None, "foo", "n"]
-    >>> all((not parse_bool(txt) for txt in txts))
+    >>> txts = ["no", "NO!", "0", 0, False, None, "foo", "n", "YES!"]
+    >>> rs = [not parse_bool(txt) for txt in txts]
+    >>> all(rs)
     True
 
     Args:
@@ -133,7 +135,7 @@
     """
     if txt is not None and type(txt) in [str, unicode, int, bool]:
         utxt = unicode(txt)
-        if len(utxt) > 0 and utxt[0] in ["y", "t", "Y", "T", "1"]:
+        if utxt.lower() in ["1", "y", "yes", "true"]:
             return True
     return False
 


-- 
To view, visit http://gerrit.ovirt.org/18637
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie5524550f5444752840f07aac4c3d8d3905750ac
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Fabian Deutsch <fabiand at fedoraproject.org>



More information about the node-patches mailing list