maodevice.utils package

maodevice.utils.decorators module

maodevice.utils.decorators.chooser(arg_name, choice_list)[source]

Check whether the value in the choices.

This function is intended to be used as a decorator like follows:

>>> @chooser("arg_name", some_choice_list):
>>> def func(*args, **kwargs):
>>>     # do something
>>>     return
Parameters:
  • arg_name (str) – Name of the specified argument.
  • choice_list (list) – List of choices.
Raises:

AssertionError – If the value of “arg_name” is not in the “choice_list”.

maodevice.utils.decorators.decoder(func)[source]

Decode bytes objects.

This function is intended to be used as a decorator like follows:

>>> @decoder
>>> def func(*args, **kwargs):
>>>     # do something
>>>     return ret
Parameters:func (function) – Function to be wrapped.
Returns:A wrapped function.
Return type:wrapper (function)
maodevice.utils.decorators.limitter(arg_name, min_val, max_val, step)[source]

Limit the value of the specified argument.

This function is intended to be used as a decorator like follows:

>>> @limitter("arg_name", 0.01, 4.99, 0.01)
>>> def func(*args, **kwargs):
>>>     # do something
>>>     return
Parameters:
  • arg_name (str) – Name of the specified value.
  • min_val (int or float) – Minimum number of the range.
  • max_val (int or float) – Maximum number of the range.
  • step (int or float) – Step number.
Raises:

AssertionError – If the value of “arg_name” is not expected type and value.

maodevice.utils.misc module

maodevice.utils.misc.extract_bits(bit, bit_dict)[source]

Extract bits which is turend on (1).

Parameters:
  • bit (int) – Bit to check.
  • bit_dict (dict) – Correspondance dict of bit and status.
Returns:

List of bit which is

turned on (1).

Return type:

valid_bit (list of str)

Example

>>> sample_dict = {
...     "S1": 0b001,
...     "S2": 0b010,
...     "S3": 0b100,
... }
>>> extract_bits(0b101, sample_dict)
["S1", "S3"]
maodevice.utils.misc.or_of_bits(*bits)[source]

OR the given bits.

Parameters:*bits (int) – Bits for OR. More than one argument required.
Returns:OR of the given bits.
Return type:or_bit (int)

Example

>>> or_of_bits(1, 4, 16)
21 # 0b10101, 0x15
>>> or_of_bits(0b00010, 0b10000)
18 # 0b10010, 0x12
>>> or_of_bits(0x01, 0x10)
17 # 0b10001, 0x11