def default(self, line): """Implements code execution.""" line = line if line.endswith('\n') else line + '\n' src, code = self.push(line) if code is None: return hist = builtins.__xonsh_history__ # pylint: disable=no-member ts1 = None store_stdout = builtins.__xonsh_env__.get('XONSH_STORE_STDOUT') # pylint: disable=no-member tee = Tee() if store_stdout else io.StringIO() try: ts0 = time.time() run_compiled_code(code, self.ctx, None, 'single') ts1 = time.time() if hist.last_cmd_rtn is None: hist.last_cmd_rtn = 0 # returncode for success except XonshError as e: print(e.args[0], file=sys.stderr) if hist.last_cmd_rtn is None: hist.last_cmd_rtn = 1 # return code for failure except Exception: # pylint: disable=broad-except print_exception() if hist.last_cmd_rtn is None: hist.last_cmd_rtn = 1 # return code for failure finally: ts1 = ts1 or time.time() self._append_history(inp=src, ts=[ts0, ts1], tee_out=tee.getvalue()) tee.close() if builtins.__xonsh_exit__: # pylint: disable=no-member return True
def default(self, line): """Implements code execution.""" line = line if line.endswith('\n') else line + '\n' src, code = self.push(line) if code is None: return env = builtins.__xonsh_env__ hist = builtins.__xonsh_history__ # pylint: disable=no-member ts1 = None enc = env.get('XONSH_ENCODING') err = env.get('XONSH_ENCODING_ERRORS') tee = Tee(encoding=enc, errors=err) try: ts0 = time.time() run_compiled_code(code, self.ctx, None, 'single') ts1 = time.time() if hist is not None and hist.last_cmd_rtn is None: hist.last_cmd_rtn = 0 # returncode for success except XonshError as e: print(e.args[0], file=sys.stderr) if hist is not None and hist.last_cmd_rtn is None: hist.last_cmd_rtn = 1 # return code for failure except Exception: # pylint: disable=broad-except print_exception() if hist is not None and hist.last_cmd_rtn is None: hist.last_cmd_rtn = 1 # return code for failure finally: ts1 = ts1 or time.time() self._append_history(inp=src, ts=[ts0, ts1], tee_out=tee.getvalue()) tee.close() self._fix_cwd() if builtins.__xonsh_exit__: # pylint: disable=no-member return True
def default(self, line, raw_line=None): """Implements code execution.""" line = line if line.endswith("\n") else line + "\n" if not self.need_more_lines: # this is the first line if not raw_line: self.src_starts_with_space = False else: self.src_starts_with_space = raw_line[0].isspace() src, code = self.push(line) if code is None: return events.on_precommand.fire(cmd=src) env = XSH.env hist = XSH.history # pylint: disable=no-member ts1 = None enc = env.get("XONSH_ENCODING") err = env.get("XONSH_ENCODING_ERRORS") tee = Tee(encoding=enc, errors=err) ts0 = time.time() try: run_compiled_code(code, self.ctx, None, "single") ts1 = time.time() if hist is not None and hist.last_cmd_rtn is None: hist.last_cmd_rtn = 0 # returncode for success except XonshError as e: print(e.args[0], file=sys.stderr) if hist is not None and hist.last_cmd_rtn is None: hist.last_cmd_rtn = 1 # return code for failure except Exception: # pylint: disable=broad-except print_exception() if hist is not None and hist.last_cmd_rtn is None: hist.last_cmd_rtn = 1 # return code for failure finally: ts1 = ts1 or time.time() tee_out = tee.getvalue() self._append_history( inp=src, ts=[ts0, ts1], spc=self.src_starts_with_space, tee_out=tee_out, cwd=self.precwd, ) self.accumulated_inputs += src if ( tee_out and env.get("XONSH_APPEND_NEWLINE") and not tee_out.endswith(os.linesep) ): print(os.linesep, end="") tee.close() self._fix_cwd() if XSH.exit: # pylint: disable=no-member return True
def default(self, line): """Implements code execution.""" line = line if line.endswith("\n") else line + "\n" src, code = self.push(line) if code is None: return events.on_precommand.fire(cmd=src) env = builtins.__xonsh__.env hist = builtins.__xonsh__.history # pylint: disable=no-member ts1 = None enc = env.get("XONSH_ENCODING") err = env.get("XONSH_ENCODING_ERRORS") tee = Tee(encoding=enc, errors=err) try: ts0 = time.time() run_compiled_code(code, self.ctx, None, "single") ts1 = time.time() if hist is not None and hist.last_cmd_rtn is None: hist.last_cmd_rtn = 0 # returncode for success except XonshError as e: print(e.args[0], file=sys.stderr) if hist is not None and hist.last_cmd_rtn is None: hist.last_cmd_rtn = 1 # return code for failure except Exception: # pylint: disable=broad-except print_exception() if hist is not None and hist.last_cmd_rtn is None: hist.last_cmd_rtn = 1 # return code for failure finally: ts1 = ts1 or time.time() tee_out = tee.getvalue() self._append_history(inp=src, ts=[ts0, ts1], tee_out=tee_out) self.accumulated_inputs += src if ( tee_out and env.get("XONSH_APPEND_NEWLINE") and not tee_out.endswith(os.linesep) ): print(os.linesep, end="") tee.close() self._fix_cwd() if builtins.__xonsh__.exit: # pylint: disable=no-member return True
def default(self, line): """Implements code execution.""" line = line if line.endswith("\n") else line + "\n" src, code = self.push(line) if code is None: return events.on_precommand.fire(cmd=src) env = builtins.__xonsh_env__ hist = builtins.__xonsh_history__ # pylint: disable=no-member ts1 = None enc = env.get("XONSH_ENCODING") err = env.get("XONSH_ENCODING_ERRORS") tee = Tee(encoding=enc, errors=err) try: ts0 = time.time() run_compiled_code(code, self.ctx, None, "single") ts1 = time.time() if hist is not None and hist.last_cmd_rtn is None: hist.last_cmd_rtn = 0 # returncode for success except XonshError as e: print(e.args[0], file=sys.stderr) if hist is not None and hist.last_cmd_rtn is None: hist.last_cmd_rtn = 1 # return code for failure except Exception: # pylint: disable=broad-except print_exception() if hist is not None and hist.last_cmd_rtn is None: hist.last_cmd_rtn = 1 # return code for failure finally: ts1 = ts1 or time.time() tee_out = tee.getvalue() self._append_history(inp=src, ts=[ts0, ts1], tee_out=tee_out) self.accumulated_inputs += src if (tee_out and env.get("XONSH_APPEND_NEWLINE") and not tee_out.endswith(os.linesep)): print(os.linesep, end="") tee.close() self._fix_cwd() if builtins.__xonsh_exit__: # pylint: disable=no-member return True