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
28 if not isinstance(o
, bool):
29 raise TypeError("'{}' is not a 'bool' object".format(o
.__class
__.__name
__))
33 if not isinstance(o
, int):
34 raise TypeError("'{}' is not an 'int' object".format(o
.__class
__.__name
__))
38 if not isinstance(o
, float):
39 raise TypeError("'{}' is not a 'float' object".format(o
.__class
__.__name
__))
43 if not isinstance(o
, str):
44 raise TypeError("'{}' is not a 'str' object".format(o
.__class
__.__name
__))
47 def _check_type(o
, expected_type
):
48 if not isinstance(o
, expected_type
):
49 raise TypeError("'{}' is not a '{}' object".format(o
.__class
__.__name
__,
53 def _is_in_int64_range(v
):
54 assert(isinstance(v
, int))
55 return v
>= -(2**63) and v
<= (2**63 - 1)
59 if not isinstance(v
, int):
62 return _is_in_int64_range(v
)
65 def _is_in_uint64_range(v
):
66 assert(isinstance(v
, int))
67 return v
>= 0 and v
<= (2**64 - 1)
71 if not isinstance(v
, int):
74 return _is_in_uint64_range(v
)
77 def _check_int64(v
, msg
=None):
80 if not _is_in_int64_range(v
):
82 msg
= 'expecting a signed 64-bit integral value'
84 msg
+= ' (got {})'.format(v
)
88 def _check_uint64(v
, msg
=None):
91 if not _is_in_uint64_range(v
):
93 msg
= 'expecting an unsigned 64-bit integral value'
95 msg
+= ' (got {})'.format(v
)
100 return v
== 18446744073709551615
104 return v
!= 0 and ((v
& (v
- 1)) == 0)
107 def _check_alignment(a
):
111 raise ValueError('{} is not a power of two'.format(a
))
114 def _raise_bt2_error(msg
):
121 def _handle_ret(ret
, msg
=None):
123 _raise_bt2_error(msg
)
126 def _handle_ptr(ptr
, msg
=None):
128 _raise_bt2_error(msg
)
131 def _check_log_level(log_level
):
132 _check_int(log_level
)
135 bt2
.logging
.LoggingLevel
.VERBOSE
,
136 bt2
.logging
.LoggingLevel
.DEBUG
,
137 bt2
.logging
.LoggingLevel
.INFO
,
138 bt2
.logging
.LoggingLevel
.WARN
,
139 bt2
.logging
.LoggingLevel
.ERROR
,
140 bt2
.logging
.LoggingLevel
.FATAL
,
141 bt2
.logging
.LoggingLevel
.NONE
,
144 if log_level
not in log_levels
:
145 raise ValueError("'{}' is not a valid logging level".format(log_level
))
This page took 0.033199 seconds and 4 git commands to generate.