def test(self): """ Test the model loaded from model_file on data in data_file model_file: pkl file to read from data_file: pcap file to read from verbosity: verbosity """ self.method = Method(api=self.api, send_fn=self.send_to_monitor) self.method.load_model(self.model_file) self.monitor = Monitor(log_level=self.verbosity, send_fn=self.send_to_method, attack_type=self.attack_type) pkts = [] with open(self.data_file, 'rb') as f: pkts = pickle.load(f) self.monitor.create_test_data(pkts) self.monitor.send() start_time = time.time() # time out after 10 seconds while not self.monitor.completed(): sleep(.1) self.monitor.show_results() if self.out_file: pickle.dump(self.monitor.test_data, open(self.out_file, 'wb'))
def train(self): """ Train the model on data in data_file and save to model_file model_file: pkl file to write to data_file: pcap file to read from """ self.method = Method(api=self.api, send_fn=self.send_to_monitor) self.method.train_model(self.model_file, self.data_file, self.featurizer)
def add_main(self): main_cls = self.main_cls if any(main_cls.mtd_by_name(u"main")): return params = [(u"String[]", u"args")] main = Method(clazz=main_cls, mods=C.PBST, name=u"main", params=params) def to_call(mtd): return mtd.name + "();" body = '\n'.join(map(to_call, self.harness())) main.body = st.to_statements(main, body) main_cls.mtds.append(main)
def calculate(self): '''Функция заполнение таблицы ''' if __import__('re').findall('\d+? *?\+ *?\d+?', self.objectiv_func_edit.text()): pass else: print("[SECURITY] F**K YOU!") return self.result_table.setColumnCount(0) self.result_table.setRowCount(0) self.except_label.setText('') self.x1min = float(self.x1_min_edit.text()) self.x1max = float(self.x1_max_edit.text()) self.x2min = float(self.x2_min_edit.text()) self.x2max = float(self.x2_max_edit.text()) self.step = float(self.step_combBox.currentText()) self.function = str(self.objectiv_func_edit.text()) if self.x1min >= self.x1max or self.x2min >= self.x2max: self.except_label.setText( 'Минимальное значение больше максимального !') else: self.excpts = [] # достает существующие ограничения и вносит в список for expt in range(0, self.exeption_table.rowCount()): if self.exeption_table.item(expt, 0).text(): self.excpts.append( self.exeption_table.item(expt, 0).text()) self.method = Method(self.x1min, self.x2min, self.x1max, self.x2max, self.step, self.function, self.excpts) bool_matrix = self.method.boolean_matrix spis = self.method.spis self.result_table.setColumnCount(len(spis[0])) self.result_table.setRowCount(len(spis)) for i in range(len(spis)): for j in range(len(spis[i])): self.min(i, j, spis, bool_matrix) self.min_label.setText(str(self.method.min_needed()))
def method_perebor(self): method = Method(self.x1min, self.x2min, self.x1max, self.x2max, self.step, self.function, self.excpts) bool_matrix = method.boolean_matrix spis = method.spis self.result_table.setColumnCount(len(spis[0])) self.result_table.setRowCount(len(spis)) for i in range(len(spis)): for j in range(len(spis[i])): self.min(i, j, spis, bool_matrix) min_value_of_fuction, x1, x2 = method.min_needed() QtWidgets.QMessageBox.information( self, "Результат", "Минимум функции:\t{0}\n\tx1:\t{1}\n\tx2:\t{2}".format( min_value_of_fuction, x1, x2))
def makeMethods(analysis): objs = [] numMethods = 0 posMethods = [] for j in range( 0, len(analysis) ): #start with something that starts w def, ends when run into other def if "def" in analysis[j]: numMethods = numMethods + 1 posMethods.append(j) for i in range(0, numMethods): innerMethod = [] #strings of things in method tempName = "" tempArgs = [] if (i == numMethods - 1): end = len(analysis) else: end = posMethods[i + 1] - 1 for a in range(posMethods[i], end): if a == posMethods[i]: tempName = analysis[a][4] tempArgs = findArgs(tempName) else: if ("def" not in analysis[a][4]): innerMethod.append(analysis[a]) organizedInnerMethod = organizeInnerMethod(tempName, innerMethod) appendMeMethod = Method(tempName, tempArgs, organizedInnerMethod) appendMeMethod.setMethodsCalled(findMethods(organizedInnerMethod)) appendMeMethod.setBasicMethodsCalled( findBasicMethods(organizedInnerMethod)) appendMeMethod.setDocs( makeDocs(appendMeMethod, tempName, tempArgs, organizedInnerMethod)) objs.append(appendMeMethod) return objs
""" name = driver.find_element_by_class_name(api.nome).text message_content = driver.find_elements_by_class_name(api.chatdados)[-1] message = message_content.text.lower() if len(message) > 0: if (message == "/ping"): api.sendResponse(response='PONG') elif (message == "/img"): api.sendMedia(file=os.path.dirname(os.path.realpath(__file__)) + '/img/Prev.png') elif (message == "/doc"): api.sendDocument(file=os.path.dirname(os.path.realpath(__file__)) + '/main.py') except Exception as error: traceback.print_exc() pass driver.find_element_by_xpath(f"//span[@title='{contactorgroupname}']").click() api.waittemp(slp=1) if __name__ == '__main__': options = webdriver.ChromeOptions() options.add_argument("user-data-dir={}".format(os.path.join(os.getcwd(), "profile", "wpp"))) driver = webdriver.Chrome(executable_path='chromedriver', options=options) meth = Method(driver) meth.waittemp(temp=1) driver.get("https://web.whatsapp.com/") try: while True: whatsapp(driver, meth) except KeyboardInterrupt: print("\nClosing bot ...")
def actions(self, state, player): return list(set(Method(player, state[1], state[2], state[3], state[4])))
def method_init(variables): method = Method(variables, '', time(), scriptpath) return method