X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fbindings%2Fpython%2Fbt2%2Fbt2%2Futils.py;h=fc6d24ce79d8b9c4915238b87ed3f7205c97b63f;hb=79092ec57262d4a1131483509d327c77f79eacf0;hp=d7e99ca60156f2c4d6f869e346adb46d531c960d;hpb=768f9bcbf4b5acd09dda85ab32c0ea30d8826136;p=babeltrace.git diff --git a/src/bindings/python/bt2/bt2/utils.py b/src/bindings/python/bt2/bt2/utils.py index d7e99ca6..fc6d24ce 100644 --- a/src/bindings/python/bt2/bt2/utils.py +++ b/src/bindings/python/bt2/bt2/utils.py @@ -2,11 +2,33 @@ # # Copyright (c) 2017 Philippe Proulx -import bt2 + +from bt2 import error as bt2_error from bt2 import logging as bt2_logging from bt2 import native_bt +class UnknownObject(Exception): + """ + Raised when a component class handles a query for an object it doesn't + know about. + """ + + pass + + +class _OverflowError(bt2_error._Error, OverflowError): + pass + + +class TryAgain(Exception): + pass + + +class Stop(StopIteration): + pass + + def _check_bool(o): if not isinstance(o, bool): raise TypeError("'{}' is not a 'bool' object".format(o.__class__.__name__)) @@ -63,9 +85,9 @@ def _check_int64(v, msg=None): if not _is_in_int64_range(v): if msg is None: - msg = 'expecting a signed 64-bit integral value' + msg = "expecting a signed 64-bit integral value" - msg += ' (got {})'.format(v) + msg += " (got {})".format(v) raise ValueError(msg) @@ -74,9 +96,9 @@ def _check_uint64(v, msg=None): if not _is_in_uint64_range(v): if msg is None: - msg = 'expecting an unsigned 64-bit integral value' + msg = "expecting an unsigned 64-bit integral value" - msg += ' (got {})'.format(v) + msg += " (got {})".format(v) raise ValueError(msg) @@ -92,7 +114,7 @@ def _check_alignment(a): _check_uint64(a) if not _is_pow2(a): - raise ValueError('{} is not a power of two'.format(a)) + raise ValueError("{} is not a power of two".format(a)) def _check_log_level(log_level): @@ -119,30 +141,27 @@ def _handle_func_status(status, msg=None): if status == native_bt.__BT_FUNC_STATUS_ERROR: assert msg is not None - raise bt2._Error(msg) + raise bt2_error._Error(msg) elif status == native_bt.__BT_FUNC_STATUS_MEMORY_ERROR: assert msg is not None - raise bt2._MemoryError(msg) + raise bt2_error._MemoryError(msg) elif status == native_bt.__BT_FUNC_STATUS_END: if msg is None: - raise bt2.Stop + raise Stop else: - raise bt2.Stop(msg) + raise Stop(msg) elif status == native_bt.__BT_FUNC_STATUS_AGAIN: if msg is None: - raise bt2.TryAgain + raise TryAgain else: - raise bt2.TryAgain(msg) + raise TryAgain(msg) elif status == native_bt.__BT_FUNC_STATUS_OVERFLOW_ERROR: - if msg is None: - raise bt2._OverflowError - else: - raise bt2._OverflowError(msg) + raise _OverflowError(msg) elif status == native_bt.__BT_FUNC_STATUS_UNKNOWN_OBJECT: if msg is None: - raise bt2.UnknownObject + raise UnknownObject else: - raise bt2.UnknownObject(msg) + raise UnknownObject(msg) else: assert False