def push(self, line): """Pushes a line onto the buffer and compiles the code in a way that enables multiline input. """ self.buffer.append(line) if self.need_more_lines: return None, None src = ''.join(self.buffer) src = fire_precommand(src) return self.compile(src)
def can_compile(src): """Returns whether the code can be compiled, i.e. it is valid xonsh.""" src = src if src.endswith('\n') else src + '\n' src = fire_precommand(src, show_diff=False) src = src.lstrip() try: builtins.__xonsh_execer__.compile(src, mode='single', glbs=None, locs=builtins.__xonsh_ctx__) rtn = True except SyntaxError: rtn = False except Exception: rtn = True return rtn