Open main menu

Changes

Relax source design

297 bytes removed, 09:59, 26 September 2014
→‎General: Updated the check_*() function section for the lib.checks.Check strategy design pattern.
== The check_*() functions ==
These functions are for performing checks for certain data being present. They can return True or False, throw RelaxWarnings, or raise RelaxErrorsThe idea uses the [https://en.wikipedia.org/wiki/Strategy_pattern strategy design pattern] which is implemented in the lib.checks.Check class.
=== Packages ===
=== Design ===
The check_*() functions should have , via the Check object, accept the 'escalate' keyword argument which can have the following values:
* 0 - This will simply cause the function to return True or False.
<source lang="python">
 
# Python module imports.
from warnings import warn
# relax module imports.
from lib.errors checks import RelaxErrorfrom lib.warnings import RelaxWarningCheck
def check_xxxcheck_xxx_func(escalatea=0None):
"""Check if xxx.
@keyword escalatea: The feedback to give if the Some check fails. This can be 0 for no printouts, 1 to throw a RelaxWarning, or 2 to raise a RelaxErrorspecific keyword argument. @type escalatea: int @raises RelaxErrorreturn: If escalate is set to 2 The status of the check and the check fails. @return: True if message to send to the check passes, False otherwiseuser. @rtype: bool, str
"""
# Init.
check_ok = True
msg = ''
# Check that...
if not something(a):
check_ok = False
msg = "Something is missing."
# Warnings Return the status and errorsmessage. if not return check_ok and escalate == 1:, "Something is missing."  warn(RelaxWarning(msg))# Create the checking object. elif not check_ok and escalate check_xxx == 2: raise RelaxErrorCheck(msgcheck_xxx_func)
# Return the status.
return check_ok
</source>
Trusted, Bureaucrats
4,223

edits