<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def detect_scheme(filename):
 """Detects partitioning scheme of the source Args: filename (str):
 path to file or device for detection of \ partitioning scheme. Returns: SCHEME_MBR, SCHEME_GPT or SCHEME_UNKNOWN Raises: IOError: The file doesn't exist or cannot be opened for reading """


    logger = logging.getLogger(__name__)
    logger.info('Detecting partitioning scheme')

    with open(filename, 'rb') as f:
        # Look for MBR signature first
        f.seek(mbr.MBR_SIG_OFFSET)
        data = f.read(mbr.MBR_SIG_SIZE)
        signature = struct.unpack("<H", data)[0]

        if signature != mbr.MBR_SIGNATURE:
            # Something else
            logger.debug('Unknown partitioning scheme')
            return PartitionScheme.SCHEME_UNKNOWN
        else:
            # Could be MBR or GPT, look for GPT header
            f.seek(gpt.GPT_HEADER_OFFSET)
            data = f.read(gpt.GPT_SIG_SIZE)
            signature = struct.unpack("<8s", data)[0]

            if signature != gpt.GPT_SIGNATURE:
                logger.debug('MBR scheme detected')
                return PartitionScheme.SCHEME_MBR
            else:
                logger.debug('GPT scheme detected')
                return PartitionScheme.SCHEME_GPT