本文整理汇总了Python中pyndn.Name.fromEscapedString方法的典型用法代码示例。如果您正苦于以下问题:Python Name.fromEscapedString方法的具体用法?Python Name.fromEscapedString怎么用?Python Name.fromEscapedString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyndn.Name
的用法示例。
在下文中一共展示了Name.fromEscapedString方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: checkInsertion
# 需要导入模块: from pyndn import Name [as 别名]
# 或者: from pyndn.Name import fromEscapedString [as 别名]
def checkInsertion(self, versionStr, processID):
fullName = Name(self.dataName).append(Name.fromEscapedString(versionStr))
checkCommand = self.createCheckInterest(fullName, processID)
self.face.makeCommandInterest(checkCommand)
def timeoutLoop(interest):
logger.warn('Timed out waiting on: '+interest.toUri())
self.face.expressInterest(checkCommand, self.onCommandData, self.onTimeout)
self.face.expressInterest(checkCommand, self.onCommandData, timeoutLoop)
示例2: onDataNotFound
# 需要导入模块: from pyndn import Name [as 别名]
# 或者: from pyndn.Name import fromEscapedString [as 别名]
def onDataNotFound(self, prefix, interest, face, interestFilterId, filter):
print "Data not found for interest: " + interest.getName().toUri()
functionComponentIdx = len(self._identityName)
if interest.getName().get(functionComponentIdx).toEscapedString() == self._functionName:
try:
parameters = interest.getName().get(functionComponentIdx + 1).toEscapedString()
pattern = re.compile('([^,]*),([^,]*),([^,]*)')
matching = pattern.match(str(Name.fromEscapedString(parameters)))
userId = matching.group(1)
basetimeString = matching.group(2)
producedDataName = matching.group(3)
dataNum = 60
self._tasks[producedDataName] = {"cap_num": dataNum, "current_num": 0, "dataset": []}
self.startConsuming(userId, basetimeString, producedDataName, dataNum, interest.getName().toUri())
except Exception as e:
print "Exception in processing function arguments: " + str(e)
else:
print "function name mismatch: expected " + self._functionName + " ; got " + interest.getName().get(functionComponentIdx).toEscapedString()
return
示例3: benchmarkEncodeDataSeconds
# 需要导入模块: from pyndn import Name [as 别名]
# 或者: from pyndn.Name import fromEscapedString [as 别名]
def benchmarkEncodeDataSeconds(nIterations, useComplex, useCrypto):
"""
Loop to encode a data packet nIterations times.
:param int nIterations: The number of iterations.
:param bool useComplex: If true, use a large name, large content and all
fields. If false, use a small name, small content and only required
fields.
:param bool useCrypto: If true, sign the data packet. If false, use a blank
signature.
:return: A tuple (duration, encoding) where duration is the number of
seconds for all iterations and encoding is the wire encoding.
:rtype: (float, Blob)
"""
if useComplex:
# Use a large name and content.
name = Name(
"/ndn/ucla.edu/apps/lwndn-test/numbers.txt/%FD%05%05%E8%0C%CE%1D/%00")
contentString = ""
count = 1
contentString += "%d" % count
count += 1
while len(contentString) < 1115:
contentString += " %d" % count
count += 1
content = Name.fromEscapedString(contentString)
else:
# Use a small name and content.
name = Name("/test")
content = Name.fromEscapedString("abc")
finalBlockId = Name("/%00")[0]
# Initialize the private key storage in case useCrypto is true.
identityStorage = MemoryIdentityStorage()
privateKeyStorage = MemoryPrivateKeyStorage()
keyChain = KeyChain(IdentityManager(identityStorage, privateKeyStorage),
SelfVerifyPolicyManager(identityStorage))
keyName = Name("/testname/DSK-123")
certificateName = keyName.getSubName(0, keyName.size() - 1).append(
"KEY").append(keyName[-1]).append("ID-CERT").append("0")
identityStorage.addKey(keyName, KeyType.RSA, Blob(DEFAULT_RSA_PUBLIC_KEY_DER))
privateKeyStorage.setKeyPairForKeyName(
keyName, KeyType.RSA, DEFAULT_RSA_PUBLIC_KEY_DER, DEFAULT_RSA_PRIVATE_KEY_DER)
# Set up signatureBits in case useCrypto is false.
signatureBits = Blob(bytearray(256))
emptyBlob = Blob([])
start = getNowSeconds()
for i in range(nIterations):
data = Data(name)
data.setContent(content)
if useComplex:
data.getMetaInfo().setFreshnessPeriod(1000)
data.getMetaInfo().setFinalBlockId(finalBlockId)
if useCrypto:
# This sets the signature fields.
keyChain.sign(data, certificateName)
else:
# Imitate IdentityManager.signByCertificate to set up the signature
# fields, but don't sign.
sha256Signature = data.getSignature()
keyLocator = sha256Signature.getKeyLocator()
keyLocator.setType(KeyLocatorType.KEYNAME)
keyLocator.setKeyName(certificateName)
sha256Signature.setSignature(signatureBits)
encoding = data.wireEncode()
finish = getNowSeconds()
return (finish - start, encoding)
示例4: benchmarkEncodeDataSeconds
# 需要导入模块: from pyndn import Name [as 别名]
# 或者: from pyndn.Name import fromEscapedString [as 别名]
def benchmarkEncodeDataSeconds(nIterations, useComplex, useCrypto, keyType):
"""
Loop to encode a data packet nIterations times.
:param int nIterations: The number of iterations.
:param bool useComplex: If true, use a large name, large content and all
fields. If false, use a small name, small content and only required
fields.
:param bool useCrypto: If true, sign the data packet. If false, use a blank
signature.
:param KeyType keyType: KeyType.RSA or EC, used if useCrypto is True.
:return: A tuple (duration, encoding) where duration is the number of
seconds for all iterations and encoding is the wire encoding.
:rtype: (float, Blob)
"""
if useComplex:
# Use a large name and content.
name = Name(
"/ndn/ucla.edu/apps/lwndn-test/numbers.txt/%FD%05%05%E8%0C%CE%1D/%00")
contentString = ""
count = 1
contentString += "%d" % count
count += 1
while len(contentString) < 1115:
contentString += " %d" % count
count += 1
content = Name.fromEscapedString(contentString)
else:
# Use a small name and content.
name = Name("/test")
content = Name.fromEscapedString("abc")
finalBlockId = Name("/%00")[0]
# Initialize the KeyChain in case useCrypto is true.
keyChain = KeyChain("pib-memory:", "tpm-memory:")
keyChain.importSafeBag(SafeBag
(Name("/testname/KEY/123"),
Blob(DEFAULT_EC_PRIVATE_KEY_DER if keyType == KeyType.EC
else DEFAULT_RSA_PRIVATE_KEY_DER, False),
Blob(DEFAULT_EC_PUBLIC_KEY_DER if keyType == KeyType.EC
else DEFAULT_RSA_PUBLIC_KEY_DER, False)))
certificateName = keyChain.getDefaultCertificateName()
# Set up signatureBits in case useCrypto is false.
signatureBits = Blob(bytearray(256))
start = getNowSeconds()
for i in range(nIterations):
data = Data(name)
data.setContent(content)
if useComplex:
data.getMetaInfo().setFreshnessPeriod(1000)
data.getMetaInfo().setFinalBlockId(finalBlockId)
if useCrypto:
# This sets the signature fields.
keyChain.sign(data)
else:
# Imitate IdentityManager.signByCertificate to set up the signature
# fields, but don't sign.
sha256Signature = data.getSignature()
keyLocator = sha256Signature.getKeyLocator()
keyLocator.setType(KeyLocatorType.KEYNAME)
keyLocator.setKeyName(certificateName)
sha256Signature.setSignature(signatureBits)
encoding = data.wireEncode()
finish = getNowSeconds()
return (finish - start, encoding)