def decode_bitmask(mask, value, strict=True):
    """Decode a integer value into its symbolic bit names.

    Use this function to convert a bitmask value into a list of symbolic bit names,
    for example::

        >>> COLORS = define_bitmask('COLORS','Primary colors',RED=0,BLUE=1,GREEN=4)
        >>> decode_bitmask(COLORS,COLORS.RED|COLORS.BLUE)
        ('RED', 'BLUE')

    For pretty printing, try::

        >>> print('|'.join(decode_bitmask(COLORS,COLORS.RED|COLORS.BLUE)))
        RED|BLUE

    Args:
        mask: A bitmask type, normally created with :func:`create_bitmask`, that defines
            the symbolic bit names to use for the decoding.
        value(int): The integral value to decode.
        strict(bool): If set, then all bits set in value must be defined in the bitmask
            type definition.

    Returns:
        tuple: A tuple of symbolic bit names in order of increasing bit offset. If strict
            is False, then any bits without corresponding symbolic names will appear as
            '1<<n' for offset n.

    Raises:
        AttributeError: mask does not have the attributes necessary to define a bitmask.
        ValueError: value has a bit set that has no symbolic name defined and strict is True.
    """
    names = []
    shifted = int(value)
    offset = 0
    while shifted:
        if shifted & 1:
            name = mask._reverse_map.get(offset)
            if name is None:
                if strict:
                    raise ValueError(
                        'Bit {0:d} is set but has no symbolic name defined.'
                        .format(offset))
                name = '1<<{0:d}'.format(offset)
            names.append(name)
        offset += 1
        shifted = shifted >> 1
    return tuple(names)
