lib: make can_seek_beginning and can_seek_ns_from_origin methods return a status
[babeltrace.git] / src / bindings / python / bt2 / bt2 / message_iterator.py
index 23e2c9a6a0c0257eeead66b184c610e768bf8d2b..c392d420491918ac1c35fd910d9fc3783d732144 100644 (file)
@@ -23,7 +23,6 @@
 from bt2 import native_bt, object, utils
 from bt2 import message as bt2_message
 import collections.abc
-from bt2 import component as bt2_component
 from bt2 import stream as bt2_stream
 from bt2 import event_class as bt2_event_class
 from bt2 import packet as bt2_packet
@@ -59,11 +58,15 @@ class _GenericMessageIterator(object._SharedObject, _MessageIterator):
 
     @property
     def can_seek_beginning(self):
-        res = self._can_seek_beginning(self._ptr)
+        status, res = self._can_seek_beginning(self._ptr)
+        utils._handle_func_status(
+            status,
+            'cannot check whether or not message iterator can seek its beginning',
+        )
         return res != 0
 
     def seek_beginning(self):
-        # Forget about buffered messages, they won't be valid after seeking..
+        # Forget about buffered messages, they won't be valid after seeking.
         self._current_msgs.clear()
         self._at = 0
 
@@ -124,6 +127,14 @@ class _UserMessageIterator(_MessageIterator):
     def _component(self):
         return native_bt.bt2_get_user_component_from_user_msg_iter(self._bt_ptr)
 
+    @property
+    def _port(self):
+        port_ptr = native_bt.self_message_iterator_borrow_port(self._bt_ptr)
+        assert port_ptr is not None
+        return bt2_port._create_self_from_ptr_and_get_ref(
+            port_ptr, native_bt.PORT_TYPE_OUTPUT
+        )
+
     @property
     def addr(self):
         return int(self._bt_ptr)
@@ -144,10 +155,10 @@ class _UserMessageIterator(_MessageIterator):
             msg = next(self)
         except StopIteration:
             raise bt2.Stop
-        except:
+        except Exception:
             raise
 
-        utils._check_type(msg, bt2_message._Message)
+        utils._check_type(msg, bt2_message._MessageConst)
 
         # The reference we return will be given to the message array.
         # However, the `msg` Python object may stay alive, if the user has kept
@@ -161,7 +172,7 @@ class _UserMessageIterator(_MessageIterator):
         #
         # - If the iterator has a _user_can_seek_beginning attribute,
         #   read it and use that result.
-        # - Otherwise, the presence or absence of a `_seek_beginning`
+        # - 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
@@ -176,18 +187,15 @@ class _UserMessageIterator(_MessageIterator):
     def _create_input_port_message_iterator(self, input_port):
         utils._check_type(input_port, bt2_port._UserComponentInputPort)
 
-        msg_iter_ptr = native_bt.self_component_port_input_message_iterator_create_from_message_iterator(
+        status, msg_iter_ptr = native_bt.bt2_self_component_port_input_message_iterator_create_from_message_iterator(
             self._bt_ptr, input_port._ptr
         )
-
-        if msg_iter_ptr is None:
-            raise bt2._MemoryError('cannot create message iterator object')
+        utils._handle_func_status(status, 'cannot create message iterator object')
+        assert msg_iter_ptr is not None
 
         return _UserComponentInputPortMessageIterator(msg_iter_ptr)
 
-    def _create_event_message(
-        self, event_class, parent=None, default_clock_snapshot=None
-    ):
+    def _create_event_message(self, event_class, parent, default_clock_snapshot=None):
         utils._check_type(event_class, bt2_event_class._EventClass)
 
         if event_class.stream_class.supports_packets:
This page took 0.024519 seconds and 4 git commands to generate.