# Path: pybar/utils/utils.py
# def string_is_binary(string):
#     try:
#         int(string, 2)
#         return True
#     except (TypeError, ValueError):
#         return False
# 
# def flatten_iterable(iterable):
#     """flatten iterable, but leaves out strings
# 
#     [[[1, 2, 3], [4, 5]], 6] -> [1, 2, 3, 4, 5, 6]
# 
#     """
#     for item in iterable:
#         if isinstance(item, collections.Iterable) and not isinstance(item, basestring):
#             for sub in flatten_iterable(item):
#                 yield sub
#         else:
#             yield item
# 
# def iterable(item):
#     """generate iterable from item, but leaves out strings
# 
#     """
#     if isinstance(item, collections.Iterable) and not isinstance(item, basestring):
#         return item
#     else:
#         return [item]


import logging
import re
import os
import struct
import copy
import datetime
import numpy as np
import tables as tb
from ast import literal_eval
from collections import OrderedDict
from contextlib import contextmanager
from importlib import import_module
from operator import itemgetter
from bitarray import bitarray
from pybar.utils.utils import string_is_binary, flatten_iterable, iterable

        if command_bitvector.length() == 0:
            raise ValueError("Command has length 0")
        return command_bitvector

    def get_global_register_attributes(self, register_attribute, do_sort=True, **kwargs):
        """Calculating register numbers from register names.

        Usage: get_global_register_attributes("attribute_name", name = [regname_1, regname_2, ...], addresses = 2)
        Receives: attribute name to be returned, dictionaries (kwargs) of register attributes and values for making cuts
        Returns: list of attribute values that matches dictionaries of attributes

        """
        # speed up of the most often used keyword name
        try:
            names = iterable(kwargs.pop('name'))
        except KeyError:
            register_attribute_list = []
        else:
            register_attribute_list = [self.global_registers[reg][register_attribute] for reg in names]
        for keyword in kwargs.keys():
            allowed_values = iterable(kwargs[keyword])
            try:
                register_attribute_list.extend(map(itemgetter(register_attribute), filter(lambda global_register: set(iterable(global_register[keyword])).intersection(allowed_values), self.global_registers.itervalues())))
            except AttributeError:
                pass
        if not register_attribute_list and filter(None, kwargs.itervalues()):
            raise ValueError('Global register attribute %s empty' % register_attribute)
        if do_sort:
            return sorted(set(flatten_iterable(register_attribute_list)))
        else:

# Path: pybar/utils/utils.py
# def string_is_binary(string):
#     try:
#         int(string, 2)
#         return True
#     except (TypeError, ValueError):
#         return False
# 
# def flatten_iterable(iterable):
#     """flatten iterable, but leaves out strings
# 
#     [[[1, 2, 3], [4, 5]], 6] -> [1, 2, 3, 4, 5, 6]
# 
#     """
#     for item in iterable:
#         if isinstance(item, collections.Iterable) and not isinstance(item, basestring):
#             for sub in flatten_iterable(item):
#                 yield sub
#         else:
#             yield item
# 
# def iterable(item):
#     """generate iterable from item, but leaves out strings
# 
#     """
#     if isinstance(item, collections.Iterable) and not isinstance(item, basestring):
#         return item
#     else:
#         return [item]


# Path: pybar/fei4/register.py
import logging
import re
import os
import struct
import copy
import datetime
import numpy as np
import tables as tb
from ast import literal_eval
from collections import OrderedDict
from contextlib import contextmanager
from importlib import import_module
from operator import itemgetter
from bitarray import bitarray
from pybar.utils.utils import string_is_binary, flatten_iterable, iterable

        if command_bitvector.length() == 0:
            raise ValueError("Command has length 0")
        return command_bitvector

    def get_global_register_attributes(self, register_attribute, do_sort=True, **kwargs):
        """Calculating register numbers from register names.

        Usage: get_global_register_attributes("attribute_name", name = [regname_1, regname_2, ...], addresses = 2)
        Receives: attribute name to be returned, dictionaries (kwargs) of register attributes and values for making cuts
        Returns: list of attribute values that matches dictionaries of attributes

        """
        # speed up of the most often used keyword name
        try:
            names = iterable(kwargs.pop('name'))
        except KeyError:
            register_attribute_list = []
        else:
            register_attribute_list = [self.global_registers[reg][register_attribute] for reg in names]
        for keyword in kwargs.keys():
            allowed_values = iterable(kwargs[keyword])
            try:
                register_attribute_list.extend(map(itemgetter(register_attribute), filter(lambda global_register: set(iterable(global_register[keyword])).intersection(allowed_values), self.global_registers.itervalues())))
            except AttributeError:
                pass
        if not register_attribute_list and filter(None, kwargs.itervalues()):
            raise ValueError('Global register attribute %s empty' % register_attribute)
        if do_sort:
            return sorted(set(flatten_iterable(register_attribute_list)))
        else:

            return flatten_iterable(register_attribute_list)
