本文整理匯總了Python中BaseLib.Core.TorrentDef.TorrentDef.retrieve_from_magnet方法的典型用法代碼示例。如果您正苦於以下問題:Python TorrentDef.retrieve_from_magnet方法的具體用法?Python TorrentDef.retrieve_from_magnet怎麽用?Python TorrentDef.retrieve_from_magnet使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類BaseLib.Core.TorrentDef.TorrentDef
的用法示例。
在下文中一共展示了TorrentDef.retrieve_from_magnet方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_good_transfer
# 需要導入模塊: from BaseLib.Core.TorrentDef import TorrentDef [as 別名]
# 或者: from BaseLib.Core.TorrentDef.TorrentDef import retrieve_from_magnet [as 別名]
def test_good_transfer(self):
def torrentdef_retrieved(tdef):
tags["retrieved"] = True
tags["metainfo"] = tdef.get_metainfo()
tags = {"retrieved":False}
assert TorrentDef.retrieve_from_magnet(self.create_good_url(), torrentdef_retrieved)
# supply fake addresses (regular dht obviously wont work here)
for magnetlink in MagnetHandler.get_instance().get_magnets():
magnetlink._swarm.add_potential_peers([("localhost", LISTEN_PORT)])
# accept incoming connection
self.server.settimeout(10.0)
sock, address = self.server.accept()
assert sock, "No incoming connection"
# handshakes
conn = BTConnection(address[0], address[1], opensock=sock, user_infohash=self.tdef.get_infohash())
conn.send(self.create_good_extend_handshake())
conn.read_handshake_medium_rare()
metadata_id = self.read_extend_handshake(conn)
# serve pieces
for counter in xrange(len(self.metadata_list)):
piece = self.read_extend_metadata_request(conn)
assert 0 <= piece < len(self.metadata_list)
conn.send(self.create_good_extend_metadata_reply(metadata_id, piece))
# no more metadata request may be send and the connection must
# be closed
self.read_extend_metadata_close(conn)
time.sleep(5)
assert tags["retrieved"]
assert tags["metainfo"]["info"] == self.tdef.get_metainfo()["info"]