Open main menu

Changes

Relax source design

862 bytes added, 11:05, 14 September 2014
β†’β€ŽThe check_*() functions: Added a function prototype
* 1 - In addition to returning True or False, the function will throw a RelaxWarning for better user feedback.
* 2 - This will cause a RelaxError to be raised if the data is missing, not set up, etc. Otherwise the function returns True.
 
=== Implementation ===
 
Here is a prototype function:
 
<source lang="python">
def check_xxx(escalate=0):
"""Check if xxx.
 
@keyword escalate: The feedback to give if the check fails. This can be 0 for no printouts, 1 to throw a RelaxWarning, or 2 to raise a RelaxError.
@type escalate: int
@raises RelaxError: If escalate is set to 2 and the check fails.
@return: True if the check passes, False otherwise.
@rtype: bool
"""
 
# Init.
flag = True
msg = ''
 
# Check that...
if not something():
flag = False
msg = "Something is missing."
 
# Warnings and errors.
if not flag and escalate == 1:
warn(RelaxWarning(msg))
elif not flag and escalate == 2:
raise RelaxError(msg)
 
# Return the answer.
return flag
</source>
Trusted, Bureaucrats
4,228

edits