本文整理汇总了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"]