当前位置: 首页>>代码示例>>Python>>正文


Python Name.fromEscapedString方法代码示例

本文整理汇总了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)
开发者ID:thecodemaiden,项目名称:nfd-timing,代码行数:10,代码来源:repo-event-publisher.py

示例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
开发者ID:zhehaowang,项目名称:sample-omh-dpu,代码行数:22,代码来源:dpu.py

示例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)
开发者ID:WeiqiJust,项目名称:NDN-total,代码行数:76,代码来源:test_encode_decode_benchmark.py

示例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)
开发者ID:named-data,项目名称:PyNDN2,代码行数:74,代码来源:test_encode_decode_benchmark.py


注:本文中的pyndn.Name.fromEscapedString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。