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
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
):
50 raise TypeError("'{}' is not a '{}' object".format(o
.__class
__.__name
__,
54 def _is_in_int64_range(v
):
55 assert(isinstance(v
, int))
56 return v
>= -(2**63) and v
<= (2**63 - 1)
60 if not isinstance(v
, int):
63 return _is_in_int64_range(v
)
66 def _is_in_uint64_range(v
):
67 assert(isinstance(v
, int))
68 return v
>= 0 and v
<= (2**64 - 1)
72 if not isinstance(v
, int):
75 return _is_in_uint64_range(v
)
78 def _check_int64(v
, msg
=None):
81 if not _is_in_int64_range(v
):
83 msg
= 'expecting a signed 64-bit integral value'
85 msg
+= ' (got {})'.format(v
)
89 def _check_uint64(v
, msg
=None):
92 if not _is_in_uint64_range(v
):
94 msg
= 'expecting an unsigned 64-bit integral value'
96 msg
+= ' (got {})'.format(v
)
101 return v
== 18446744073709551615
105 return v
!= 0 and ((v
& (v
- 1)) == 0)
108 def _check_alignment(a
):
112 raise ValueError('{} is not a power of two'.format(a
))
115 def _raise_bt2_error(msg
):
122 def _handle_ptr(ptr
, msg
=None):
124 _raise_bt2_error(msg
)
127 def _check_log_level(log_level
):
128 _check_int(log_level
)
131 bt2
.logging
.LoggingLevel
.TRACE
,
132 bt2
.logging
.LoggingLevel
.DEBUG
,
133 bt2
.logging
.LoggingLevel
.INFO
,
134 bt2
.logging
.LoggingLevel
.WARNING
,
135 bt2
.logging
.LoggingLevel
.ERROR
,
136 bt2
.logging
.LoggingLevel
.FATAL
,
137 bt2
.logging
.LoggingLevel
.NONE
,
140 if log_level
not in log_levels
:
141 raise ValueError("'{}' is not a valid logging level".format(log_level
))
144 def _handle_func_status(status
, msg
=None):
145 if status
== native_bt
.__BT
_FUNC
_STATUS
_OK
:
149 if status
== native_bt
.__BT
_FUNC
_STATUS
_ERROR
or status
== native_bt
.__BT
_FUNC
_STATUS
_MEMORY
_ERROR
:
154 elif status
== native_bt
.__BT
_FUNC
_STATUS
_END
:
159 elif status
== native_bt
.__BT
_FUNC
_STATUS
_AGAIN
:
163 raise bt2
.TryAgain(msg
)
164 elif status
== native_bt
.__BT
_FUNC
_STATUS
_CANCELED
:
168 raise bt2
.Canceled(msg
)
169 elif status
== native_bt
.__BT
_FUNC
_STATUS
_LOADING
_ERROR
:
171 raise bt2
.LoadingError
173 raise bt2
.LoadingError(msg
)
174 elif status
== native_bt
.__BT
_FUNC
_STATUS
_OVERFLOW
:
176 raise bt2
.OverflowError
178 raise bt2
.OverflowError(msg
)
179 elif status
== native_bt
.__BT
_FUNC
_STATUS
_INVALID
_OBJECT
:
181 raise bt2
.InvalidObject
183 raise bt2
.InvalidObject(msg
)
184 elif status
== native_bt
.__BT
_FUNC
_STATUS
_INVALID
_PARAMS
:
186 raise bt2
.InvalidParams
188 raise bt2
.InvalidParams(msg
)
189 elif status
== native_bt
.__BT
_FUNC
_STATUS
_UNSUPPORTED
:
191 raise bt2
.Unsupported
193 raise bt2
.Unsupported(msg
)
This page took 0.035306 seconds and 4 git commands to generate.