def _moduledoc(file):
    """return the top-level python documentation for the given file

    Loosely inspired by pydoc.source_synopsis(), but rewritten to
    handle triple quotes and to return the whole text instead of just
    the synopsis"""
    result = []
    line = file.readline()
    while line[:1] == b'#' or not line.strip():
        line = file.readline()
        if not line:
            break
    start = line[:3]
    if start == b'"""' or start == b"'''":
        line = line[3:]
        while line:
            if line.rstrip().endswith(start):
                line = line.split(start)[0]
                if line:
                    result.append(line)
                break
            elif not line:
                return None
            result.append(line)
            line = file.readline()
    else:
        return None
    return b''.join(result)
