diff options
author | Tomás Touceda <chiiph@leap.se> | 2013-07-26 10:45:29 -0300 |
---|---|---|
committer | Tomás Touceda <chiiph@leap.se> | 2013-07-26 10:45:29 -0300 |
commit | 66d02033fe4f38de04aa174b8e7b35bbabe3c678 (patch) | |
tree | c6740a2406adada67ad65c72c66b4727f0221239 /src/leap/common/check.py | |
parent | 8b5e745eb274be5b38c99d1b6121521ec2023475 (diff) | |
parent | b006c2c56fe0b83a3baf6a10a1e7dbe196051b8d (diff) |
Merge branch 'release-0.2.7'
Diffstat (limited to 'src/leap/common/check.py')
-rw-r--r-- | src/leap/common/check.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/leap/common/check.py b/src/leap/common/check.py index e6b0b52..82da5ff 100644 --- a/src/leap/common/check.py +++ b/src/leap/common/check.py @@ -60,3 +60,20 @@ def leap_assert_type(var, expectedType): leap_assert(isinstance(var, expectedType), "Expected type %r instead of %r" % (expectedType, type(var))) + + +def leap_check(condition, message="", exception=Exception): + """ + Asserts the condition and displays the message if that's not + met. It also logs the error and its backtrace. + + :param condition: condition to check + :type condition: bool + :param message: message to display if the condition isn't met + :type message: str + :param exception: the exception to raise in case of condition being false. + :type exception: Exception + """ + if not condition: + logger.error(message) + raise exception(message) |