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


Python Function.reverse_format_string方法代碼示例

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


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

示例1: search

# 需要導入模塊: import Function [as 別名]
# 或者: from Function import reverse_format_string [as 別名]
def search(sessionID, query, SN, SN_host, host, listPkt):
	ricevutoByteRam = b''
	ricevutoByte = b''
	pk = pack.request_search(sessionID, query)
	s = func.create_socket_client(func.roll_the_dice(SN_host[0]), SN_host[1]);
	if s is None:
		func.error("Super nodo non attivo.")
		update_network(host, SN, listPkt)
	else:
		s.sendall(pk)

		ricevutoByte = s.recv(4 * const.LENGTH_PACK)

		if str(ricevutoByte[0:4],"ascii") == const.CODE_ANSWER_SEARCH:
			print(ricevutoByte)
			nIdmd5 = int(ricevutoByte[4:7])
			if(nIdmd5 != 0):
				func.success("Ricerca completata.")
				pointer = 7
				id = 0
				listFile = []
				for j in range(0, nIdmd5):
					md5 = ricevutoByte[pointer:pointer + 32]
					nomeFile = ricevutoByte[pointer + 32:pointer + 132]
					nCopy = int(ricevutoByte[pointer + 132:pointer + 135])

					pointer = pointer + 135

					for i in range(0, nCopy):
						ip = ricevutoByte[pointer:pointer + 55]
						port = ricevutoByte[pointer + 55:pointer + 60]
						id = id + 1
						pointer = pointer + 60
						fixList = [id, md5, nomeFile, ip, port]
						listFile.append(fixList)
						
				print("\nScegli file da quelli disponibili (0 per uscire): \n")
				print("FILE    \t\tID\tIP\n")
				lastFileName = b''
				for row in listFile:
					if lastFileName != row[2]:
						nomeFile = func.reverse_format_string((str(row[2], "ascii").strip() + ":"), const.LENGTH_FORMAT, " ")
						print(nomeFile + str(row[0]) + "\t" + str(row[3], "ascii"))
					else:
						print("\t\t\t" + str(row[0]) + "\t" + str(row[3], "ascii"))
					lastFileName = row[2]
				
				selectId = input("\nInserire il numero di file che vuoi scaricare (0 per uscire): ")
				
				if(selectId != "0"):
					for i in range (0, id):
						if listFile[i][0] == int(selectId):
							selectFile = listFile[i]
							break

					func.download(selectFile)

			else:
				func.error("Non sono presenti file con questa query nel nome: " + query)
		s.close()
開發者ID:tommasoberlose,項目名稱:p2p_kazaa,代碼行數:62,代碼來源:Peer.py


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