Example #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
Example #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
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()
Example #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()
Example #5
0
def dbUnRepr(s): return binstruct.varDecode(s)


# Structure of the database:
#	There is the main song db songs.db:
#		songId -> song dict
#	songId is any random string, not too long but long enough to avoid >99.999% collisions.
#	song dict can contains (specified in code by global Attribs dict later):
#		artist: str
#		title: str
#		album: str
#		tags: weighted tagmap, dict tag->[0,1]
#		rating: float in [0,1]
#		files: dict filename -> dict with entries:
#			sha1: str
#			metadata: dict
#			fingerprint_AcoustId: str
#			gain: float
#   values should only be stored if they are certain with best accurary

class DB:
Example #6
0
def dbUnRepr(s):
    return binstruct.varDecode(s)
Example #7
0
def dbUnRepr(s): return binstruct.varDecode(s)


class DB(object):
Example #8
0
def dbUnRepr(s): return binstruct.varDecode(s)



class Cache:
Example #9
0
def dbUnRepr(s):
    return binstruct.varDecode(s)
Example #10
0
def dbUnRepr(s): return binstruct.varDecode(s)


class DB(object):
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
Example #12
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