'Sets the value of the object
:param value:
An integer or a tuple of integers 0 and 1
:raises:
ValueError - when an invalid value is passed'

def set(self, value):

    if isinstance(value, set):
        if (self._map is None):
            raise ValueError(unwrap(u'\n                                                                                %s._map    has    not    been    defined\n                                                                                ', type_name(self)))
        bits = ([0] * self._size)
        self._native = value
        for index in range(0, self._size):
            key = self._map.get(index)
            if (key is None):
                continue
            if (key in value):
                bits[index] = 1
        value = u''.join(map(str_cls, bits))
    elif (value.__class__ == tuple):
        if (self._map is None):
            self._native = value
        else:
            self._native = set()
            for (index, bit) in enumerate(value):
                if bit:
                    name = self._map.get(index, index)
                    self._native.add(name)
        value = u''.join(map(str_cls, value))
    else:
        raise TypeError(unwrap(u'\n                                                                %s    value    must    be    a    tuple    of    ones    and    zeros    or    a    set    of    unicode\n                                                                strings,    not    %s\n                                                                ', type_name(self), type_name(value)))
    self._chunk = None
    if (self._map is not None):
        if (len(value) > self._size):
            raise ValueError(unwrap(u'\n                                                                                %s    value    must    be    at    most    %s    bits    long,    specified    was    %s    long\n                                                                                ', type_name(self), self._size, len(value)))
        value = value.rstrip(u'0')
    size = len(value)
    size_mod = (size % 8)
    extra_bits = 0
    if (size_mod != 0):
        extra_bits = (8 - size_mod)
        value += (u'0' * extra_bits)
    size_in_bytes = int(math.ceil((size / 8)))
    if extra_bits:
        extra_bits_byte = int_to_bytes(extra_bits)
    else:
        extra_bits_byte = '\x00'
    if (value == u''):
        value_bytes = ''
    else:
        value_bytes = int_to_bytes(int(value, 2))
    if (len(value_bytes) != size_in_bytes):
        value_bytes = (('\x00' * (size_in_bytes - len(value_bytes))) + value_bytes)
    self.contents = (extra_bits_byte + value_bytes)
    self._header = None
    if self._indefinite:
        self._indefinite = False
        self.method = 0
    if (self._trailer != ''):
        self._trailer = ''
