From: Simon Marchi Date: Mon, 9 Sep 2019 17:19:02 +0000 (-0400) Subject: bt2: make can_seek_beginning a method instead of a property X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=14cfc8ce101e9a63b8d0aa3075407e987669c3ed bt2: make can_seek_beginning a method instead of a property _GenericMessageIterator.can_seek_beginning and _UserMessageIterator._user_can_seek_beginning are currently properties. We will add the equivalent for can_seek_ns_from_origin, but this one requires a parameter (the ns_from_origin value), so it can't be a property, it has to be a method. For consistency, change the can_seek_beginning ones to be methods. Change-Id: Ic2c5b54908753dc7498fb1d0f94022301f766a15 Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/2017 Tested-by: jenkins Reviewed-by: Francis Deslauriers --- diff --git a/src/bindings/python/bt2/bt2/message_iterator.py b/src/bindings/python/bt2/bt2/message_iterator.py index c392d420..284a7d94 100644 --- a/src/bindings/python/bt2/bt2/message_iterator.py +++ b/src/bindings/python/bt2/bt2/message_iterator.py @@ -56,7 +56,6 @@ class _GenericMessageIterator(object._SharedObject, _MessageIterator): return bt2_message._create_from_ptr(msg_ptr) - @property def can_seek_beginning(self): status, res = self._can_seek_beginning(self._ptr) utils._handle_func_status( @@ -166,16 +165,15 @@ class _UserMessageIterator(_MessageIterator): msg._get_ref(msg._ptr) return int(msg._ptr) - @property def _bt_can_seek_beginning_from_native(self): # Here, we mimic the behavior of the C API: # - # - If the iterator has a _user_can_seek_beginning attribute, + # - If the iterator has a _user_can_seek_beginning method, # read it and use that result. # - Otherwise, the presence or absence of a `_user_seek_beginning` # method indicates whether the iterator can seek beginning. if hasattr(self, '_user_can_seek_beginning'): - can_seek_beginning = self._user_can_seek_beginning + can_seek_beginning = self._user_can_seek_beginning() utils._check_bool(can_seek_beginning) return can_seek_beginning else: diff --git a/src/bindings/python/bt2/bt2/native_bt_component_class.i.h b/src/bindings/python/bt2/bt2/native_bt_component_class.i.h index 58c6c774..7299d013 100644 --- a/src/bindings/python/bt2/bt2/native_bt_component_class.i.h +++ b/src/bindings/python/bt2/bt2/native_bt_component_class.i.h @@ -548,7 +548,8 @@ component_class_can_seek_beginning( py_iter = bt_self_message_iterator_get_data(self_message_iterator); BT_ASSERT(py_iter); - py_result = PyObject_GetAttrString(py_iter, "_bt_can_seek_beginning_from_native"); + py_result = PyObject_CallMethod(py_iter, + "_bt_can_seek_beginning_from_native", NULL); BT_ASSERT(!py_result || PyBool_Check(py_result)); diff --git a/tests/bindings/python/bt2/test_message_iterator.py b/tests/bindings/python/bt2/test_message_iterator.py index 01d4eca3..752682bc 100644 --- a/tests/bindings/python/bt2/test_message_iterator.py +++ b/tests/bindings/python/bt2/test_message_iterator.py @@ -292,9 +292,8 @@ class UserMessageIteratorTestCase(unittest.TestCase): def _user_seek_beginning(self): self._upstream_iter.seek_beginning() - @property def _user_can_seek_beginning(self): - return self._upstream_iter.can_seek_beginning + return self._upstream_iter.can_seek_beginning() class MyFilter(bt2._UserFilterComponent, message_iterator_class=MyFilterIter): def __init__(self, params, obj): @@ -345,7 +344,7 @@ def _setup_seek_test(sink_cls, user_seek_beginning=None, user_can_seek_beginning MySourceIter._user_seek_beginning = user_seek_beginning if user_can_seek_beginning is not None: - MySourceIter._user_can_seek_beginning = property(user_can_seek_beginning) + MySourceIter._user_can_seek_beginning = user_can_seek_beginning class MySource(bt2._UserSourceComponent, message_iterator_class=MySourceIter): def __init__(self, params, obj): @@ -364,9 +363,8 @@ def _setup_seek_test(sink_cls, user_seek_beginning=None, user_can_seek_beginning def __next__(self): return next(self._upstream_iter) - @property def _user_can_seek_beginning(self): - return self._upstream_iter.can_seek_beginning + return self._upstream_iter.can_seek_beginning() def _user_seek_beginning(self): self._upstream_iter.seek_beginning() @@ -392,7 +390,7 @@ class UserMessageIteratorSeekBeginningTestCase(unittest.TestCase): def _user_consume(self): nonlocal can_seek_beginning - can_seek_beginning = self._msg_iter.can_seek_beginning + can_seek_beginning = self._msg_iter.can_seek_beginning() def _user_can_seek_beginning(self): nonlocal input_port_iter_can_seek_beginning @@ -426,7 +424,7 @@ class UserMessageIteratorSeekBeginningTestCase(unittest.TestCase): def _user_consume(self): nonlocal can_seek_beginning - can_seek_beginning = self._msg_iter.can_seek_beginning + can_seek_beginning = self._msg_iter.can_seek_beginning() def _user_seek_beginning(self): pass @@ -450,7 +448,7 @@ class UserMessageIteratorSeekBeginningTestCase(unittest.TestCase): def _user_consume(self): nonlocal can_seek_beginning - can_seek_beginning = self._msg_iter.can_seek_beginning + can_seek_beginning = self._msg_iter.can_seek_beginning() graph = _setup_seek_test(MySink) can_seek_beginning = None @@ -469,7 +467,7 @@ class UserMessageIteratorSeekBeginningTestCase(unittest.TestCase): def _user_consume(self): # This is expected to raise. - self._msg_iter.can_seek_beginning + self._msg_iter.can_seek_beginning() def _user_can_seek_beginning(self): raise ValueError('moustiquaire') @@ -496,7 +494,7 @@ class UserMessageIteratorSeekBeginningTestCase(unittest.TestCase): def _user_consume(self): # This is expected to raise. - self._msg_iter.can_seek_beginning + self._msg_iter.can_seek_beginning() def _user_can_seek_beginning(self): return 'Amqui'