

def _parse_args(func, args, usage=None):
    'Parse the arguments given to a magic function'
    if isinstance(args, list):
        args = ' '.join(args)
    args = _split_args(args)
    kwargs = dict()
    if getattr(func, 'has_options', False):
        parser = MagicOptionParser(usage=usage)
        parser.add_options(func.options)
        left = []
        value = None
        if ('--' in args):
            left = args[:args.index('--')]
            (value, args) = parser.parse_args(args[(args.index('--') + 1):])
        else:
            while args:
                try:
                    (value, args) = parser.parse_args(args)
                except Exception:
                    left.append(args.pop(0))
                else:
                    break
        args = (left + args)
        if value:
            kwargs = value.__dict__
    new_args = []
    for arg in args:
        try:
            new_args.append(eval(arg))
        except:
            new_args.append(arg)
    for (key, value) in kwargs.items():
        try:
            kwargs[key] = eval(value)
        except:
            pass
    return (new_args, kwargs)

dataset/ETHPy150Open Calysto/metakernel/metakernel/magic.py _parse_args/original