def end_of_block(text, pos):
    """Return the position of the closing '}' starting from pos
    """
    assert text[pos] == '{'
    cnt = 1;  i = pos
    while cnt > 0:
        k = text.find('{', i + 1)
        i = text.find('}', i + 1)
        if k >= 0 and k < i:
            cnt += 1
            i = k
        else:
            cnt -= 1
    return i