本文整理匯總了Python中pyroute2.common.AddrPool.locate方法的典型用法代碼示例。如果您正苦於以下問題:Python AddrPool.locate方法的具體用法?Python AddrPool.locate怎麽用?Python AddrPool.locate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pyroute2.common.AddrPool
的用法示例。
在下文中一共展示了AddrPool.locate方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_locate
# 需要導入模塊: from pyroute2.common import AddrPool [as 別名]
# 或者: from pyroute2.common.AddrPool import locate [as 別名]
def test_locate(self):
ap = AddrPool()
f = ap.alloc()
base1, bit1, is_allocated1 = ap.locate(f)
base2, bit2, is_allocated2 = ap.locate(f + 1)
assert base1 == base2
assert bit2 == bit1 + 1
assert is_allocated1
assert not is_allocated2
assert ap.allocated == 1
示例2: test_setaddr_allocated
# 需要導入模塊: from pyroute2.common import AddrPool [as 別名]
# 或者: from pyroute2.common.AddrPool import locate [as 別名]
def test_setaddr_allocated(self):
ap = AddrPool()
f = ap.alloc()
base, bit, is_allocated = ap.locate(f + 1)
assert not is_allocated
assert ap.allocated == 1
ap.setaddr(f + 1, 'allocated')
base, bit, is_allocated = ap.locate(f + 1)
assert is_allocated
assert ap.allocated == 2
ap.free(f + 1)
base, bit, is_allocated = ap.locate(f + 1)
assert not is_allocated
assert ap.allocated == 1
示例3: test_setaddr_free
# 需要導入模塊: from pyroute2.common import AddrPool [as 別名]
# 或者: from pyroute2.common.AddrPool import locate [as 別名]
def test_setaddr_free(self):
ap = AddrPool()
f = ap.alloc()
base, bit, is_allocated = ap.locate(f + 1)
assert not is_allocated
assert ap.allocated == 1
ap.setaddr(f + 1, 'free')
base, bit, is_allocated = ap.locate(f + 1)
assert not is_allocated
assert ap.allocated == 1
ap.setaddr(f, 'free')
base, bit, is_allocated = ap.locate(f)
assert not is_allocated
assert ap.allocated == 0
try:
ap.free(f)
except KeyError:
pass