def IndentWrappedStructure(source, INDENT='    ', open='{', close='}'):
    """ Transform wrapped to indented structure.
        ~ Wrapping must be consistent!
        ~ open/close tokens must be on an empty line! """
    EOL = '\n'
    result = ''
    pos, level = 0, 0
    lines = source.splitlines()
    for i, line in enumerate(lines):
        if line.strip() == open:
            level += 1
        elif line.strip() == close:
            if level == 0:
                message = (
                    'Inconsistent indentation at line #%s (decrement under zero):\n%s'
                     % (i, line))
                raise ValueError(message)
            level -= 1
        else:
            result += level * INDENT + line.lstrip() + EOL
    return result
