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


Python Name.equals方法代码示例

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


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

示例1: PibKeyContainer

# 需要导入模块: from pyndn.name import Name [as 别名]
# 或者: from pyndn.name.Name import equals [as 别名]
class PibKeyContainer(object):
    """
    Create a PibKeyContainer for an identity with identityName. This constructor
    should only be called by PibIdentityImpl.

    :param Name identityName: The name of the identity, which is copied.
    :param PibImpl pibImpl: The PIB backend implementation.
    """
    def __init__(self, identityName, pibImpl):
        # Cache of loaded PibKeyImpl objects. Name => PibKeyImpl.
        self._keys = {}

        # Copy the Name.
        self._identityName = Name(identityName)
        self._pibImpl = pibImpl

        if pibImpl == None:
            raise ValueError("The pibImpl is None")

        self._keyNames = self._pibImpl.getKeysOfIdentity(identityName)

    def size(self):
        """
        Get the number of keys in the container.

        :return: The number of keys.
        :rtype: int
        """
        return len(self._keyNames)

    def add(self, key, keyName):
        """
        Add a key with name keyName into the container. If a key with the same
        name already exists, this replaces it.

        :param key: The buffer of encoded key bytes.
        :type key: an array which implements the buffer protocol
        :param Name keyName: The name of the key, which is copied.
        :return: The PibKey object.
        :rtype: PibKey
        :raises ValueError: If the name of the key does not match the identity
          name.
        """
        if not self._identityName.equals(PibKey.extractIdentityFromKeyName(keyName)):
            raise ValueError("The key name `" + keyName.toUri() +
              "` does not match the identity name `" +
              self._identityName.toUri() + "`")

        # Copy the Name.
        self._keyNames.add(Name(keyName))
        self._keys[Name(keyName)] = PibKeyImpl(keyName, key, self._pibImpl)

        return self.get(keyName)

    def remove(self, keyName):
        """
        Remove the key with name keyName from the container, and its related
        certificates. If the key does not exist, do nothing.

        :param Name keyName: The name of the key.
        :raises ValueError: If keyName does not match the identity name.
        """
        if not self._identityName.equals(PibKey.extractIdentityFromKeyName(keyName)):
          raise ValueError("Key name `" + keyName.toUri() +
            "` does not match identity `" + self._identityName.toUri() + "`")

        try:
            self._keyNames.remove(keyName)
        except KeyError:
            # Do nothing if it doesn't exist.
            pass

        try:
            del self._keys[keyName]
        except KeyError:
            # Do nothing if it doesn't exist.
            pass

        self._pibImpl.removeKey(keyName)

    def get(self, keyName):
        """
        Get the key with name keyName from the container.

        :param Name keyName: The name of the key.
        :return: The PibKey object.
        :rtype: PibKey
        :raises ValueError: If keyName does not match the identity name.
        :raises Pib.Error: If the key does not exist.
        """
        if not self._identityName.equals(PibKey.extractIdentityFromKeyName(keyName)):
            raise ValueError("Key name `" + keyName.toUri() +
              "` does not match identity `" + self._identityName.toUri() + "`")

        try:
            pibKeyImpl = self._keys[keyName]
        except KeyError:
            pibKeyImpl = None

        if pibKeyImpl == None:
#.........这里部分代码省略.........
开发者ID:named-data,项目名称:PyNDN2,代码行数:103,代码来源:pib_key_container.py

示例2: FullPSync2017

# 需要导入模块: from pyndn.name import Name [as 别名]
# 或者: from pyndn.name.Name import equals [as 别名]

#.........这里部分代码省略.........
        # random1 is from 0.0 to 1.0.
        random1 = self._systemRandom.random()
        # Get a jitter of +/- syncInterestLifetime_ * 0.2 .
        jitter = (random1 - 0.5) * (self._syncInterestLifetime * 0.2)

        self._face.callLater(
          self._syncInterestLifetime / 2 + jitter, self._sendSyncInterest)

        syncInterest = Interest(syncInterestName)
        syncInterest.setInterestLifetimeMilliseconds(self._syncInterestLifetime)
        syncInterest.refreshNonce()

        SegmentFetcher.fetch(
          self._face, syncInterest, None,
          lambda content: self._onSyncData(content, syncInterest),
          FullPSync2017._onError)

        logging.getLogger(__name__).debug("sendFullSyncInterest, nonce: " +
          syncInterest.getNonce().toHex() + ", hash: " +
          str(abs(hash(syncInterestName))))

    @staticmethod
    def _onError(errorCode, message):
        logging.getLogger(__name__).info("Cannot fetch sync data, error: " +
        str(errorCode) + " message: " + message)

    def _onSyncInterest(self, prefixName, interest, face, interestFilterId, filter):
        """
        Process a sync interest received from another party.
        This gets the difference between our IBLT and the IBLT in the other sync
        interest. If we cannot get the difference successfully, then send an
        application Nack. If we have some things in our IBLT that the other side
        does not have, then reply with the content. Or, if the number of
        different items is greater than threshold or equals zero, then send a
        Nack. Otherwise add the sync interest into the pendingEntries_ map with
        the interest name as the key and a PendingEntryInfoFull as the value.

        :param Name prefixName: The prefix Name for the sync group which we
          registered.
        :param Interest interest: The the received Interest.
        """
        if self._segmentPublisher.replyFromStore(interest.getName()):
            return

        nameWithoutSyncPrefix = interest.getName().getSubName(prefixName.size())

        if nameWithoutSyncPrefix.size() == 1:
            # Get /<prefix>/IBLT from /<prefix>/IBLT
            interestName = interest.getName()
        elif nameWithoutSyncPrefix.size() == 3:
            # Get /<prefix>/IBLT from /<prefix>/IBLT/<version>/<segment-no>
            interestName = interest.getName().getPrefix(-2)
        else:
            return

        ibltName = interestName.get(-1)

        logging.getLogger(__name__).debug("Full Sync Interest received, nonce: " +
          interest.getNonce().toHex() + ", hash:" + str(abs(hash(interestName))))

        iblt = InvertibleBloomLookupTable(self._expectedNEntries)
        try:
            iblt.initialize(ibltName.getValue())
        except Exception as ex:
            logging.getLogger(__name__).error(
              "Error in iblt.initialize: %s", str(ex))
开发者ID:named-data,项目名称:PyNDN2,代码行数:70,代码来源:full_psync2017.py


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