X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;ds=sidebyside;f=src%2Fbindings%2Fpython%2Fbt2%2Fbt2%2Fmessage.py;h=5039d923b59208c1b057f78256ec85083f99e96e;hb=f5567ea88d172767b34373bc6e402da8bfd85ef8;hp=fd92361dd69371981310b21792e76dafa363a22d;hpb=60d02328261d37044d37a7d77b3d3847db5c72bf;p=babeltrace.git diff --git a/src/bindings/python/bt2/bt2/message.py b/src/bindings/python/bt2/bt2/message.py index fd92361d..5039d923 100644 --- a/src/bindings/python/bt2/bt2/message.py +++ b/src/bindings/python/bt2/bt2/message.py @@ -1,24 +1,6 @@ -# The MIT License (MIT) +# SPDX-License-Identifier: MIT # # Copyright (c) 2017 Philippe Proulx -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. from bt2 import native_bt, object, utils from bt2 import clock_snapshot as bt2_clock_snapshot @@ -40,7 +22,7 @@ class _MessageConst(object._SharedObject): def _check_has_default_clock_class(clock_class): if clock_class is None: raise ValueError( - 'cannot get default clock snapshot: stream class has no default clock class' + "cannot get default clock snapshot: stream class has no default clock class" ) @@ -230,7 +212,7 @@ class _DiscardedMessageConst(_MessageConst, _MessageWithDefaultClockSnapshot): def _check_has_default_clock_snapshots(self): if not self._has_default_clock_snapshots: raise ValueError( - 'cannot get default clock snapshot: such a message has no clock snapshots for this stream class' + "cannot get default clock snapshot: such a message has no clock snapshots for this stream class" ) @property @@ -251,6 +233,10 @@ class _DiscardedMessage(_DiscardedMessageConst, _Message): def _set_count(self, count): utils._check_uint64(count) + + if count == 0: + raise ValueError("discarded {} count is 0".format(self._item_name)) + self._set_count(self._ptr, count) _count = property(fget=_DiscardedMessageConst.count.fget, fset=_set_count) @@ -273,9 +259,10 @@ class _DiscardedEventsMessageConst(_DiscardedMessageConst): return self.stream.cls.discarded_events_have_default_clock_snapshots -class _DiscardedEventsMessage(_DiscardedMessage): +class _DiscardedEventsMessage(_DiscardedEventsMessageConst, _DiscardedMessage): _borrow_stream_ptr = staticmethod(native_bt.message_discarded_events_borrow_stream) _set_count = staticmethod(native_bt.message_discarded_events_set_count) + _item_name = "event" class _DiscardedPacketsMessageConst(_DiscardedMessageConst): @@ -298,6 +285,7 @@ class _DiscardedPacketsMessageConst(_DiscardedMessageConst): class _DiscardedPacketsMessage(_DiscardedPacketsMessageConst, _DiscardedMessage): _borrow_stream_ptr = staticmethod(native_bt.message_discarded_packets_borrow_stream) _set_count = staticmethod(native_bt.message_discarded_packets_set_count) + _item_name = "packet" _MESSAGE_TYPE_TO_CLS = {