本文整理匯總了Python中Tribler.Core.CacheDB.SqliteCacheDBHandler.TorrentDBHandler.getTrackerListByInfohash方法的典型用法代碼示例。如果您正苦於以下問題:Python TorrentDBHandler.getTrackerListByInfohash方法的具體用法?Python TorrentDBHandler.getTrackerListByInfohash怎麽用?Python TorrentDBHandler.getTrackerListByInfohash使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Tribler.Core.CacheDB.SqliteCacheDBHandler.TorrentDBHandler
的用法示例。
在下文中一共展示了TorrentDBHandler.getTrackerListByInfohash方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: TestTorrentDBHandler
# 需要導入模塊: from Tribler.Core.CacheDB.SqliteCacheDBHandler import TorrentDBHandler [as 別名]
# 或者: from Tribler.Core.CacheDB.SqliteCacheDBHandler.TorrentDBHandler import getTrackerListByInfohash [as 別名]
class TestTorrentDBHandler(AbstractDB):
def setUp(self):
super(TestTorrentDBHandler, self).setUp()
from Tribler.Core.APIImplementation.LaunchManyCore import TriblerLaunchMany
from Tribler.Core.Modules.tracker_manager import TrackerManager
self.session.lm = TriblerLaunchMany()
self.session.lm.tracker_manager = TrackerManager(self.session)
self.session.lm.tracker_manager.initialize()
self.tdb = TorrentDBHandler(self.session)
self.tdb.torrent_dir = TESTS_DATA_DIR
self.tdb.category = Category.getInstance(self.session)
self.tdb.mypref_db = MyPreferenceDBHandler(self.session)
@blocking_call_on_reactor_thread
def tearDown(self):
self.tdb.mypref_db.close()
self.tdb.mypref_db = None
self.tdb.close()
self.tdb = None
super(TestTorrentDBHandler, self).tearDown()
@blocking_call_on_reactor_thread
def test_hasTorrent(self):
infohash_str = 'AA8cTG7ZuPsyblbRE7CyxsrKUCg='
infohash = str2bin(infohash_str)
assert self.tdb.hasTorrent(infohash)
fake_infoahsh = 'fake_infohash_100000'
assert self.tdb.hasTorrent(fake_infoahsh) == False
@blocking_call_on_reactor_thread
def test_add_update_Torrent(self):
self.addTorrent()
self.updateTorrent()
@blocking_call_on_reactor_thread
def addTorrent(self):
old_size = self.tdb.size()
old_tracker_size = self.tdb._db.size('TrackerInfo')
s_infohash = unhexlify('44865489ac16e2f34ea0cd3043cfd970cc24ec09')
m_infohash = unhexlify('ed81da94d21ad1b305133f2726cdaec5a57fed98')
sid = self.tdb.getTorrentID(s_infohash)
mid = self.tdb.getTorrentID(m_infohash)
single_torrent_file_path = os.path.join(self.getStateDir(), 'single.torrent')
multiple_torrent_file_path = os.path.join(self.getStateDir(), 'multiple.torrent')
copyFile(S_TORRENT_PATH_BACKUP, single_torrent_file_path)
copyFile(M_TORRENT_PATH_BACKUP, multiple_torrent_file_path)
single_tdef = TorrentDef.load(single_torrent_file_path)
assert s_infohash == single_tdef.get_infohash()
multiple_tdef = TorrentDef.load(multiple_torrent_file_path)
assert m_infohash == multiple_tdef.get_infohash()
self.tdb.addExternalTorrent(single_tdef)
self.tdb.addExternalTorrent(multiple_tdef)
single_torrent_id = self.tdb.getTorrentID(s_infohash)
multiple_torrent_id = self.tdb.getTorrentID(m_infohash)
assert self.tdb.getInfohash(single_torrent_id) == s_infohash
single_name = 'Tribler_4.1.7_src.zip'
multiple_name = 'Tribler_4.1.7_src'
assert self.tdb.size() == old_size + 2, old_size - self.tdb.size()
new_tracker_table_size = self.tdb._db.size('TrackerInfo')
assert old_tracker_size < new_tracker_table_size, new_tracker_table_size - old_tracker_size
sname = self.tdb.getOne('name', torrent_id=single_torrent_id)
assert sname == single_name, (sname, single_name)
mname = self.tdb.getOne('name', torrent_id=multiple_torrent_id)
assert mname == multiple_name, (mname, multiple_name)
s_size = self.tdb.getOne('length', torrent_id=single_torrent_id)
assert s_size == 1583233, s_size
m_size = self.tdb.getOne('length', torrent_id=multiple_torrent_id)
assert m_size == 5358560, m_size
cat = self.tdb.getOne('category', torrent_id=multiple_torrent_id)
assert cat == u'xxx', cat
s_status = self.tdb.getOne('status', torrent_id=single_torrent_id)
assert s_status == u'unknown', s_status
m_comment = self.tdb.getOne('comment', torrent_id=multiple_torrent_id)
comments = 'www.tribler.org'
assert m_comment.find(comments) > -1
comments = 'something not inside'
assert m_comment.find(comments) == -1
m_trackers = self.tdb.getTrackerListByInfohash(m_infohash)
assert len(m_trackers) == 8
assert 'http://tpb.tracker.thepiratebay.org/announce' in m_trackers, m_trackers
#.........這裏部分代碼省略.........