def _get_imbalance_index(text, imbalance=0, boundary_characters='()'):
    """
    Return an integer where:

        - If the parenthesis are not balanced--the integer is the imbalance
          index at the end of the text (a negative number).

        - If the parenthesis are balanced--the integer is the index at which
          they become so (a positive integer).
    """
    index = 0
    length = len(text)
    while index < length and imbalance != 0:
        character = text[index]
        if character == boundary_characters[0]:
            imbalance -= 1
        elif character == boundary_characters[-1]:
            imbalance += 1
        index += 1
    return index if imbalance == 0 else imbalance
