当前位置: 首页>>代码示例>>Python>>正文


Python Function.download方法代码示例

本文整理汇总了Python中Function.download方法的典型用法代码示例。如果您正苦于以下问题:Python Function.download方法的具体用法?Python Function.download怎么用?Python Function.download使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Function的用法示例。


在下文中一共展示了Function.download方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: search

# 需要导入模块: import Function [as 别名]
# 或者: from Function import download [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.download方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。