本文整理汇总了Python中drogulus.dht.routingtable.RoutingTable._random_key_in_bucket_range方法的典型用法代码示例。如果您正苦于以下问题:Python RoutingTable._random_key_in_bucket_range方法的具体用法?Python RoutingTable._random_key_in_bucket_range怎么用?Python RoutingTable._random_key_in_bucket_range使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类drogulus.dht.routingtable.RoutingTable
的用法示例。
在下文中一共展示了RoutingTable._random_key_in_bucket_range方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_random_key_in_bucket_range
# 需要导入模块: from drogulus.dht.routingtable import RoutingTable [as 别名]
# 或者: from drogulus.dht.routingtable.RoutingTable import _random_key_in_bucket_range [as 别名]
def test_random_key_in_bucket_range(self):
"""
Ensures the returned key is within the expected bucket range.
"""
parent_node_id = 'deadbeef'
r = RoutingTable(parent_node_id)
bucket = Bucket(1, 2)
r._buckets[0] = bucket
expected = 1
actual = int(r._random_key_in_bucket_range(0), 0)
self.assertEqual(expected, actual)
示例2: test_random_key_in_bucket_range_long
# 需要导入模块: from drogulus.dht.routingtable import RoutingTable [as 别名]
# 或者: from drogulus.dht.routingtable.RoutingTable import _random_key_in_bucket_range [as 别名]
def test_random_key_in_bucket_range_long(self):
"""
Ensures that random_key_in_bucket_range works with large numbers.
"""
minimum = 978675645342314253647586978
maximum = 978675645342314253647586979
parent_node_id = 'abc'
r = RoutingTable(parent_node_id)
bucket = KBucket(minimum, maximum)
r._buckets[0] = bucket
expected = minimum
actual = int(r._random_key_in_bucket_range(0).encode('hex'), 16)
self.assertEqual(expected, actual)