def reindent(txt):
    """ reindents according to { and } braces.  strips all whitespace,
        possibly not smartest thing to do.  oh well.
    """
    res = ''
    indent = 0
    for l in txt.split("\n"):
        l = l.strip()
        if l.startswith("}"):
            indent -= 1
            if 0 < indent:
                res += "INDENT ERROR"
        res += '    ' * indent + l + "\n"
        if l.endswith("{"):
            indent += 1
    return res
dataset/ETHPy150Open anandology/pyjamas/contrib/java2py.py/reindent/swapped operands of `<`