當前位置: 首頁>>代碼示例>>Python>>正文


Python Function.search_file方法代碼示例

本文整理匯總了Python中Function.search_file方法的典型用法代碼示例。如果您正苦於以下問題:Python Function.search_file方法的具體用法?Python Function.search_file怎麽用?Python Function.search_file使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Function的用法示例。


在下文中一共展示了Function.search_file方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: run

# 需要導入模塊: import Function [as 別名]
# 或者: from Function import search_file [as 別名]

#.........這裏部分代碼省略.........
							else:
								func.write_daemon_error(self.name, addr[0], "ADD FILE - User not logged")

					elif str(ricevutoByte[0:4], "ascii") == const.CODE_REMOVEFILE:
						if self.SN:
							if func.isUserLogged(ricevutoByte[4:20], self.listUsers):
								findFile = False
								i = 0
								for file in self.listFiles:
									if (ricevutoByte[4:20] == file[2]) and (ricevutoByte[20:] == file[0]):
										findFile = True
										del self.listFiles[i]
										func.write_daemon_success(self.name, addr[0], "REMOVE FILE: " + str(ricevutoByte[20:], "ascii").strip())
										i -= 1
									i += 1
								if not findFile:
									func.write_daemon_error(self.name, addr[0], "REMOVE FILE - File not exists")
							else:
								func.write_daemon_error(self.name, addr[0], "REMOVE FILE - User not logged")

					elif str(ricevutoByte[0:4], "ascii") == const.CODE_LOGOUT: ### LOGOUT
						if self.SN:
							i = 0
							for user in self.listUsers:
								if ricevutoByte[4:] == user[2]:
									del user

							nDelete = 0
							for file in self.listFiles:
								if ricevutoByte[4:] == file[2]:
									del self.listFiles[i]
									nDelete += 1
									i -= 1
								i += 1

							pk = pack.answer_logout(nDelete)
							conn.sendall(pk)
							func.write_daemon_success(self.name, addr[0], "LOGOUT OK")


					elif str(ricevutoByte[0:4], "ascii") == const.CODE_QUERY: ### QUERY tra SN
						func.write_daemon_text(self.name, addr[0], "QUERY - " + func.reformat_string(str(ricevutoByte[82:],"ascii")))
						if func.add_pktid(ricevutoByte[4:20], self.listPkt, self.port) is True:
							# Inoltro
							pk = pack.forward_query(ricevutoByte)
							func.forward(pk, addr[0], self.sn_network)

							# Rispondi
							listFileFounded = []
							listFileFounded = func.search_file(bytes(func.reformat_string(str(ricevutoByte[82:],"ascii")),"ascii"), self.listFiles, self.listUsers) # Da controllare
							if len(listFileFounded) != 0:
								for x in listFileFounded:
									pk = pack.answer_query(ricevutoByte[4:20], x[2], x[3], str(x[0], "ascii"), str(x[1], "ascii"))
									sC = func.create_socket_client(func.roll_the_dice(str(ricevutoByte[20:75], "ascii")), ricevutoByte[75:80])
									if sC != None:
										sC.sendall(pk)
										sC.close()
						#else:
						#	func.write_daemon_error(self.name, addr[0], "Pacchetto già ricevuto")

					elif str(ricevutoByte[0:4], "ascii") == const.CODE_ANSWER_QUERY: ### RISPOSTA QUERY tra SN
						if func.check_query(ricevutoByte[4:20], self.listPkt, self.port):
							listResultQuery.append([ricevutoByte[80:112], ricevutoByte[112:], ricevutoByte[20:75], ricevutoByte[75:80]])
						else: 
							func.write_daemon_error(self.name, addr[0], "ANSWER QUERY - Ricerca conclusa")
					
					elif str(ricevutoByte[0:4], "ascii") == const.CODE_DOWNLOAD: ### DOWNLOAD
						func.write_daemon_text(self.name, addr[0], "UPLOAD")
						filef = func.find_file_by_md5(ricevutoByte[4:])
						if filef != const.ERROR_FILE:
							func.upload(filef, conn)

					elif(str(ricevutoByte[0:4], "ascii") == const.CODE_SEARCH): ### Richiesta di ricerca da un peer
						if self.SN:
							del listResultQuery[:]
							func.write_daemon_text(self.name, addr[0], "INIZIO RICERCA DI: " + str(ricevutoByte[20:], "ascii").strip())
							pk = pack.query(self.host, ricevutoByte[20:])
							func.add_pktid(pk[4:20], self.listPkt, self.port)

							for x in self.sn_network:
								sNet = func.create_socket_client(func.roll_the_dice(x[0]), x[1])
								if sNet != None:
									sNet.sendall(pk)
									sNet.close()

							listaRisultatiDellaQuery = []
							listaRisultatiDellaQuery = func.search_file(bytes(str(ricevutoByte[20:],"ascii").strip(),"ascii"), self.listFiles, self.listUsers)
							for x in listaRisultatiDellaQuery:
								listResultQuery.append(x)


							#func.send_afin(conn, self.listResultQuery)

							daemonAfin = threading.Thread(target=sendAfin, args=(conn, ))
							daemonAfin.start()

							#t = Timer(int(const.MAX_TIME / 1000), func.send_afin, (conn, self.listResultQuery))
					else:
						func.write_daemon_error(self.name, addr[0], "Ricevuto pacchetto sbagliato: " + str(ricevutoByte, "ascii"))
			s.close()
開發者ID:tommasoberlose,項目名稱:p2p_kazaa,代碼行數:104,代碼來源:Daemon.py


注:本文中的Function.search_file方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。