def process_msg_from_client(self, recvd_msg): function_from_cmd = recvd_msg[ "cmd"] # takes function arguments from received dict unique_id = recvd_msg["id"] # takes unique_id from receieved dict # checks if function is print; if so, then take the text from the received dict if (function_from_cmd == "print"): text = recvd_msg["text"] # print's argument # text length will always be > 0; if text length == 1, # then make text into string rather than a list. if (len(text) == 1): text = text[0] print("Printing " + str(text)) response_dict = { 'status': 'success', 'result': text, 'id': unique_id } elif (function_from_cmd == "set"): functions.set(recvd_msg["key"], recvd_msg["val"]) response_dict = {'status': 'success', 'id': unique_id} elif (function_from_cmd == "get"): result = functions.get(recvd_msg["key"]) if (result is None): response_dict = { 'status': 'fail', 'result': result, 'id': unique_id } else: response_dict = { 'status': 'success', 'result': result, 'id': unique_id } elif (function_from_cmd == "query_all_keys"): result = functions.query_all_keys() if (result is None): response_dict = { 'status': 'fail', 'result': result, 'id': unique_id } else: response_dict = { 'status': 'success', 'result': result, 'id': unique_id } else: print("Rejecting RPC request because function is unknown.") return response_dict
def test_set(self): functions.rpc_dict = {} key = 'dog' value = 'happy' functions.set(key, value) self.assertEqual(functions.rpc_dict, {key: value}) key = 'dog' value = 'sad' functions.set(key, value) self.assertEqual(functions.rpc_dict, {key: value}) key = 'cat' value = 'ambivalent' functions.set(key, value) self.assertTrue(key in functions.rpc_dict) self.assertEqual(functions.rpc_dict[key], value)
getobfs_param = form['setobfs_param'].value else: getobfs_param = "" if form.has_key('setspeed_limit_per_con'): getspeed_limit_per_con = form['setspeed_limit_per_con'].value else: getspeed_limit_per_con = 0 if form.has_key('setspeed_limit_per_user'): getspeed_limit_per_user = form['setspeed_limit_per_user'].value else: getspeed_limit_per_user = 0 functions.set(getport, getpassword, getmethod, getprotocol, getprotocol_param, getobfs, getobfs_param, getspeed_limit_per_user, getspeed_limit_per_con) html = ''' <nav class="navbar navbar-default"> <div class="container-fluid"> <!-- Brand and toggle get grouped for better mobile display --> <div class="navbar-header"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" href="#">SWEB管理面板</a></div> <!-- Collect the nav links, forms, and other content for toggling --> <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> <ul class="nav navbar-nav"> <li> <a href="#" data-toggle="dropdown" >SSR<b class="caret"></b></a>