def read_and_rewrite(path): try: content = file(path, 'r').read() lexer = RoughLexer(StringIO(content)) io = StringIO() converter = Converter(lexer, io, run_funcname='zsh.run') converter.convert(False) return io.getvalue() except: return None
def scan_and_convert(): lexer = ZshRoughLexer() tokens = [] for token in lexer: indent = token[0] if not indent and token[1] == 'python' and is_python_expr(token[2]): token = (token[0], token[1], 'print ' + token[2]) tokens.append(token) if not indent and zsh.native.cvar.curindentwidth == 0: break io = StringIO() converter = Converter(tokens, io, run_funcname='zsh.run') converter.convert(False) return io.getvalue()