本文整理汇总了Python中drogulus.dht.routingtable.RoutingTable._kbucket_index方法的典型用法代码示例。如果您正苦于以下问题:Python RoutingTable._kbucket_index方法的具体用法?Python RoutingTable._kbucket_index怎么用?Python RoutingTable._kbucket_index使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类drogulus.dht.routingtable.RoutingTable
的用法示例。
在下文中一共展示了RoutingTable._kbucket_index方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_kbucket_index_multiple_buckets
# 需要导入模块: from drogulus.dht.routingtable import RoutingTable [as 别名]
# 或者: from drogulus.dht.routingtable.RoutingTable import _kbucket_index [as 别名]
def test_kbucket_index_multiple_buckets(self):
"""
Ensures the expected index is returned when multiple buckets exist.
"""
parent_node_id = 'abc'
r = RoutingTable(parent_node_id)
r._split_bucket(0)
split_point = (2 ** 512) / 2
lower_key = split_point - 1
higher_key = split_point + 1
expected_lower_index = 0
expected_higher_index = 1
actual_lower_index = r._kbucket_index(lower_key)
actual_higher_index = r._kbucket_index(higher_key)
self.assertEqual(expected_lower_index, actual_lower_index)
self.assertEqual(expected_higher_index, actual_higher_index)
示例2: test_kbucket_index_as_string_and_int
# 需要导入模块: from drogulus.dht.routingtable import RoutingTable [as 别名]
# 或者: from drogulus.dht.routingtable.RoutingTable import _kbucket_index [as 别名]
def test_kbucket_index_as_string_and_int(self):
"""
Ensures that the specified key can be expressed as both a string
and integer value.
"""
parent_node_id = 'abc'
r = RoutingTable(parent_node_id)
# key as a string
test_key = 'abc123'
expected_index = 0
actual_index = r._kbucket_index(test_key)
self.assertEqual(expected_index, actual_index)
# key as an integer
test_key = 1234567
actual_index = r._kbucket_index(test_key)
self.assertEqual(expected_index, actual_index)
示例3: test_kbucket_index_single_bucket
# 需要导入模块: from drogulus.dht.routingtable import RoutingTable [as 别名]
# 或者: from drogulus.dht.routingtable.RoutingTable import _kbucket_index [as 别名]
def test_kbucket_index_single_bucket(self):
"""
Ensures the expected index is returned when only a single bucket
exists.
"""
parent_node_id = 'abc'
r = RoutingTable(parent_node_id)
# a simple test with only one kbucket in the routing table.
test_key = 'abc123'
expected_index = 0
actual_index = r._kbucket_index(test_key)
self.assertEqual(expected_index, actual_index)