# The MIT License (MIT)
#
-# Copyright (c) 2016 Philippe Proulx <pproulx@efficios.com>
+# 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
return
if status == native_bt.VALUE_STATUS_FROZEN:
- raise bt2.FrozenError('{} value object is frozen'.format(obj_name))
+ raise bt2.Frozen('{} value object is frozen'.format(obj_name))
elif status == native_bt.VALUE_STATUS_INVAL:
# In practice, this should never happen, because arguments
# should always be validated in this Python module before
class _Value(object._Object, object._Freezable, metaclass=abc.ABCMeta):
- def __init__(self, ptr):
- super().__init__(ptr)
-
def __eq__(self, other):
if other is None:
# self is never the null value object
return self.value <= float(other)
def _spec_eq(self, other):
- return
+ pass
def __eq__(self, other):
if not isinstance(other, numbers.Number):
if not isinstance(value, bool):
raise TypeError("'{}' object is not a 'bool' or 'BoolValue' object".format(value.__class__))
- return value
+ return int(value)
@property
def value(self):
status, value = native_bt.value_bool_get(self._ptr)
- self._handle_status(status)
- return value
+ assert(status == native_bt.VALUE_STATUS_OK)
+ return value > 0
@value.setter
def value(self, value):
@property
def value(self):
status, value = native_bt.value_integer_get(self._ptr)
- self._handle_status(status)
+ assert(status == native_bt.VALUE_STATUS_OK)
return value
@value.setter
@property
def value(self):
status, value = native_bt.value_float_get(self._ptr)
- self._handle_status(status)
+ assert(status == native_bt.VALUE_STATUS_OK)
return value
@value.setter
@property
def value(self):
status, value = native_bt.value_string_get(self._ptr)
- self._handle_status(status)
+ assert(status == native_bt.VALUE_STATUS_OK)
return value
@value.setter
ptr = native_bt.value_copy(self._ptr)
if ptr is None:
- fmt = 'unexpected error: cannot deep-copy {} value object'
- raise RuntimeError(fmt.format(self._NAME))
+ raise RuntimeError('unexpected error: cannot deep-copy {} value object'.format(self._NAME))
copy = self.__class__._create_from_ptr(ptr)
memo[id(self)] = copy
def __len__(self):
size = native_bt.value_array_size(self._ptr)
- self._handle_status(size)
+ assert(size >= 0)
return size
def _check_index(self, index):
def __getitem__(self, index):
self._check_index(index)
ptr = native_bt.value_array_get(self._ptr, index)
-
- if ptr is None:
- raise RuntimeError('unexpected error: cannot get array value object element')
-
+ assert(ptr)
return _create_from_ptr(ptr)
def __setitem__(self, index, value):
def __len__(self):
size = native_bt.value_map_size(self._ptr)
- self._handle_status(size)
+ assert(size >= 0)
return size
def __contains__(self, key):
def __getitem__(self, key):
self._check_key(key)
ptr = native_bt.value_map_get(self._ptr, key)
-
- if ptr is None:
- raise RuntimeError('unexpected error: cannot get map value object element')
-
+ assert(ptr)
return _create_from_ptr(ptr)
def __iter__(self):