Example #1
0
 def exec_code(self, code):
     try:
         self.count += 1
         code = re.sub(r'«', '<<', code)
         if self.pinterp is None:
             self.pinterp = pipes3.init_cling()
         pinterp = self.pinterp
         caller = inspect.stack()[-1][0].f_globals
         code = replvar(code, caller)
         #history += [code]
         pinterp.stdin.write(code + "$delim$\n")
         pinterp.stdin.flush()
         out = pipes3.read_output(pinterp, pinterp.stdout)
         err = pipes3.read_output(pinterp, pinterp.stderr)
         if "Segfault or Fatal error" in out[0]:
             pinterp.wait()
             self.pinterp = pipes3.init_cling()
             self.count = 1
             pinter = self.pinterp
             out += ["Server Restart"]
             #prev_history = history
             #history = []
         res = out + err
         #res = {"out":out[0], "err":err[0], "type":None}
         #color_text("#f8f8ff",out[0])
         #if len(out) > 1:
         #    color_text("#eeffee",out[1])
         #    res["type"] = out[1]
     except Exception as e:
         print_exc()
         res = [str(e)]
     #color_text("#ffcccc",err[0])
     #if line2 is not None:
     #    caller[line2.strip()] = res
     return res
Example #2
0
def cling(line, code):
    global pinterp, history, prev_history
    if line is None:
        line2 = None
    else:
        line2 = re.sub(r'--init\b', '', line)
    if pinterp is None:
        pinterp = pipes3.init_cling()
    elif line != line2:
        pinterp = pipes3.init_cling()
    try:
        caller = inspect.stack()[2][0].f_globals
        code = replvar(code, caller)
        history += [code]
        pinterp.stdin.write(code + "$delim$\n")
        pinterp.stdin.flush()
        out = pipes3.read_output(pinterp, pinterp.stdout)
        err = pipes3.read_output(pinterp, pinterp.stderr)
        if "Segfault or Fatal error" in out[0]:
            pinterp.wait()
            pinterp = pipes3.init_cling()
            prev_history = history
            history = []
        res = {"out": out[0], "err": err[0], "type": None}
        color_text("#f8f8ff", out[0])
        if len(out) > 1:
            color_text("#eeffee", out[1])
            res["type"] = out[1]
        color_text("#ffcccc", err[0])
        if line2 is not None:
            caller[line2.strip()] = res
    except Exception as e:
        print(e)
Example #3
0
def cling(line, code):
    global pinterp, history, prev_history, results
    if line is None:
        line2 = None
    else:
        line2 = re.sub(r'--init\b', '', line)
    if pinterp is None:
        pinterp = pipes3.init_cling()
    elif line != line2:
        pinterp = pipes3.init_cling()
    try:
        #istack = inspect.stack()
        # Figure out where in the stack the symbol is supposed to go
        #for i in range(len(istack)):
        #    print("stack:",i,istack[i][0].f_globals.get("foo","UNDEF"))
        #if len(istack) > 2:
        #    caller = istack[2][0].f_globals
        #else:
        #    caller = {}
        code = replvar(code, results)
        history += [code]
        pinterp.stdin.write(code + delim + "\n")
        pinterp.stdin.flush()
        out = pipes3.read_output(pinterp, pinterp.stdout)
        err = pipes3.read_output(pinterp, pinterp.stderr)
        if "Segfault or Fatal error" in out[0]:
            pinterp.wait()
            pinterp = pipes3.init_cling()
            prev_history = history
            history = []
        res = {"out": out[0], "err": err[0], "type": None}
        color_text("#f8f8ff", out[0])
        if len(out) > 1:
            color_text("#eeffee", out[1])
            res["type"] = out[1]
        color_text("#ffcccc", err[0])
        if line2 is not None:
            results[line2.strip()] = res
    except Exception as e:
        print_exc()
Example #4
0
def replay(n=-1):
    global prev_history, history, pinterp
    for cmd in prev_history[0:n]:
        history += [cmd]
        color_text("#eeeeee", "replaying: " + cmd)
        pinterp.stdin.write(cmd + '$delim$\n')
        pinterp.stdin.flush()
        out = pipes3.read_output(pinterp, pinterp.stdout)
        err = pipes3.read_output(pinterp, pinterp.stderr)
        color_text("#f8f8ff", out[0])
        color_text("#ffcccc", err[0])
        if "Segfault or Fatal error" in out[0]:
            pinterp.wait()
            pinterp = pipes3.init_cling()
Example #5
0
        pinterp.stdin.write(src + '$delim$\n')
        pinterp.stdin.flush()
        out = join(pipes3.read_output(pinterp, pinterp.stdout))
        err = join(pipes3.read_output(pinterp, pinterp.stderr))
        print("src:", colored(src, "cyan"))
        if "ASSERTION FAILURE" in err:
            print("out:", colored(out, "yellow"))
            print("err:", colored(err, "red"))
            print(colored("FAILED", "red"))
            exit(1)
        else:
            print(colored("PASSED", "green"))
    elif type(jdata) == dict:
        for k in jdata:
            jd = jdata[k]
            process(jd, key=k)
    elif type(jdata) in [str, int]:
        pass
    else:
        print("info:", type(jdata), jdata, key)
        raise Exception()


for a in sys.argv[1:]:
    with open(a, "r") as fd:
        print(colored("Testing file:" + a, "magenta"))
        pinterp = pipes3.init_cling()
        jdata = json.loads(fd.read().strip())
        process(jdata)
print(colored("ALL TESTS PASSSED", "green"))