def parse_exchange_file(path, default_compartment):
    """Parse a file as a list of exchange compounds with flux limits.

    The file format is detected and the file is parsed accordingly. Path can
    be given as a string or a context.
    """

    context = FilePathContext(path)

    format = resolve_format(None, context.filepath)
    if format == 'tsv':
        logger.debug('Parsing exchange file {} as TSV'.format(
            context.filepath))
        with context.open('r') as f:
            for entry in parse_exchange_table_file(f):
                yield entry
    elif format == 'yaml':
        logger.debug('Parsing exchange file {} as YAML'.format(
            context.filepath))
        with context.open('r') as f:
            for entry in parse_exchange_yaml_file(
                    context, f, default_compartment):
                yield entry
    else:
        raise ParseError('Unable to detect format of exchange file {}'.format(
            context.filepath))
Parse a file as a list of exchange compounds with flux limits.

    The file format is detected and the file is parsed accordingly. Path can
    be given as a string or a context.