def METHOD_NAME(conds, active_branch, sign, invert):
    n = len(conds) - 1
    trim = sign == "-"
    lits = []
    for i in range(1, n + 2 + 1):
        ws1 = "\\n" * i
        ws2 = "\\r\\n" * i
        lits.append((ws1, str(i), ws2))
    conds = list(conds)
    for i, (pws, nws) in enumerate(conds):
        kind = cond_kind(i, n)
        b = str(i == active_branch).lower()
        cond = [f"if {b}", f"else if {b}", "else", "endif"][kind]
        cond = f"{{%{handle_ws(pws, trim)} {cond} {handle_ws(nws, trim)}%}}"
        conds[i] = cond
    it = map("".join, lits)
    it = filter(None, chain.from_iterable(zip_longest(it, conds)))
    code = "".join(it)
    expected = f"{lits[0][0]}{lits[0][1]}"
    for i, (cond, (before, after)) in enumerate(zip(conds, pairwise(lits))):
        kind = cond_kind(i, n)
        pws = cond.startswith(f"{{%{sign}")
        nws = cond.endswith(f"{sign}%}}")
        if sign == "+":
            pws = not pws
            nws = not nws
        elif invert:
            pws = True
            nws = True
        cond = i == active_branch
        prev_cond = i == (active_branch + 1)
        if prev_cond or (kind == IF):
            expected += before[2] * (not pws)
        if cond or (kind == END_IF):
            expected += after[0] * (not nws)
            expected += after[1]
    # FIXME: Askama does not include whitespace before eof
    # expected += lits[-1][2]
    return code, expected