import ast def process(node): exceptionHandlerLabel = "_" + ast.nextLabel() + "_handler" #ast.setFinally( exceptionHandlerLabel ) ast.outputInBlock("push_eh %s" % ( exceptionHandlerLabel ) ) ast.evaluate( node.body ) ast.outputInBlock("clear_eh" ) #ast.setFinally( "" ) ast.outputLabel( exceptionHandlerLabel ) ast.evaluate( node.final )