Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vtk refactor #1229

Merged
merged 4 commits into from May 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 45 additions & 1 deletion Packages/vcs/Lib/VCS_validation_functions.py
Expand Up @@ -349,15 +349,55 @@ def checkIntFloat(self,name,value):
## return value
## else:
## raise ValueError, 'The '+name+' attribute must be either an integer or a float value.'


def checkBoolean(self, name, value):
"""Strictly checks for True/False only. See also: checkFuzzyBoolean."""
checkName(self, name, value)
if isinstance(value, bool):
return value
checkedRaise(self, value, ValueError,
"The '%s' attribute must be either True of False, got %s."
%(name, value))

fuzzy_boolean_true_strings = ['on', '1', 'true', 'y', 'yes']
fuzzy_boolean_false_strings = ['off', '0', 'false', 'n', 'no']
fuzzy_boolean_valid_value_string = "True/False, 'True'/'False', 1/0, " \
"'1'/'0', 'y'/'n', 'yes'/'no', 'on'/'off'"
def checkFuzzyBoolean(self, name, value):
"""Checks if a value can be interpreted as true or false.

Accepted values are %s.
"""%fuzzy_boolean_valid_value_string
checkName(self, name, value)
if isinstance(value, str):
if value.lower() in fuzzy_boolean_true_strings:
return True
elif value.lower() in fuzzy_boolean_false_strings:
return False
elif isinstance(value, int):
if value == 1:
return True
elif value == 0:
return False
elif isinstance(value, bool):
return value
checkedRaise(self, value, ValueError,
"The '%s' attribute must be one of: %s. Got %s."
%(name, fuzzy_boolean_valid_value_string, value))

def checkTrueFalse(self,name,value):
"""Strictly checks for True/False or 1/0 only. See also: checkFuzzyBoolean."""
checkName(self,name,value)
if value in [True,False,1,0]:
return value==True
else:
checkedRaise(self,value, ValueError, "The '%s' attribute must be True or False" % name)

def checkOnOff(self,name,value,return_string=0):
"""Checks for some true/false inputs and returns various true/false outputs.

See also: checkFuzzyBoolean.
"""
checkName(self,name,value)
if isinstance(value,unicode):
value = str(value)
Expand Down Expand Up @@ -391,6 +431,10 @@ def checkOnOff(self,name,value,return_string=0):
return value

def checkYesNo(self,name,value):
"""Checks various true/false inputs and returns 'y'/'n'.

See also: checkFuzzyBoolean.
"""
checkName(self,name,value)
if isinstance(value,unicode):
value = str(value)
Expand Down