def get_kegg_section(k_record, sname, whole_section=False):
    """Get the section with name `sname` from a kegg compound record.

       Returns a str, possibly empty."""

    in_section = False
    section = []

    for line in k_record.splitlines():
        if line.startswith(sname):
            in_section = True
            section.append(line)
        elif in_section and line.startswith(' '):
            section.append(line)
        elif in_section and not line.startswith(' '):
            break

    if whole_section:
        sectionlines = section
    else:
        sectionlines = [line[12:] for line in section]
    return '\n'.join(sectionlines)