本文整理汇总了Python中pyndn.Name.get方法的典型用法代码示例。如果您正苦于以下问题:Python Name.get方法的具体用法?Python Name.get怎么用?Python Name.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyndn.Name
的用法示例。
在下文中一共展示了Name.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_append
# 需要导入模块: from pyndn import Name [as 别名]
# 或者: from pyndn.Name import get [as 别名]
def test_append(self):
# could possibly split this into different tests
uri = "/localhost/user/folders/files/%00%0F"
name = Name(uri)
name2 = Name("/localhost").append(Name("/user/folders/"))
self.assertEqual(name2.size(), 3, 'Name constructed by appending names has ' + str(name2.size()) + ' components instead of 3')
self.assertTrue(name2.get(2).getValue().equals(Blob(bytearray("folders"))), 'Name constructed with append has wrong suffix')
name2 = name2.append("files")
self.assertEqual(name2.size(), 4, 'Name constructed by appending string has ' + str(name2.size()) + ' components instead of 4')
name2 = name2.appendSegment(15)
self.assertTrue(name2.get(4).getValue().equals(Blob(bytearray([0x00, 0x0F]))), 'Name constructed by appending segment has wrong segment value')
self.assertTrue(name2.equals(name), 'Name constructed with append is not equal to URI constructed name')
self.assertEqual(name2.toUri(), name.toUri(), 'Name constructed with append has wrong URI')
示例2: test_typed_name_component
# 需要导入模块: from pyndn import Name [as 别名]
# 或者: from pyndn.Name import get [as 别名]
def test_typed_name_component(self):
otherTypeCode = 99
uri = "/ndn/" + str(otherTypeCode) + "=value"
name = Name()
name.append("ndn").append("value", ComponentType.OTHER_CODE, otherTypeCode)
self.assertEqual(uri, name.toUri())
nameFromUri = Name(uri)
self.assertEqual("value", str(nameFromUri.get(1).getValue()))
self.assertEqual(otherTypeCode, nameFromUri.get(1).getOtherTypeCode())
decodedName = Name()
decodedName.wireDecode(name.wireEncode())
self.assertEqual("value", str(decodedName.get(1).getValue()))
self.assertEqual(otherTypeCode, decodedName.get(1).getOtherTypeCode())
示例3: testTimestamp
# 需要导入模块: from pyndn import Name [as 别名]
# 或者: from pyndn.Name import get [as 别名]
def testTimestamp(self):
expected = Name("/%FC%00%04%7BE%E3%1B%00%00")
self.assertTrue(expected.get(0).isTimestamp())
# 40 years (not counting leap years) in microseconds.
number = 40 * 365 * 24 * 3600 * 1000000
self.assertEqual(Name().appendTimestamp(number), expected, "appendTimestamp did not create the expected component")
self.assertEqual(expected[0].toTimestamp(), number, "toTimestamp did not return the expected value")
示例4: _updateCapabilities
# 需要导入模块: from pyndn import Name [as 别名]
# 或者: from pyndn.Name import get [as 别名]
def _updateCapabilities(self):
"""
Send the controller a list of our commands.
"""
fullCommandName = Name(self._policyManager.getTrustRootIdentity()
).append('updateCapabilities')
capabilitiesMessage = UpdateCapabilitiesCommandMessage()
for command in self._commands:
commandName = Name(self.prefix).append(Name(command.suffix))
capability = capabilitiesMessage.capabilities.add()
for i in range(commandName.size()):
capability.commandPrefix.components.append(
str(commandName.get(i).getValue()))
for kw in command.keywords:
capability.keywords.append(kw)
capability.needsSignature = command.isSigned
encodedCapabilities = ProtobufTlv.encode(capabilitiesMessage)
fullCommandName.append(encodedCapabilities)
interest = Interest(fullCommandName)
interest.setInterestLifetimeMilliseconds(5000)
self.face.makeCommandInterest(interest)
signature = self._policyManager._extractSignature(interest)
self.log.info("Sending capabilities to controller")
self.face.expressInterest(interest, self._onCapabilitiesAck, self._onCapabilitiesTimeout)
# update twice a minute
self.loop.call_later(30, self._updateCapabilities)
示例5: apply_exclude
# 需要导入模块: from pyndn import Name [as 别名]
# 或者: from pyndn.Name import get [as 别名]
def apply_exclude(self, last_node, exclude):
"""
@param last_node - the node to start search from
@param exlucde - exclude filter the interest contains
@returns all nodes that fullfil the selector
"""
_id = last_node._id
query = 'START s=node(%s)\n' % _id + \
'MATCH (s)-[:%s]->(m)\n' % (RELATION_C2C) + \
'RETURN (m)'
records = neo4j.CypherQuery(self.db_handler, query).execute()
_nodes = [record.values[0] for record in records.data]
if not exclude:
return _nodes
nodes = []
for node in _nodes:
name = Name()
name.set(node.get_properties()[PROPERTY_COMPONENT])
comp = name.get(0)
if not exclude.matches(comp):
nodes.append(node)
return nodes
示例6: createCheckInterest
# 需要导入模块: from pyndn import Name [as 别名]
# 或者: from pyndn.Name import get [as 别名]
def createCheckInterest(fullName, checkNum):
insertionName = Name("/repotest/repo/insert check")
commandParams = RepoCommandParameterMessage()
interestName = Name(fullName)
commandParams.repo_command_parameter.process_id = checkNum
for i in range(interestName.size()):
commandParams.repo_command_parameter.name.component.append(interestName.get(i).toEscapedString())
commandName = insertionName.append(ProtobufTlv.encode(commandParams))
interest = Interest(commandName)
return interest
示例7: createCheckInterest
# 需要导入模块: from pyndn import Name [as 别名]
# 或者: from pyndn.Name import get [as 别名]
def createCheckInterest(self, fullName, checkNum):
insertionName = Name(self.repoPrefix).append('insert check')
commandParams = RepoCommandParameterMessage()
interestName = Name(fullName)
commandParams.repo_command_parameter.process_id = checkNum
for i in range(interestName.size()):
commandParams.repo_command_parameter.name.component.append(str(interestName.get(i).getValue()))
commandName = insertionName.append(ProtobufTlv.encode(commandParams))
interest = Interest(commandName)
return interest
示例8: onInterest
# 需要导入模块: from pyndn import Name [as 别名]
# 或者: from pyndn.Name import get [as 别名]
def onInterest(self, prefix, interest, transport, registeredPrefixId):
print "received interest"
initInterest = Name(interest.getName())
print "interest name:",initInterest.toUri()
#d = Data(interest.getName().getPrefix(prefix.size()+1))
#self.excludeDevice = interest.getName().get(prefix.size())
#initInterest = interest.getName()
d = Data(interest.getName().append(self.deviceComponent))
try:
if(initInterest == self.prefix):
print "start to set data's content"
currentString = ','.join(currentList)
d.setContent("songList of " +self.device+":"+currentString+ "\n")
else:
self.excludeDevice = initInterest.get(prefix.size())
print "excludeDevice",self.excludeDevice.toEscapedString()
if(self.excludeDevice != self.deviceComponent):
print "start to set data's content"
currentString = ','.join(currentList)
d.setContent("songList of " +self.device+":"+currentString+ "\n")
else:
print"remove register"
self.face.removeRegisteredPrefix(registeredPrefixId)
time.sleep(30)
#sleep 30s which means user cannot update the song list twice within 1 minutes
print"register again"
self.face.registerPrefix(self.prefix, self.onInterest, self.onRegisterFailed)
except KeyboardInterrupt:
print "key interrupt"
sys.exit(1)
except Exception as e:
print e
d.setContent("Bad command\n")
finally:
self.keychain.sign(d,self.certificateName)
encodedData = d.wireEncode()
transport.send(encodedData.toBuffer())
print d.getName().toUri()
print d.getContent()
示例9: onInterest
# 需要导入模块: from pyndn import Name [as 别名]
# 或者: from pyndn.Name import get [as 别名]
def onInterest(self, prefix, interest, transport, registeredPrefixId):
initInterest = Name(interest.getName())
print "interest name:",initInterest.toUri()
d = Data(interest.getName().append(self.deviceComponent))
try:
if(initInterest == self.listPrefix):
print "initial db,start to set data's content"
currentString = ','.join(currentList)
d.setContent(currentString)
encodedData = d.wireEncode()
transport.send(encodedData.toBuffer())
print d.getName().toUri()
print d.getContent()
else:
self.excludeDevice = initInterest.get(self.listPrefix.size())
excDevice = self.excludeDevice.toEscapedString()
if(excDevice != str("exc")+self.device):
print "not init db,start to set data's content"
currentString = ','.join(currentList)
d.setContent(currentString)
encodedData = d.wireEncode()
transport.send(encodedData.toBuffer())
print d.getName().toUri()
print d.getContent()
else:
print"controller has exclude me, I have to remove register!!!!!!!"
self.face.removeRegisteredPrefix(registeredPrefixId)
print"register again"
self.face.registerPrefix(self.listPrefix,self.onInterest,self.onRegisterFailed)
except KeyboardInterrupt:
print "key interrupt"
sys.exit(1)
except Exception as e:
print e
d.setContent("Bad command\n")
finally:
self.keychain.sign(d,self.certificateName)
示例10: createInsertInterest
# 需要导入模块: from pyndn import Name [as 别名]
# 或者: from pyndn.Name import get [as 别名]
def createInsertInterest(fullName):
# we have to do the versioning when we poke the repo
interestName = Name(fullName)
logger.debug('Creating insert interest for: '+interestName.toUri())
insertionName = Name("/repotest/repo/insert")
commandParams = RepoCommandParameterMessage()
for i in range(interestName.size()):
commandParams.repo_command_parameter.name.component.append(interestName.get(i).toEscapedString())
commandParams.repo_command_parameter.start_block_id = 0
commandParams.repo_command_parameter.end_block_id = 0
commandName = insertionName.append(ProtobufTlv.encode(commandParams))
interest = Interest(commandName)
return interest
示例11: createInsertInterest
# 需要导入模块: from pyndn import Name [as 别名]
# 或者: from pyndn.Name import get [as 别名]
def createInsertInterest(self, fullName):
'''
For poking the repo
'''
# we have to do the versioning before we poke the repo
interestName = Name(fullName)
logger.debug('Creating insert interest for: '+interestName.toUri())
insertionName = Name(self.repoPrefix).append('insert')
commandParams = RepoCommandParameterMessage()
for i in range(interestName.size()):
commandParams.repo_command_parameter.name.component.append(interestName.get(i).getValue().toRawStr())
commandParams.repo_command_parameter.start_block_id = 0
commandParams.repo_command_parameter.end_block_id = 0
commandName = insertionName.append(ProtobufTlv.encode(commandParams))
interest = Interest(commandName)
interest.setInterestLifetimeMilliseconds(2000)
return interest
示例12: createKeyChain
# 需要导入模块: from pyndn import Name [as 别名]
# 或者: from pyndn.Name import get [as 别名]
def createKeyChain():
"""
Create an in-memory KeyChain with default keys.
:return: A tuple with the new KeyChain and certificate name.
:rtype: (KeyChain,Name)
"""
identityStorage = MemoryIdentityStorage()
privateKeyStorage = MemoryPrivateKeyStorage()
keyChain = KeyChain(
IdentityManager(identityStorage, privateKeyStorage),
NoVerifyPolicyManager())
# Initialize the storage.
keyName = Name("/testname/DSK-123")
certificateName = keyName.getSubName(0, keyName.size() - 1).append(
"KEY").append(keyName.get(-1)).append("ID-CERT").append("0")
identityStorage.addKey(
keyName, KeyType.RSA, Blob(DEFAULT_RSA_PUBLIC_KEY_DER, False))
privateKeyStorage.setKeyPairForKeyName(
keyName, KeyType.RSA, DEFAULT_RSA_PUBLIC_KEY_DER,
DEFAULT_RSA_PRIVATE_KEY_DER)
return keyChain, certificateName
示例13: test_full_name
# 需要导入模块: from pyndn import Name [as 别名]
# 或者: from pyndn.Name import get [as 别名]
def test_full_name(self):
data = Data()
data.wireDecode(codedData)
# Check the full name format.
self.assertEqual(data.getFullName().size(), data.getName().size() + 1)
self.assertEqual(data.getName(), data.getFullName().getPrefix(-1))
self.assertEqual(data.getFullName().get(-1).getValue().size(), 32)
# Check the independent digest calculation.
sha256 = hashes.Hash(hashes.SHA256(), backend=default_backend())
sha256.update(Blob(codedData).toBytes())
newDigest = Blob(bytearray(sha256.finalize()), False)
self.assertTrue(newDigest.equals(data.getFullName().get(-1).getValue()))
# Check the expected URI.
self.assertEqual(
data.getFullName().toUri(), "/ndn/abc/sha256digest=" +
"96556d685dcb1af04be4ae57f0e7223457d4055ea9b3d07c0d337bef4a8b3ee9")
# Changing the Data packet should change the full name.
saveFullName = Name(data.getFullName())
data.setContent(Blob())
self.assertNotEqual(data.getFullName().get(-1), saveFullName.get(-1))
示例14: testVersion
# 需要导入模块: from pyndn import Name [as 别名]
# 或者: from pyndn.Name import get [as 别名]
def testVersion(self):
expected = Name("/%FD%00%0FB%40")
self.assertTrue(expected.get(0).isVersion())
number = 1000000
self.assertEqual(Name().appendVersion(number), expected, "appendVersion did not create the expected component")
self.assertEqual(expected[0].toVersion(), number, "toVersion did not return the expected value")
示例15: test_prefix
# 需要导入模块: from pyndn import Name [as 别名]
# 或者: from pyndn.Name import get [as 别名]
def test_prefix(self):
name = Name(self.expectedURI)
name2 = name.getPrefix(2)
self.assertEqual(name2.size(),2, 'Name prefix has ' + str(name2.size()) + ' components instead of 2')
for i in range(2):
self.assertTrue(name.get(i).getValue().equals(name2.get(i).getValue()))