Esempio n. 1
0
def eval_(ast):
    if isinstance(ast, str):
        ast = parse(ast, '<eval>')

    if isinstance(ast, Quote):
        ast = ast.body

    return Sequence(*config.instance.eval(ast, first=True))
Esempio n. 2
0
 def run(self, context, args, kwargs, opargs):
     if len(args) == 0:
         raise CommandException(_("Please provide a filename. For help see 'help <command>'"))
     else:
         for arg in args:
             arg = os.path.expanduser(arg)
             if os.path.isfile(arg):
                 try:
                     with open(arg, 'rb') as f:
                         ast = parse(f.read().decode('utf8'), arg)
                         context.eval_block(ast)
                 except UnicodeDecodeError as e:
                     raise CommandException(_(
                         "Incorrect filetype, cannot parse file: {0}".format(str(e))
                     ))
             else:
                 raise CommandException(_("File {0} does not exist.".format(arg)))
Esempio n. 3
0
 def parse(self, code):
     return dump_ast(parse(code, '<remote eval>'))
Esempio n. 4
0
 def eval_code(self, code, user):
     ast = parse(code, '<remote eval>')
     return self.context.ml.eval(ast)
def eval_(line):
    return config.instance.eval(parse(line, '<stdin>'))