1 # The MIT License (MIT)
3 # Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com>
5 # Permission is hereby granted, free of charge, to any person obtaining a copy
6 # of this software and associated documentation files (the "Software"), to deal
7 # in the Software without restriction, including without limitation the rights
8 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 # copies of the Software, and to permit persons to whom the Software is
10 # furnished to do so, subject to the following conditions:
12 # The above copyright notice and this permission notice shall be included in
13 # all copies or substantial portions of the Software.
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 from bt2
import logging
as bt2_logging
25 from bt2
import native_bt
29 if not isinstance(o
, bool):
30 raise TypeError("'{}' is not a 'bool' object".format(o
.__class
__.__name
__))
34 if not isinstance(o
, int):
35 raise TypeError("'{}' is not an 'int' object".format(o
.__class
__.__name
__))
39 if not isinstance(o
, float):
40 raise TypeError("'{}' is not a 'float' object".format(o
.__class
__.__name
__))
44 if not isinstance(o
, str):
45 raise TypeError("'{}' is not a 'str' object".format(o
.__class
__.__name
__))
48 def _check_type(o
, expected_type
):
49 if not isinstance(o
, expected_type
):
51 "'{}' is not a '{}' object".format(o
.__class
__.__name
__, expected_type
)
55 def _is_in_int64_range(v
):
56 assert isinstance(v
, int)
57 return v
>= -(2 ** 63) and v
<= (2 ** 63 - 1)
61 if not isinstance(v
, int):
64 return _is_in_int64_range(v
)
67 def _is_in_uint64_range(v
):
68 assert isinstance(v
, int)
69 return v
>= 0 and v
<= (2 ** 64 - 1)
73 if not isinstance(v
, int):
76 return _is_in_uint64_range(v
)
79 def _check_int64(v
, msg
=None):
82 if not _is_in_int64_range(v
):
84 msg
= 'expecting a signed 64-bit integral value'
86 msg
+= ' (got {})'.format(v
)
90 def _check_uint64(v
, msg
=None):
93 if not _is_in_uint64_range(v
):
95 msg
= 'expecting an unsigned 64-bit integral value'
97 msg
+= ' (got {})'.format(v
)
102 return v
== 18446744073709551615
106 return v
!= 0 and ((v
& (v
- 1)) == 0)
109 def _check_alignment(a
):
113 raise ValueError('{} is not a power of two'.format(a
))
116 def _check_log_level(log_level
):
117 _check_int(log_level
)
120 bt2_logging
.LoggingLevel
.TRACE
,
121 bt2_logging
.LoggingLevel
.DEBUG
,
122 bt2_logging
.LoggingLevel
.INFO
,
123 bt2_logging
.LoggingLevel
.WARNING
,
124 bt2_logging
.LoggingLevel
.ERROR
,
125 bt2_logging
.LoggingLevel
.FATAL
,
126 bt2_logging
.LoggingLevel
.NONE
,
129 if log_level
not in log_levels
:
130 raise ValueError("'{}' is not a valid logging level".format(log_level
))
133 def _handle_func_status(status
, msg
=None):
134 if status
== native_bt
.__BT
_FUNC
_STATUS
_OK
:
138 if status
== native_bt
.__BT
_FUNC
_STATUS
_ERROR
:
139 assert msg
is not None
140 raise bt2
._Error(msg
)
141 elif status
== native_bt
.__BT
_FUNC
_STATUS
_MEMORY
_ERROR
:
142 assert msg
is not None
143 raise bt2
._MemoryError(msg
)
144 elif status
== native_bt
.__BT
_FUNC
_STATUS
_END
:
149 elif status
== native_bt
.__BT
_FUNC
_STATUS
_AGAIN
:
153 raise bt2
.TryAgain(msg
)
154 elif status
== native_bt
.__BT
_FUNC
_STATUS
_OVERFLOW
_ERROR
:
156 raise bt2
._OverflowError
158 raise bt2
._OverflowError(msg
)
159 elif status
== native_bt
.__BT
_FUNC
_STATUS
_UNKNOWN
_OBJECT
:
161 raise bt2
.UnknownObject
163 raise bt2
.UnknownObject(msg
)
168 class _ListenerHandle
:
169 def __init__(self
, listener_id
, obj
):
170 self
._listener
_id
= listener_id
This page took 0.032836 seconds and 4 git commands to generate.