def call_magic(self, mtype, name, code, args):
        self.code = code
        old_args = args
        mtype = mtype.replace('sticky', 'cell')

        func = getattr(self, mtype + '_' + name)
        try:
            args, kwargs = _parse_args(func, args, usage=self.get_help(mtype, name))
        except Exception as e:
            self.kernel.Error(str(e))
            return self

        arg_spec = inspect.getargspec(func)
        fargs = arg_spec.args
        if fargs[0] == 'self':
            fargs = fargs[1:]

        fargs = [f for f in fargs if not f in kwargs.keys()]
        if len(args) > len(fargs) and not arg_spec.varargs:
            extra = ' '.join(str(s) for s in (args[len(fargs) - 1:]))
            args = args[:len(fargs) - 1] + [extra]

        try:
            try:
                func(*args, **kwargs)
            except __HOLE__:
                func(old_args)
        except Exception as exc:
            msg = "Error in calling magic '%s' on %s:\n    %s\n    args: %s\n    kwargs: %s" % (
                name, mtype, str(exc), args, kwargs)
            self.kernel.Error(msg)
            self.kernel.Error(traceback.format_exc())
            self.kernel.Error(self.get_help(mtype, name))
            # return dummy magic to end processing:
            return Magic(self.kernel)
        return self
dataset/ETHPy150Open Calysto/metakernel/metakernel/magic.py/Magic.call_magic