def sendRequestBlock(): with registerThread(connection): main = slave.mainObject() if slave.requestBlock(main, {"number": 3}, "requestBlock", None, True, slave.IP, False): return "OK" return "Error"
def init(): with registerThread(connection): with open("top_secret_data.pkl", "rb") as pfile: data = pickle.load(pfile) if slave.initKey(data[slave.name][0], data[slave.mainObject().name]): return "OK" return "Error"
def init(): with registerThread(connection): res = main.firstInit() if res == {}: return "Error" print(res) with open("top_secret_data.pkl", "wb") as pfile: pickle.dump(res, pfile) return "OK"
def objectTurned(): with registerThread(connection): return main.objectTurned(request.form)
def sendBlock(): with registerThread(connection): return main.sendBlocks(request.form)
def shareBlock(): with registerThread(connection): if main.shareBlock(): return "OK" return "Error"
def requestKeys(): with registerThread(connection): if main.requestNewKeys(): return "OK" return "Error"
def wrapper(self, obj, data, where, resp, thread, other, check): if other is None: data = {"data": self.createMsg(data)} else: data = {"data": self.createMsg(data), "other": other} if thread: with registerThread(self.connection): response = None try: response = requests.post("http://" + obj.IP + "/" + where, data=data) except requests.exceptions.RequestException as e: self.alert("Connection error with object. " + str(e), 5, obj) return except requests.exceptions.HTTPError as e: self.alert("Connection error with object. " + str(e), 5, obj) return lock = Lock() with lock: print(response.text) if response.status_code != 200: self.alert( "Status code error: %d" % response.status_code, 6, obj) return if check: resp = obj.checkMsg(response.text) else: resp = response.text return procces_func(self, obj, data, where, resp, thread, other, check) else: response = None try: response = requests.post("http://" + obj.IP + "/" + where, data=data) except requests.exceptions.RequestException as e: self.alert("Connection error with object. " + str(e), 5, obj) return except requests.exceptions.HTTPError as e: self.alert("Connection error with object. " + str(e), 5, obj) return print(response.text) if response.status_code != 200: self.alert("Status code error: %d" % response.status_code, 6, obj) return if check: resp = obj.checkMsg(response.text) else: resp = response.text return procces_func(self, obj, data, where, resp, thread, other, check)
def turnOn(): with registerThread(connection): if slave.turn(on=True): return "OK" return "Error"
def turnOff(): with registerThread(connection): if slave.turn(on=False): return "OK" return "Error"
def requestNewKey(): with registerThread(connection): return slave.generateNewKeys(request.form)
def updateBlock(): with registerThread(connection): return slave.updateBlock(request.form)