Take a string in ANVL format and break it into a dictionary of key/values

def readANVLString(string):
    """
    Take a string in ANVL format and break it into a dictionary of key/values
    """

    ANVLDict = {}
    ANVLLines = string.split("\n")
    lineCount = len(ANVLLines)
    index = 0
    while index < lineCount:
        line = ANVLLines[index]
        if not len(line) or not len(line.strip()):
            index = index + 1
            continue
        if "#" == line[0]:
            index = index + 1
            continue
        if ":" not in line:
            raise InvalidANVLRecord(
                "Missing colon in line %d of ANVL record." % (index+1,)
            )
        parts = line.split(":", 1)
        key = parts[0].strip()
        contentBuffer = parts[1].lstrip()
        nextIndex = index + 1
        while nextIndex < lineCount:
            nextLine = ANVLLines[nextIndex]
            if len(nextLine) and "#" == nextLine[0]:
                nextIndex = nextIndex + 1
                continue
            if nextLine == nextLine.lstrip():
                break
            if contentBuffer:
                contentBuffer = contentBuffer + " " + nextLine.lstrip()
            else:
                contentBuffer = nextLine.lstrip()
            nextIndex = nextIndex + 1
        index = nextIndex
        ANVLDict[key] = contentBuffer
    return ANVLDict