示例#1
0
def _remoteExec(execStr):
	global f, idx
	idx += 1
	f.write(binstruct.varEncode((idx, execStr)).tostring())
	f.flush()

	answeridx,answertype,answerret = binstruct.varDecode(f)
	assert answeridx == idx
	return answertype, answerret
示例#2
0
def _remoteExec(execStr):
    global f, idx
    idx += 1
    f.write(binstruct.varEncode((idx, execStr)).tostring())
    f.flush()

    answeridx, answertype, answerret = binstruct.varDecode(f)
    assert answeridx == idx
    return answertype, answerret
示例#3
0
def _handleConnection(conn):
    conn.setblocking(True)
    f = conn.makefile()

    binstruct.write(f, (appinfo.appid, "SocketControl", 0.1))
    f.flush()
    try:
        clientappid, clientname, clientver, clientstatus = binstruct.read(f)
    except binstruct.FormatError:
        print "socketcontrol.handleConnection: wrong signature"
        return
    if clientstatus != "ok":
        print "socketcontrol.handleConnection: status returned %s" % status
        return

    from State import state
    from queue import queue
    shellGlobals = {
        "state": state,
        "queue": queue,
    }
    globals = locals = shellGlobals
    COMPILE_STRING_FN = "<socketcontrol input>"

    while True:
        try:
            idx, s = binstruct.varDecode(f)
        except Exception:
            # probably closed
            return
        assert isinstance(s, (str, unicode))

        try:
            c = utils.interactive_py_compile(s, COMPILE_STRING_FN)
        except Exception as e:
            answer = (idx, "compile-exception", (e.__class__.__name__, str(e)))
        else:
            try:
                ret = eval(c, globals, locals)
            except Exception as e:
                answer = (idx, "eval-exception", (e.__class__.__name__,
                                                  str(e)))
            else:
                if ret is not None:
                    try:
                        ret = repr(ret)
                    except Exception as e:
                        ret = "<repr exception: %s: %s>" % (
                            e.__class__.__name__, str(e))
                answer = (idx, "return", ret)

        f.write(binstruct.varEncode(answer).tostring())
        f.flush()
示例#4
0
def _handleConnection(conn):
	conn.setblocking(True)
	f = conn.makefile()

	binstruct.write(f, (appinfo.appid, "SocketControl", 0.1))
	f.flush()
	try:
		clientappid,clientname,clientver,clientstatus = binstruct.read(f)
	except binstruct.FormatError:
		print "socketcontrol.handleConnection: wrong signature"
		return	
	if clientstatus != "ok":
		print "socketcontrol.handleConnection: status returned %s" % status
		return
	
	from State import state
	from queue import queue
	shellGlobals = {
		"state": state,
		"queue": queue,
		}
	globals = locals = shellGlobals
	COMPILE_STRING_FN = "<socketcontrol input>"
		
	while True:
		try:
			idx,s = binstruct.varDecode(f)
		except Exception:
			# probably closed
			return
		assert isinstance(s, (str,unicode))
		
		try:
			c = utils.interactive_py_compile(s, COMPILE_STRING_FN)
		except Exception as e:
			answer = (idx, "compile-exception", (e.__class__.__name__, str(e)))
		else:
			try:
				ret = eval(c, globals, locals)
			except Exception as e:
				answer = (idx, "eval-exception", (e.__class__.__name__, str(e)))
			else:
				if ret is not None:
					try:
						ret = repr(ret)
					except Exception as e:
						ret = "<repr exception: %s: %s>" % (e.__class__.__name__, str(e))
				answer = (idx, "return", ret)
		
		f.write(binstruct.varEncode(answer).tostring())
		f.flush()
示例#5
0
def dbRepr(o):
    return binstruct.varEncode(o).tostring()
示例#6
0
def dbRepr(o): return binstruct.varEncode(o).tostring()
def dbUnRepr(s): return binstruct.varDecode(s)
示例#7
0
def dbRepr(o):
    return binstruct.varEncode(o).tostring()
示例#8
0
def dbRepr(o): return binstruct.varEncode(o).tostring()
def dbUnRepr(s): return binstruct.varDecode(s)
binstruct.write(f, (appinfo.appid, "SocketControl-InteractiveClient", 0.1, "ok"))
f.flush()

try: import readline
except ImportError: pass # ignore

idx = 0
while True:
	idx += 1
	try: s = raw_input("> ")
	except (KeyboardInterrupt,EOFError):
		print("")
		sys.exit(0)
	
	if s.strip() == "": continue
	f.write(binstruct.varEncode((idx, s)).tostring())
	f.flush()
	
	answeridx,answertype,answerret = binstruct.varDecode(f)
	assert answeridx == idx
	if answertype == "compile-exception":
		print("%s : %s in %r" % (answerret[0], answerret[1], s))
	elif answertype == "eval-exception":
		print("Exception %s : %s" % (answerret[0], answerret[1]))
	elif answertype == "return":
		if answerret is not None:
			print(answerret)
	else:
		assert False, "%s unknown" % answertype
示例#10
0
f.flush()

try:
    import readline
except ImportError:
    pass  # ignore

idx = 0
while True:
    try:
        s = raw_input("> ")
    except (KeyboardInterrupt, EOFError):
        print("")
        sys.exit(0)

    if s.strip() == "": continue
    f.write(binstruct.varEncode((idx, s)).tostring())
    f.flush()

    answeridx, answertype, answerret = binstruct.varDecode(f)
    assert answeridx == idx
    if answertype == "compile-exception":
        print("%s : %s in %r" % (answerret[0], answerret[1], s))
    elif answertype == "eval-exception":
        print("Exception %s : %s" % (answerret[0], answerret[1]))
    elif answertype == "return":
        if answerret is not None:
            print(answerret)
    else:
        assert False, "%s unknown" % answertype