def test_no_msg(self): try: raise RuntimeError except Exception as ex: exc = ex assert exc_to_str(exc) == 'RuntimeError' assert exc_to_str(exc, True) == 'RuntimeError'
def test_regular(self): try: 123 / 0 except Exception as ex: exc = ex assert exc_to_str(exc) == 'division by zero' assert exc_to_str(exc, True) == 'ZeroDivisionError: division by zero'
def cmd_vars(self): """Call vars(<TARGET>) and show all the results. See also 'VarsPublic' command. """ target = self.ctx.target try: v = vars(target) except Exception as ex: raise CommandError(exc_to_str(ex)) content = self.ctx.mgr.propose_attr(v.keys(), v.values()) self.ctx.explorer.fill(content, 'attr')
def cmd_items(self, offset): """Call <TARGET>.items() and iterate through results. This can be used for listing keys and values of the dictionary. Optional <OFFSET> can be used for skipping certain number of entires. """ target = self.ctx.target try: keys = target.keys() except Exception as ex: raise CommandError(exc_to_str(ex)) try: content = self.ctx.mgr.propose_subscr(keys) except: raise CommandError("Error while obtaining items to iterate.") self.ctx.explorer.fill(content, 'dict', offset)
def cmd_vars_public(self): """Call vars(<TARGET>) and show results other than starting with '_'. See also 'Vars' command. """ target = self.ctx.target try: v = vars(target) except Exception as ex: raise CommandError(exc_to_str(ex)) items = ((k, v) for k,v in vars(target).items() if isaccess(k).public) try: keys, values = zip(*items) except ValueError: keys, values = (), () content = self.ctx.mgr.propose_attr(keys, values) self.ctx.explorer.fill(content, 'attr')
def cmd_eval(self, expr): """Evaluate <EXPR> and print the result. Empty <EXPR> will paste expression of current target and let you edit it. See also '$<EXPR>' command. """ expr = expr.strip() if expr: try: try: result = self.ctx.eval_(expr) print(repr(result)) except SyntaxError: self.ctx.exec_(expr) except Exception as ex: raise CommandError(exc_to_str(ex, show_type=True)) from ex terminal.update_suggestions(self.ctx.env.current) else: expr = dialect.Evaluable().stringify(self.ctx.mgr.selected) terminal.prefill_input('!' + expr)
def evaluate(self, prev, ctx): try: value = ctx.eval_(self.expr) except SyntaxError as ex: raise CommandError(exc_to_str(ex, show_type=True)) from ex return value
def evaluate(self, prev, ctx): try: value = ctx.eval_(f"_[{self.expr}]") except Exception as ex: raise CommandError(exc_to_str(ex, show_type=True)) from ex return value