python: run isort on everything
[babeltrace.git] / src / bindings / python / bt2 / bt2 / value.py
index 4c3afacbedc26dd855288ba188459137d43650c8..c938ff9046bba925db8b2d09b9f73f572c3aa4d4 100644 (file)
@@ -1,32 +1,17 @@
-# The MIT License (MIT)
+# SPDX-License-Identifier: MIT
 #
 # Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com>
-#
-# 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
-import collections.abc
-import functools
-import numbers
-import math
+
 import abc
-import bt2
+import math
+import numbers
+import functools
+import collections.abc
+
+from bt2 import error as bt2_error
+from bt2 import utils as bt2_utils
+from bt2 import object as bt2_object
+from bt2 import native_bt
 
 
 def _create_from_ptr_template(ptr, object_map):
@@ -99,9 +84,15 @@ def create_value(value):
     )
 
 
-class _ValueConst(object._SharedObject, metaclass=abc.ABCMeta):
-    _get_ref = staticmethod(native_bt.value_get_ref)
-    _put_ref = staticmethod(native_bt.value_put_ref)
+class _ValueConst(bt2_object._SharedObject, metaclass=abc.ABCMeta):
+    @staticmethod
+    def _get_ref(ptr):
+        native_bt.value_get_ref(ptr)
+
+    @staticmethod
+    def _put_ref(ptr):
+        native_bt.value_put_ref(ptr)
+
     _create_value_from_ptr = staticmethod(_create_from_const_ptr)
     _create_value_from_ptr_and_get_ref = staticmethod(
         _create_from_const_ptr_and_get_ref
@@ -112,8 +103,8 @@ class _ValueConst(object._SharedObject, metaclass=abc.ABCMeta):
 
     def _check_create_status(self, ptr):
         if ptr is None:
-            raise bt2._MemoryError(
-                'cannot create {} value object'.format(self._NAME.lower())
+            raise bt2_error._MemoryError(
+                "cannot create {} value object".format(self._NAME.lower())
             )
 
 
@@ -265,7 +256,7 @@ class _IntegralValue(_IntegralValueConst, _NumericValue):
 
 
 class _BoolValueConst(_IntegralValueConst):
-    _NAME = 'Const boolean'
+    _NAME = "Const boolean"
 
     def __bool__(self):
         return self._value
@@ -280,7 +271,7 @@ class _BoolValueConst(_IntegralValueConst):
 
 
 class BoolValue(_BoolValueConst, _IntegralValue):
-    _NAME = 'Boolean'
+    _NAME = "Boolean"
 
     def __init__(self, value=None):
         if value is None:
@@ -330,7 +321,7 @@ class _IntegerValue(_IntegerValueConst, _IntegralValue):
     @classmethod
     def _value_to_int(cls, value):
         if not isinstance(value, numbers.Integral):
-            raise TypeError('expecting an integral number object')
+            raise TypeError("expecting an integral number object")
 
         value = int(value)
         cls._check_int_range(value)
@@ -343,33 +334,33 @@ class _IntegerValue(_IntegerValueConst, _IntegralValue):
 
 
 class _UnsignedIntegerValueConst(_IntegerValueConst):
-    _NAME = 'Const unsigned integer'
+    _NAME = "Const unsigned integer"
     _get_value = staticmethod(native_bt.value_integer_unsigned_get)
 
 
 class UnsignedIntegerValue(_UnsignedIntegerValueConst, _IntegerValue):
-    _NAME = 'Unsigned integer'
-    _check_int_range = staticmethod(utils._check_uint64)
+    _NAME = "Unsigned integer"
+    _check_int_range = staticmethod(bt2_utils._check_uint64)
     _create_default_value = staticmethod(native_bt.value_integer_unsigned_create)
     _create_value = staticmethod(native_bt.value_integer_unsigned_create_init)
     _set_value = staticmethod(native_bt.value_integer_unsigned_set)
 
 
 class _SignedIntegerValueConst(_IntegerValueConst):
-    _NAME = 'Const signed integer'
+    _NAME = "Const signed integer"
     _get_value = staticmethod(native_bt.value_integer_signed_get)
 
 
 class SignedIntegerValue(_SignedIntegerValueConst, _IntegerValue):
-    _NAME = 'Signed integer'
-    _check_int_range = staticmethod(utils._check_int64)
+    _NAME = "Signed integer"
+    _check_int_range = staticmethod(bt2_utils._check_int64)
     _create_default_value = staticmethod(native_bt.value_integer_signed_create)
     _create_value = staticmethod(native_bt.value_integer_signed_create_init)
     _set_value = staticmethod(native_bt.value_integer_signed_set)
 
 
 class _RealValueConst(_NumericValueConst, numbers.Real):
-    _NAME = 'Const real number'
+    _NAME = "Const real number"
 
     @property
     def _value(self):
@@ -377,7 +368,7 @@ class _RealValueConst(_NumericValueConst, numbers.Real):
 
 
 class RealValue(_RealValueConst, _NumericValue):
-    _NAME = 'Real number'
+    _NAME = "Real number"
 
     def __init__(self, value=None):
         if value is None:
@@ -404,14 +395,14 @@ class RealValue(_RealValueConst, _NumericValue):
 
 @functools.total_ordering
 class _StringValueConst(collections.abc.Sequence, _Value):
-    _NAME = 'Const string'
+    _NAME = "Const string"
 
     @classmethod
     def _value_to_str(cls, value):
         if isinstance(value, _StringValueConst):
             value = value._value
 
-        utils._check_str(value)
+        bt2_utils._check_str(value)
         return value
 
     @property
@@ -447,7 +438,7 @@ class _StringValueConst(collections.abc.Sequence, _Value):
 
 
 class StringValue(_StringValueConst, _Value):
-    _NAME = 'String'
+    _NAME = "String"
 
     def __init__(self, value=None):
         if value is None:
@@ -460,7 +451,7 @@ class StringValue(_StringValueConst, _Value):
 
     def _set_value(self, value):
         status = native_bt.value_string_set(self._ptr, self._value_to_str(value))
-        utils._handle_func_status(status)
+        bt2_utils._handle_func_status(status)
 
     value = property(fset=_set_value)
 
@@ -482,7 +473,7 @@ class _Container(_ContainerConst):
 
 
 class _ArrayValueConst(_ContainerConst, collections.abc.Sequence, _ValueConst):
-    _NAME = 'Const array'
+    _NAME = "Const array"
     _borrow_element_by_index = staticmethod(
         native_bt.value_array_borrow_element_by_index_const
     )
@@ -519,7 +510,7 @@ class _ArrayValueConst(_ContainerConst, collections.abc.Sequence, _ValueConst):
         index = int(index)
 
         if index < 0 or index >= len(self):
-            raise IndexError('array value object index is out of range')
+            raise IndexError("array value object index is out of range")
 
     def __getitem__(self, index):
         self._check_index(index)
@@ -528,11 +519,11 @@ class _ArrayValueConst(_ContainerConst, collections.abc.Sequence, _ValueConst):
         return self._create_value_from_ptr_and_get_ref(ptr)
 
     def __repr__(self):
-        return '[{}]'.format(', '.join([repr(v) for v in self]))
+        return "[{}]".format(", ".join([repr(v) for v in self]))
 
 
 class ArrayValue(_ArrayValueConst, _Container, collections.abc.MutableSequence, _Value):
-    _NAME = 'Array'
+    _NAME = "Array"
     _borrow_element_by_index = staticmethod(
         native_bt.value_array_borrow_element_by_index
     )
@@ -558,7 +549,7 @@ class ArrayValue(_ArrayValueConst, _Container, collections.abc.MutableSequence,
             ptr = value._ptr
 
         status = native_bt.value_array_set_element_by_index(self._ptr, index, ptr)
-        utils._handle_func_status(status)
+        bt2_utils._handle_func_status(status)
 
     def append(self, value):
         value = create_value(value)
@@ -569,7 +560,7 @@ class ArrayValue(_ArrayValueConst, _Container, collections.abc.MutableSequence,
             ptr = value._ptr
 
         status = native_bt.value_array_append_element(self._ptr, ptr)
-        utils._handle_func_status(status)
+        bt2_utils._handle_func_status(status)
 
     def __iadd__(self, iterable):
         # Python will raise a TypeError if there's anything wrong with
@@ -590,7 +581,7 @@ class _MapValueKeyIterator(collections.abc.Iterator):
         keys_ptr = native_bt.value_map_get_keys(map_obj._ptr)
 
         if keys_ptr is None:
-            raise RuntimeError('unexpected error: cannot get map value object keys')
+            raise RuntimeError("unexpected error: cannot get map value object keys")
 
         self._keys = _create_from_ptr(keys_ptr)
 
@@ -604,7 +595,7 @@ class _MapValueKeyIterator(collections.abc.Iterator):
 
 
 class _MapValueConst(_ContainerConst, collections.abc.Mapping, _ValueConst):
-    _NAME = 'Const map'
+    _NAME = "Const map"
     _borrow_entry_value_ptr = staticmethod(native_bt.value_map_borrow_entry_value_const)
 
     def __ne__(self, other):
@@ -637,7 +628,7 @@ class _MapValueConst(_ContainerConst, collections.abc.Mapping, _ValueConst):
         return native_bt.value_map_has_entry(self._ptr, key)
 
     def _check_key_type(self, key):
-        utils._check_str(key)
+        bt2_utils._check_str(key)
 
     def _check_key(self, key):
         if key not in self:
@@ -653,12 +644,12 @@ class _MapValueConst(_ContainerConst, collections.abc.Mapping, _ValueConst):
         return _MapValueKeyIterator(self)
 
     def __repr__(self):
-        items = ['{}: {}'.format(repr(k), repr(v)) for k, v in self.items()]
-        return '{{{}}}'.format(', '.join(items))
+        items = ["{}: {}".format(repr(k), repr(v)) for k, v in self.items()]
+        return "{{{}}}".format(", ".join(items))
 
 
 class MapValue(_MapValueConst, _Container, collections.abc.MutableMapping, _Value):
-    _NAME = 'Map'
+    _NAME = "Map"
     _borrow_entry_value_ptr = staticmethod(native_bt.value_map_borrow_entry_value)
 
     def __init__(self, value=None):
@@ -682,7 +673,7 @@ class MapValue(_MapValueConst, _Container, collections.abc.MutableMapping, _Valu
             ptr = value._ptr
 
         status = native_bt.value_map_insert_entry(self._ptr, key, ptr)
-        utils._handle_func_status(status)
+        bt2_utils._handle_func_status(status)
 
 
 _TYPE_TO_OBJ = {
This page took 0.02769 seconds and 4 git commands to generate.