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


Python Name.match方法代码示例

本文整理汇总了Python中pyndn.Name.match方法的典型用法代码示例。如果您正苦于以下问题:Python Name.match方法的具体用法?Python Name.match怎么用?Python Name.match使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyndn.Name的用法示例。


在下文中一共展示了Name.match方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_match

# 需要导入模块: from pyndn import Name [as 别名]
# 或者: from pyndn.Name import match [as 别名]
    def test_match(self):
        name = Name("/edu/cmu/andrew/user/3498478")
        name2 = Name(name)
        self.assertTrue(name.match(name2), 'Name does not match deep copy of itself')

        name2 = name[:2]
        self.assertTrue(name2.match(name), 'Name did not match prefix')
        self.assertFalse(name.match(name2), 'Name should not match shorter name')
        self.assertTrue(Name().match(name), 'Empty name should always match another')
开发者ID:MAHIS,项目名称:PyNDN2,代码行数:11,代码来源:test_name_methods.py

示例2: _onCommandReceived

# 需要导入模块: from pyndn import Name [as 别名]
# 或者: from pyndn.Name import match [as 别名]
    def _onCommandReceived(self, prefix, interest, transport, prefixId):

        # first off, we shouldn't be here if we have no configured environment
        # just let this interest time out
        if (self._policyManager.getTrustRootIdentity() is None or
                self._policyManager.getEnvironmentPrefix() is None):
            return

        # if this is a cert request, we can serve it from our store (if it exists)
        certData = self._identityStorage.getCertificate(interest.getName())
        if certData is not None:
            self.log.info("Serving certificate request")
            # if we sign the certificate, we lose the controller's signature!
            self.sendData(certData, transport, False)
            return

        # else we must look in our command list to see if this requires verification
        # we dispatch directly or after verification as necessary

        # now we look for the first command that matches in our config
        self.log.debug("Received {}".format(interest.getName().toUri()))
        
        for command in self._commands:
            fullCommandName = Name(self.prefix).append(Name(command.suffix))
            if fullCommandName.match(interest.getName()):
                dispatchFunc = command.function
                
                if not command.isSigned:
                    responseData = dispatchFunc(interest)
                    self.sendData(responseData, transport)
                else:
                    try:
                        self._keyChain.verifyInterest(interest, 
                                self._makeVerifiedCommandDispatch(dispatchFunc, transport),
                                self.verificationFailed)
                        return
                    except Exception as e:
                        self.log.exception("Exception while verifying command", exc_info=True)
                        self.verificationFailed(interest)
                        return
        #if we get here, just let it timeout
        return
开发者ID:RayneHwang,项目名称:ndn-pi,代码行数:44,代码来源:iot_node.py

示例3: IotPolicyManager

# 需要导入模块: from pyndn import Name [as 别名]
# 或者: from pyndn.Name import match [as 别名]
class IotPolicyManager(ConfigPolicyManager):
    def __init__(self, identityStorage, configFilename=None):
        """
        :param pyndn.IdentityStorage: A class that stores signing identities and certificates.
        :param str configFilename: A configuration file specifying validation rules and network
            name settings.
        """

        # use the default configuration where possible
        # TODO: use environment variable for this, fall back to default
        path = os.path.dirname(__file__)
        templateFilename = os.path.join(path, '.default.conf')
        self._configTemplate = BoostInfoParser()
        self._configTemplate.read(templateFilename)

        if configFilename is None:
            configFilename = templateFilename
        
        certificateCache = CertificateCache()
        super(IotPolicyManager, self).__init__(configFilename, certificateCache)
        self._identityStorage = identityStorage

        self.setEnvironmentPrefix(None)
        self.setTrustRootIdentity(None)
        self.setDeviceIdentity(None)

    def updateTrustRules(self):
        """
        Should be called after either the device identity, trust root or network
        prefix is changed.

        Not called automatically in case they are all changing (typical for
        bootstrapping).

        Resets the validation rules if we don't have a trust root or enivronment

        """
        validatorTree = self._configTemplate["validator"][0].clone()

        if (self._environmentPrefix.size() > 0 and 
            self._trustRootIdentity.size() > 0 and 
            self._deviceIdentity.size() > 0):
            # don't sneak in a bad identity
            if not self._environmentPrefix.match(self._deviceIdentity):
                raise SecurityException("Device identity does not belong to configured network!")
            
            environmentUri = self._environmentPrefix.toUri()
            deviceUri = self._deviceIdentity.toUri()
             
            for rule in validatorTree["rule"]:
                ruleId = rule["id"][0].value
                if ruleId == 'Certificate Trust':
                    #modify the 'Certificate Trust' rule
                    rule["checker/key-locator/name"][0].value = environmentUri
                elif ruleId == 'Command Interests':
                    rule["filter/name"][0].value = deviceUri
                    rule["checker/key-locator/name"][0].value = environmentUri
            
        #remove old validation rules from config
        # replace with new validator rules
        self.config._root.subtrees["validator"] = [validatorTree]
        

    def inferSigningIdentity(self, fromName):
        """
        Used to map Data or Interest names to identitites.
        :param pyndn.Name fromName: The name of a Data or Interest packet
        """
        # works if you have an IotIdentityStorage
        return self._identityStorage.inferIdentityForName(fromName)

    def setTrustRootIdentity(self, identityName):
        """
        : param pyndn.Name identityName: The new identity to trust as the controller.
        """
        self._trustRootIdentity = Name(identityName)

    def getTrustRootIdentity(self):
        """
        : return pyndn.Name: The trusted controller's network name.
        """
        return Name(self._trustRootIdentity)

    def setEnvironmentPrefix(self, name):
        """
        : param pyndn.Name name: The new root of the network namespace (network prefix)
        """
        self._environmentPrefix = Name(name)

    def getEnvironmentPrefix(self):
        """
        :return: The root of the network namespace
        :rtype: pyndn.Name
        """
        return Name(self._environmentPrefix)

    def getDeviceIdentity(self):
        return self._deviceIdentity

    def setDeviceIdentity(self, identity):
#.........这里部分代码省略.........
开发者ID:zhehaowang,项目名称:ndn-pi,代码行数:103,代码来源:iot_policy_manager.py

示例4: findDeviceIdMatching

# 需要导入模块: from pyndn import Name [as 别名]
# 或者: from pyndn.Name import match [as 别名]
 def findDeviceIdMatching(self, matchPrefix):
     for d in self._deviceList:
         devName = Name(d.id)
         if devName.match(matchPrefix):
             return devName.toUri()
     return None
开发者ID:RayneHwang,项目名称:ndn-pi,代码行数:8,代码来源:consumer.py


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