Esempio n. 1
0
    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'
Esempio n. 2
0
    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'
Esempio n. 3
0
    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')
Esempio n. 4
0
    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)
Esempio n. 5
0
    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')
Esempio n. 6
0
    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)
Esempio n. 7
0
 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
Esempio n. 8
0
 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