本文整理汇总了Python中dht.crawling.ValueSpiderCrawl.find方法的典型用法代码示例。如果您正苦于以下问题:Python ValueSpiderCrawl.find方法的具体用法?Python ValueSpiderCrawl.find怎么用?Python ValueSpiderCrawl.find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dht.crawling.ValueSpiderCrawl
的用法示例。
在下文中一共展示了ValueSpiderCrawl.find方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_find
# 需要导入模块: from dht.crawling import ValueSpiderCrawl [as 别名]
# 或者: from dht.crawling.ValueSpiderCrawl import find [as 别名]
def test_find(self):
self._connecting_to_connected()
self.wire_protocol[self.addr1] = self.con
self.wire_protocol[self.addr2] = self.con
self.wire_protocol[self.addr3] = self.con
self.protocol.router.addContact(self.node1)
self.protocol.router.addContact(self.node2)
self.protocol.router.addContact(self.node3)
node = Node(digest("s"))
nearest = self.protocol.router.findNeighbors(node)
spider = ValueSpiderCrawl(self.protocol, node, nearest, 20, 3)
spider.find()
self.clock.advance(constants.PACKET_TIMEOUT)
connection.REACTOR.runUntilCurrent()
self.assertEqual(len(self.proto_mock.send_datagram.call_args_list), 4)
示例2: get
# 需要导入模块: from dht.crawling import ValueSpiderCrawl [as 别名]
# 或者: from dht.crawling.ValueSpiderCrawl import find [as 别名]
def get(self, keyword):
"""
Get a key if the network has it.
Returns:
:class:`None` if not found, the value otherwise.
"""
dkey = digest(keyword)
if self.storage.get(dkey) is not None:
return defer.succeed(self.storage.get(dkey))
node = Node(dkey)
nearest = self.protocol.router.findNeighbors(node)
if len(nearest) == 0:
self.log.warning("there are no known neighbors to get key %s" % dkey.encode('hex'))
return defer.succeed(None)
spider = ValueSpiderCrawl(self.protocol, node, nearest, self.ksize, self.alpha)
return spider.find()
示例3: get
# 需要导入模块: from dht.crawling import ValueSpiderCrawl [as 别名]
# 或者: from dht.crawling.ValueSpiderCrawl import find [as 别名]
def get(self, keyword, save_at_nearest=True):
"""
Get a key if the network has it.
Args:
keyword = the keyword to save to
save_at_nearest = save value at the nearest without value
Returns:
:class:`None` if not found, the value otherwise.
"""
dkey = digest(keyword)
node = Node(dkey)
nearest = self.protocol.router.findNeighbors(node)
if len(nearest) == 0:
self.log.warning("there are no known neighbors to get key %s" % dkey.encode('hex'))
return defer.succeed(None)
spider = ValueSpiderCrawl(self.protocol, node, nearest, self.ksize, self.alpha, save_at_nearest)
return spider.find()