X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;ds=sidebyside;f=src%2Fbindings%2Fpython%2Fbt2%2Fbt2%2Ftrace_class.py;h=f66f385527934d5348e8e83ed9aa3730396db293;hb=f5567ea88d172767b34373bc6e402da8bfd85ef8;hp=94010d47aa04aac8e2dc48795bf758a7dddf59e6;hpb=67de22bafe6b7ad1f344a84c73bf1f4a90ea460a;p=babeltrace.git diff --git a/src/bindings/python/bt2/bt2/trace_class.py b/src/bindings/python/bt2/bt2/trace_class.py index 94010d47..f66f3855 100644 --- a/src/bindings/python/bt2/bt2/trace_class.py +++ b/src/bindings/python/bt2/bt2/trace_class.py @@ -1,26 +1,8 @@ -# The MIT License (MIT) +# SPDX-License-Identifier: MIT # # Copyright (c) 2017 Philippe Proulx # Copyright (c) 2018 Francis Deslauriers # Copyright (c) 2019 Simon Marchi -# -# 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, utils, object from bt2 import stream_class as bt2_stream_class @@ -112,7 +94,7 @@ class _TraceClassConst(object._SharedObject, collections.abc.Mapping): fn = native_bt.bt2_trace_class_add_destruction_listener status, listener_id = fn(self._ptr, listener_from_native) utils._handle_func_status( - status, 'cannot add destruction listener to trace class object' + status, "cannot add destruction listener to trace class object" ) handle._set_listener_id(listener_id) @@ -124,12 +106,12 @@ class _TraceClassConst(object._SharedObject, collections.abc.Mapping): if listener_handle._addr != self.addr: raise ValueError( - 'This trace class destruction listener does not match the trace class object.' + "This trace class destruction listener does not match the trace class object." ) if listener_handle._listener_id is None: raise ValueError( - 'This trace class destruction listener was already removed.' + "This trace class destruction listener was already removed." ) status = native_bt.trace_class_remove_destruction_listener( @@ -160,7 +142,7 @@ class _TraceClass(_TraceClassConst): trace_ptr = native_bt.trace_create(self._ptr) if trace_ptr is None: - raise bt2._MemoryError('cannot create trace class object') + raise bt2._MemoryError("cannot create trace class object") trace = bt2_trace._Trace._create_from_ptr(trace_ptr) @@ -218,14 +200,14 @@ class _TraceClass(_TraceClassConst): if self.assigns_automatic_stream_class_id: if id is not None: raise ValueError( - 'id provided, but trace class assigns automatic stream class ids' + "id provided, but trace class assigns automatic stream class ids" ) sc_ptr = native_bt.stream_class_create(self._ptr) else: if id is None: raise ValueError( - 'id not provided, but trace class does not assign automatic stream class ids' + "id not provided, but trace class does not assign automatic stream class ids" ) utils._check_uint64(id) @@ -292,7 +274,7 @@ class _TraceClass(_TraceClassConst): def _check_field_class_create_status(self, ptr, type_name): if ptr is None: - raise bt2._MemoryError('cannot create {} field class'.format(type_name)) + raise bt2._MemoryError("cannot create {} field class".format(type_name)) @staticmethod def _set_field_class_user_attrs(fc, user_attributes): @@ -301,7 +283,7 @@ class _TraceClass(_TraceClassConst): def create_bool_field_class(self, user_attributes=None): field_class_ptr = native_bt.field_class_bool_create(self._ptr) - self._check_field_class_create_status(field_class_ptr, 'boolean') + self._check_field_class_create_status(field_class_ptr, "boolean") fc = bt2_field_class._BoolFieldClass._create_from_ptr(field_class_ptr) self._set_field_class_user_attrs(fc, user_attributes) return fc @@ -311,13 +293,13 @@ class _TraceClass(_TraceClassConst): if length < 1 or length > 64: raise ValueError( - 'invalid length {}: expecting a value in the [1, 64] range'.format( + "invalid length {}: expecting a value in the [1, 64] range".format( length ) ) field_class_ptr = native_bt.field_class_bit_array_create(self._ptr, length) - self._check_field_class_create_status(field_class_ptr, 'bit array') + self._check_field_class_create_status(field_class_ptr, "bit array") fc = bt2_field_class._BitArrayFieldClass._create_from_ptr(field_class_ptr) self._set_field_class_user_attrs(fc, user_attributes) return fc @@ -351,7 +333,7 @@ class _TraceClass(_TraceClassConst): return self._create_integer_field_class( native_bt.field_class_integer_signed_create, bt2_field_class._SignedIntegerFieldClass, - 'signed integer', + "signed integer", field_value_range, preferred_display_base, user_attributes, @@ -363,7 +345,7 @@ class _TraceClass(_TraceClassConst): return self._create_integer_field_class( native_bt.field_class_integer_unsigned_create, bt2_field_class._UnsignedIntegerFieldClass, - 'unsigned integer', + "unsigned integer", field_value_range, preferred_display_base, user_attributes, @@ -375,7 +357,7 @@ class _TraceClass(_TraceClassConst): return self._create_integer_field_class( native_bt.field_class_enumeration_signed_create, bt2_field_class._SignedEnumerationFieldClass, - 'signed enumeration', + "signed enumeration", field_value_range, preferred_display_base, user_attributes, @@ -387,7 +369,7 @@ class _TraceClass(_TraceClassConst): return self._create_integer_field_class( native_bt.field_class_enumeration_unsigned_create, bt2_field_class._UnsignedEnumerationFieldClass, - 'unsigned enumeration', + "unsigned enumeration", field_value_range, preferred_display_base, user_attributes, @@ -395,7 +377,7 @@ class _TraceClass(_TraceClassConst): def create_single_precision_real_field_class(self, user_attributes=None): field_class_ptr = native_bt.field_class_real_single_precision_create(self._ptr) - self._check_field_class_create_status(field_class_ptr, 'single-precision real') + self._check_field_class_create_status(field_class_ptr, "single-precision real") field_class = bt2_field_class._SinglePrecisionRealFieldClass._create_from_ptr( field_class_ptr @@ -407,7 +389,7 @@ class _TraceClass(_TraceClassConst): def create_double_precision_real_field_class(self, user_attributes=None): field_class_ptr = native_bt.field_class_real_double_precision_create(self._ptr) - self._check_field_class_create_status(field_class_ptr, 'double-precision real') + self._check_field_class_create_status(field_class_ptr, "double-precision real") field_class = bt2_field_class._DoublePrecisionRealFieldClass._create_from_ptr( field_class_ptr @@ -419,14 +401,14 @@ class _TraceClass(_TraceClassConst): def create_structure_field_class(self, user_attributes=None): field_class_ptr = native_bt.field_class_structure_create(self._ptr) - self._check_field_class_create_status(field_class_ptr, 'structure') + self._check_field_class_create_status(field_class_ptr, "structure") fc = bt2_field_class._StructureFieldClass._create_from_ptr(field_class_ptr) self._set_field_class_user_attrs(fc, user_attributes) return fc def create_string_field_class(self, user_attributes=None): field_class_ptr = native_bt.field_class_string_create(self._ptr) - self._check_field_class_create_status(field_class_ptr, 'string') + self._check_field_class_create_status(field_class_ptr, "string") fc = bt2_field_class._StringFieldClass._create_from_ptr(field_class_ptr) self._set_field_class_user_attrs(fc, user_attributes) return fc @@ -435,8 +417,8 @@ class _TraceClass(_TraceClassConst): utils._check_type(elem_fc, bt2_field_class._FieldClass) utils._check_uint64(length) ptr = native_bt.field_class_array_static_create(self._ptr, elem_fc._ptr, length) - self._check_field_class_create_status(ptr, 'static array') - fc = bt2_field_class._StaticArrayFieldClass._create_from_ptr_and_get_ref(ptr) + self._check_field_class_create_status(ptr, "static array") + fc = bt2_field_class._StaticArrayFieldClass._create_from_ptr(ptr) self._set_field_class_user_attrs(fc, user_attributes) return fc @@ -453,8 +435,8 @@ class _TraceClass(_TraceClassConst): ptr = native_bt.field_class_array_dynamic_create( self._ptr, elem_fc._ptr, length_fc_ptr ) - self._check_field_class_create_status(ptr, 'dynamic array') - fc = bt2_field_class._create_field_class_from_ptr_and_get_ref(ptr) + self._check_field_class_create_status(ptr, "dynamic array") + fc = bt2_field_class._obj_type_from_field_class_ptr(ptr)._create_from_ptr(ptr) self._set_field_class_user_attrs(fc, user_attributes) return fc @@ -465,8 +447,8 @@ class _TraceClass(_TraceClassConst): ptr = native_bt.field_class_option_without_selector_create( self._ptr, content_fc._ptr ) - self._check_field_class_create_status(ptr, 'option') - fc = bt2_field_class._create_field_class_from_ptr_and_get_ref(ptr) + self._check_field_class_create_status(ptr, "option") + fc = bt2_field_class._obj_type_from_field_class_ptr(ptr)._create_from_ptr(ptr) self._set_field_class_user_attrs(fc, user_attributes) return fc @@ -479,8 +461,8 @@ class _TraceClass(_TraceClassConst): ptr = native_bt.field_class_option_with_selector_field_bool_create( self._ptr, content_fc._ptr, selector_fc._ptr ) - self._check_field_class_create_status(ptr, 'option') - fc = bt2_field_class._create_field_class_from_ptr_and_get_ref(ptr) + self._check_field_class_create_status(ptr, "option") + fc = bt2_field_class._obj_type_from_field_class_ptr(ptr)._create_from_ptr(ptr) self._set_field_class_user_attrs(fc, user_attributes) fc._selector_is_reversed = selector_is_reversed return fc @@ -492,7 +474,7 @@ class _TraceClass(_TraceClassConst): utils._check_type(selector_fc, bt2_field_class._IntegerFieldClass) if len(ranges) == 0: - raise ValueError('integer range set is empty') + raise ValueError("integer range set is empty") if isinstance(selector_fc, bt2_field_class._UnsignedIntegerFieldClass): utils._check_type(ranges, bt2_integer_range_set.UnsignedIntegerRangeSet) @@ -501,12 +483,14 @@ class _TraceClass(_TraceClassConst): ) else: utils._check_type(ranges, bt2_integer_range_set.SignedIntegerRangeSet) - ptr = native_bt.field_class_option_with_selector_field_integer_signed_create( - self._ptr, content_fc._ptr, selector_fc._ptr, ranges._ptr + ptr = ( + native_bt.field_class_option_with_selector_field_integer_signed_create( + self._ptr, content_fc._ptr, selector_fc._ptr, ranges._ptr + ) ) - self._check_field_class_create_status(ptr, 'option') - fc = bt2_field_class._create_field_class_from_ptr_and_get_ref(ptr) + self._check_field_class_create_status(ptr, "option") + fc = bt2_field_class._obj_type_from_field_class_ptr(ptr)._create_from_ptr(ptr) self._set_field_class_user_attrs(fc, user_attributes) return fc @@ -518,7 +502,7 @@ class _TraceClass(_TraceClassConst): selector_fc_ptr = selector_fc._ptr ptr = native_bt.field_class_variant_create(self._ptr, selector_fc_ptr) - self._check_field_class_create_status(ptr, 'variant') - fc = bt2_field_class._create_field_class_from_ptr_and_get_ref(ptr) + self._check_field_class_create_status(ptr, "variant") + fc = bt2_field_class._obj_type_from_field_class_ptr(ptr)._create_from_ptr(ptr) self._set_field_class_user_attrs(fc, user_attributes) return fc