本文整理汇总了Python中pyndn.Interest.getNonce方法的典型用法代码示例。如果您正苦于以下问题:Python Interest.getNonce方法的具体用法?Python Interest.getNonce怎么用?Python Interest.getNonce使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyndn.Interest
的用法示例。
在下文中一共展示了Interest.getNonce方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_refresh_nonce
# 需要导入模块: from pyndn import Interest [as 别名]
# 或者: from pyndn.Interest import getNonce [as 别名]
def test_refresh_nonce(self):
interest = Interest(self.referenceInterest)
oldNonce = interest.getNonce()
self.assertEqual(4, oldNonce.size())
interest.refreshNonce()
self.assertEqual(oldNonce.size(), interest.getNonce().size(),
"The refreshed nonce should be the same size")
self.assertFalse(interest.getNonce().equals(oldNonce),
"The refreshed nonce should be different")
示例2: test_set_removes_nonce
# 需要导入模块: from pyndn import Interest [as 别名]
# 或者: from pyndn.Interest import getNonce [as 别名]
def test_set_removes_nonce(self):
# Ensure that changing a value on an interest clears the nonce.
self.assertFalse(self.referenceInterest.getNonce().isNull())
interest = Interest(self.referenceInterest)
# Change a child object.
interest.getExclude().clear()
self.assertTrue(interest.getNonce().isNull(), 'Interest should not have a nonce after changing fields')
示例3: TestInterestMethods
# 需要导入模块: from pyndn import Interest [as 别名]
# 或者: from pyndn.Interest import getNonce [as 别名]
class TestInterestMethods(ut.TestCase):
def setUp(self):
self.referenceInterest = Interest()
self.referenceInterest.wireDecode(codedInterest)
def test_copy_constructor(self):
interest = Interest(self.referenceInterest)
self.assertTrue(interestDumpsEqual(dumpInterest(interest), dumpInterest(self.referenceInterest)), 'Interest constructed as deep copy does not match original')
def test_empty_nonce(self):
# make sure a freshly created interest has no nonce
freshInterest = createFreshInterest()
self.assertTrue(freshInterest.getNonce().isNull(), 'Freshly created interest should not have a nonce')
def test_set_removes_nonce(self):
# ensure that setting a value on an interest clears the nonce
self.assertFalse(self.referenceInterest.getNonce().isNull())
interest = Interest(self.referenceInterest)
interest.setChildSelector(0)
self.assertTrue(interest.getNonce().isNull(), 'Interest should not have a nonce after changing fields')
示例4: TestInterestMethods
# 需要导入模块: from pyndn import Interest [as 别名]
# 或者: from pyndn.Interest import getNonce [as 别名]
class TestInterestMethods(ut.TestCase):
def setUp(self):
self.referenceInterest = Interest()
self.referenceInterest.wireDecode(codedInterest)
def test_copy_constructor(self):
interest = Interest(self.referenceInterest)
self.assertTrue(interestDumpsEqual(dumpInterest(interest), dumpInterest(self.referenceInterest)), 'Interest constructed as deep copy does not match original')
def test_empty_nonce(self):
# make sure a freshly created interest has no nonce
freshInterest = createFreshInterest()
self.assertTrue(freshInterest.getNonce().isNull(), 'Freshly created interest should not have a nonce')
def test_set_removes_nonce(self):
# Ensure that changing a value on an interest clears the nonce.
self.assertFalse(self.referenceInterest.getNonce().isNull())
interest = Interest(self.referenceInterest)
# Change a child object.
interest.getExclude().clear()
self.assertTrue(interest.getNonce().isNull(), 'Interest should not have a nonce after changing fields')
def test_refresh_nonce(self):
interest = Interest(self.referenceInterest)
oldNonce = interest.getNonce()
self.assertEqual(4, oldNonce.size())
interest.refreshNonce()
self.assertEqual(oldNonce.size(), interest.getNonce().size(),
"The refreshed nonce should be the same size")
self.assertFalse(interest.getNonce().equals(oldNonce),
"The refreshed nonce should be different")
def test_exclude_matches(self):
exclude = Exclude()
exclude.appendComponent(Name("%00%02").get(0))
exclude.appendAny()
exclude.appendComponent(Name("%00%20").get(0))
component = Name("%00%01").get(0)
self.assertFalse(exclude.matches(component),
component.toEscapedString() + " should not match " + exclude.toUri())
component = Name("%00%0F").get(0)
self.assertTrue(exclude.matches(component),
component.toEscapedString() + " should match " + exclude.toUri())
component = Name("%00%21").get(0)
self.assertFalse(exclude.matches(component),
component.toEscapedString() + " should not match " + exclude.toUri())
def test_verify_digest_sha256(self):
# Create a KeyChain but we don't need to add keys.
identityStorage = MemoryIdentityStorage()
keyChain = KeyChain(
IdentityManager(identityStorage, MemoryPrivateKeyStorage()),
SelfVerifyPolicyManager(identityStorage))
interest = Interest(Name("/test/signed-interest"))
keyChain.signWithSha256(interest)
# We create 'mock' objects to replace callbacks since we're not
# interested in the effect of the callbacks themselves.
failedCallback = Mock()
verifiedCallback = Mock()
keyChain.verifyInterest(interest, verifiedCallback, failedCallback)
self.assertEqual(failedCallback.call_count, 0, 'Signature verification failed')
self.assertEqual(verifiedCallback.call_count, 1, 'Verification callback was not used.')
def test_interest_filter_matching(self):
self.assertEqual(True, InterestFilter("/a").doesMatch(Name("/a/b")))
self.assertEqual(True, InterestFilter("/a/b").doesMatch(Name("/a/b")))
self.assertEqual(False, InterestFilter("/a/b/c").doesMatch(Name("/a/b")))
self.assertEqual(True, InterestFilter("/a", "<b>").doesMatch(Name("/a/b")))
self.assertEqual(False, InterestFilter("/a/b", "<b>").doesMatch(Name("/a/b")))
self.assertEqual(False, InterestFilter("/a/b", "<c>").doesMatch(Name("/a/b/c/d")))
self.assertEqual(False, InterestFilter("/a/b", "<b>").doesMatch(Name("/a/b/c/b")))
self.assertEqual(True, InterestFilter("/a/b", "<>*<b>").doesMatch(Name("/a/b/c/b")))
self.assertEqual(False, InterestFilter("/a", "<b>").doesMatch(Name("/a/b/c/d")))
self.assertEqual(True, InterestFilter("/a", "<b><>*").doesMatch(Name("/a/b/c/d")))
self.assertEqual(True, InterestFilter("/a", "<b><>*").doesMatch(Name("/a/b")))
self.assertEqual(False, InterestFilter("/a", "<b><>+").doesMatch(Name("/a/b")))
self.assertEqual(True, InterestFilter("/a", "<b><>+").doesMatch(Name("/a/b/c")))
示例5: TestInterestMethods
# 需要导入模块: from pyndn import Interest [as 别名]
# 或者: from pyndn.Interest import getNonce [as 别名]
class TestInterestMethods(ut.TestCase):
def setUp(self):
self.referenceInterest = Interest()
self.referenceInterest.wireDecode(codedInterest)
def test_copy_constructor(self):
interest = Interest(self.referenceInterest)
self.assertTrue(interestDumpsEqual(dumpInterest(interest), dumpInterest(self.referenceInterest)), 'Interest constructed as deep copy does not match original')
def test_empty_nonce(self):
# make sure a freshly created interest has no nonce
freshInterest = createFreshInterest()
self.assertTrue(freshInterest.getNonce().isNull(), 'Freshly created interest should not have a nonce')
def test_set_removes_nonce(self):
# Ensure that changing a value on an interest clears the nonce.
self.assertFalse(self.referenceInterest.getNonce().isNull())
interest = Interest(self.referenceInterest)
# Change a child object.
interest.getExclude().clear()
self.assertTrue(interest.getNonce().isNull(), 'Interest should not have a nonce after changing fields')
def test_refresh_nonce(self):
interest = Interest(self.referenceInterest)
oldNonce = interest.getNonce()
self.assertEqual(4, oldNonce.size())
interest.refreshNonce()
self.assertEqual(oldNonce.size(), interest.getNonce().size(),
"The refreshed nonce should be the same size")
self.assertFalse(interest.getNonce().equals(oldNonce),
"The refreshed nonce should be different")
def test_exclude_matches(self):
exclude = Exclude()
exclude.appendComponent(Name("%00%02").get(0))
exclude.appendAny()
exclude.appendComponent(Name("%00%20").get(0))
component = Name("%00%01").get(0)
self.assertFalse(exclude.matches(component),
component.toEscapedString() + " should not match " + exclude.toUri())
component = Name("%00%0F").get(0)
self.assertTrue(exclude.matches(component),
component.toEscapedString() + " should match " + exclude.toUri())
component = Name("%00%21").get(0)
self.assertFalse(exclude.matches(component),
component.toEscapedString() + " should not match " + exclude.toUri())
def test_verify_digest_sha256(self):
# Create a KeyChain but we don't need to add keys.
identityStorage = MemoryIdentityStorage()
keyChain = KeyChain(
IdentityManager(identityStorage, MemoryPrivateKeyStorage()),
SelfVerifyPolicyManager(identityStorage))
interest = Interest(Name("/test/signed-interest"))
keyChain.signWithSha256(interest)
# We create 'mock' objects to replace callbacks since we're not
# interested in the effect of the callbacks themselves.
failedCallback = Mock()
verifiedCallback = Mock()
keyChain.verifyInterest(interest, verifiedCallback, failedCallback)
self.assertEqual(failedCallback.call_count, 0, 'Signature verification failed')
self.assertEqual(verifiedCallback.call_count, 1, 'Verification callback was not used.')
def test_matches_data(self):
interest = Interest(Name("/A"))
interest.setMinSuffixComponents(2)
interest.setMaxSuffixComponents(2)
interest.getKeyLocator().setType(KeyLocatorType.KEYNAME)
interest.getKeyLocator().setKeyName(Name("/B"))
interest.getExclude().appendComponent(Name.Component("J"))
interest.getExclude().appendAny()
data = Data(Name("/A/D"))
signature = Sha256WithRsaSignature()
signature.getKeyLocator().setType(KeyLocatorType.KEYNAME)
signature.getKeyLocator().setKeyName(Name("/B"))
data.setSignature(signature)
self.assertEqual(interest.matchesData(data), True)
# Check violating MinSuffixComponents.
data1 = Data(data)
data1.setName(Name("/A"))
self.assertEqual(interest.matchesData(data1), False)
interest1 = Interest(interest)
interest1.setMinSuffixComponents(1)
self.assertEqual(interest1.matchesData(data1), True)
# Check violating MaxSuffixComponents.
data2 = Data(data)
data2.setName(Name("/A/E/F"))
self.assertEqual(interest.matchesData(data2), False)
interest2 = Interest(interest)
interest2.setMaxSuffixComponents(3)
#.........这里部分代码省略.........
示例6: test_set_removes_nonce
# 需要导入模块: from pyndn import Interest [as 别名]
# 或者: from pyndn.Interest import getNonce [as 别名]
def test_set_removes_nonce(self):
# ensure that setting a value on an interest clears the nonce
self.assertFalse(self.referenceInterest.getNonce().isNull())
interest = Interest(self.referenceInterest)
interest.setChildSelector(0)
self.assertTrue(interest.getNonce().isNull(), 'Interest should not have a nonce after changing fields')