本文整理汇总了Python中pyndn.util.change_counter.ChangeCounter.set方法的典型用法代码示例。如果您正苦于以下问题:Python ChangeCounter.set方法的具体用法?Python ChangeCounter.set怎么用?Python ChangeCounter.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyndn.util.change_counter.ChangeCounter
的用法示例。
在下文中一共展示了ChangeCounter.set方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Data
# 需要导入模块: from pyndn.util.change_counter import ChangeCounter [as 别名]
# 或者: from pyndn.util.change_counter.ChangeCounter import set [as 别名]
class Data(object):
def __init__(self, value = None):
if isinstance(value, Data):
# Copy the values.
self._name = ChangeCounter(Name(value.getName()))
self._metaInfo = ChangeCounter(MetaInfo(value.getMetaInfo()))
self._signature = ChangeCounter(value.getSignature().clone())
self._content = value._content
self._defaultWireEncoding = value.getDefaultWireEncoding()
self._defaultWireEncodingFormat = value._defaultWireEncodingFormat
else:
self._name = ChangeCounter(Name(value) if type(value) is Name
else Name())
self._metaInfo = ChangeCounter(MetaInfo())
self._signature = ChangeCounter(Sha256WithRsaSignature())
self._content = Blob()
self._defaultWireEncoding = SignedBlob()
self._defaultWireEncodingFormat = None
self._getDefaultWireEncodingChangeCount = 0
self._changeCount = 0
def wireEncode(self, wireFormat = None):
"""
Encode this Data for a particular wire format. If wireFormat is the
default wire format, also set the defaultWireEncoding field to the
encoded result.
:param wireFormat: (optional) A WireFormat object used to encode this
Data object. If omitted, use WireFormat.getDefaultWireFormat().
:type wireFormat: A subclass of WireFormat
:return: The encoded buffer in a SignedBlob object.
:rtype: SignedBlob
"""
if wireFormat == None:
# Don't use a default argument since getDefaultWireFormat can change.
wireFormat = WireFormat.getDefaultWireFormat()
if (not self.getDefaultWireEncoding().isNull() and
self.getDefaultWireEncodingFormat() == wireFormat):
# We already have an encoding in the desired format.
return self.getDefaultWireEncoding()
(encoding, signedPortionBeginOffset, signedPortionEndOffset) = \
wireFormat.encodeData(self)
wireEncoding = SignedBlob(
encoding, signedPortionBeginOffset, signedPortionEndOffset)
if wireFormat == WireFormat.getDefaultWireFormat():
# This is the default wire encoding.
self._setDefaultWireEncoding(
wireEncoding, WireFormat.getDefaultWireFormat())
return wireEncoding
def wireDecode(self, input, wireFormat = None):
"""
Decode the input using a particular wire format and update this Data.
If wireFormat is the default wire format, also set the
defaultWireEncoding to another pointer to the input.
:param input: The array with the bytes to decode. If input is not a
Blob, then copy the bytes to save the defaultWireEncoding (otherwise
take another pointer to the same Blob).
:type input: A Blob or an array type with int elements
:param wireFormat: (optional) A WireFormat object used to decode this
Data object. If omitted, use WireFormat.getDefaultWireFormat().
:type wireFormat: A subclass of WireFormat
"""
if wireFormat == None:
# Don't use a default argument since getDefaultWireFormat can change.
wireFormat = WireFormat.getDefaultWireFormat()
# If input is a blob, get its buf().
decodeBuffer = input.buf() if isinstance(input, Blob) else input
(signedPortionBeginOffset, signedPortionEndOffset) = \
wireFormat.decodeData(self, decodeBuffer)
if wireFormat == WireFormat.getDefaultWireFormat():
# This is the default wire encoding. In the Blob constructor, set
# copy true, but if input is already a Blob, it won't copy.
self._setDefaultWireEncoding(SignedBlob(
Blob(input, True),
signedPortionBeginOffset, signedPortionEndOffset),
WireFormat.getDefaultWireFormat())
else:
self._setDefaultWireEncoding(SignedBlob(), None)
def getName(self):
"""
Get the data packet's name.
:return: The name.
:rtype: Name
"""
return self._name.get()
def getMetaInfo(self):
"""
Get the data packet's meta info.
#.........这里部分代码省略.........
示例2: Sha256WithRsaSignature
# 需要导入模块: from pyndn.util.change_counter import ChangeCounter [as 别名]
# 或者: from pyndn.util.change_counter.ChangeCounter import set [as 别名]
class Sha256WithRsaSignature(Signature):
"""
Create a new Sha256WithRsaSignature object, possibly copying values from
another object.
:param value: (optional) If value is a Sha256WithRsaSignature, copy its
values. If value is omitted, the keyLocator is the default with
unspecified values and the signature is unspecified.
:param value: Sha256WithRsaSignature
"""
def __init__(self, value = None):
if value == None:
self._keyLocator = ChangeCounter(KeyLocator())
self._signature = Blob()
elif type(value) is Sha256WithRsaSignature:
# Copy its values.
self._keyLocator = ChangeCounter(KeyLocator(value.getKeyLocator()))
self._signature = value._signature
else:
raise RuntimeError(
"Unrecognized type for Sha256WithRsaSignature constructor: " +
str(type(value)))
self._changeCount = 0
def clone(self):
"""
Create a new Sha256WithRsaSignature which is a copy of this object.
:return: A new object which is a copy of this object.
:rtype: Sha256WithRsaSignature
"""
return Sha256WithRsaSignature(self)
def getKeyLocator(self):
"""
Get the key locator.
:return: The key locator.
:rtype: KeyLocator
"""
return self._keyLocator.get()
def getSignature(self):
"""
Get the data packet's signature bytes.
:return: The signature bytes as a Blob, which maybe isNull().
:rtype: Blob
"""
return self._signature
def setKeyLocator(self, keyLocator):
"""
Set the key locator to a copy of the given keyLocator.
:param KeyLocator keyLocator: The KeyLocator to copy.
"""
self._keyLocator.set(KeyLocator(keyLocator))
self._changeCount += 1
def setSignature(self, signature):
"""
Set the signature bytes to the given value.
:param signature: The array with the signature bytes. If signature is
not a Blob, then create a new Blob to copy the bytes (otherwise
take another pointer to the same Blob).
:type signature: A Blob or an array type with int elements
"""
self._signature = (signature if type(signature) is Blob
else Blob(signature))
self._changeCount += 1
def clear(self):
self._keyLocator.get().clear()
self._signature = Blob()
self._changeCount += 1
def getChangeCount(self):
"""
Get the change count, which is incremented each time this object
(or a child object) is changed.
:return: The change count.
:rtype: int
"""
# Make sure each of the checkChanged is called.
changed = self._keyLocator.checkChanged()
if changed:
# A child object has changed, so update the change count.
self._changeCount += 1
return self._changeCount
# Create managed properties for read/write properties of the class for more pythonic syntax.
keyLocator = property(getKeyLocator, setKeyLocator)
signature = property(getSignature, setSignature)
示例3: KeyLocator
# 需要导入模块: from pyndn.util.change_counter import ChangeCounter [as 别名]
# 或者: from pyndn.util.change_counter.ChangeCounter import set [as 别名]
class KeyLocator(object):
"""
Create a new KeyLocator object, possibly copying values from
another object.
:param KeyLocator value: (optional) If value is a KeyLocator, copy its
values. If value is omitted, set the fields to unspecified.
"""
def __init__(self, value = None):
if value == None:
self._type = None
self._keyName = ChangeCounter(Name())
self._keyData = Blob()
elif type(value) is KeyLocator:
# Copy its values.
self._type = value._type
self._keyName = ChangeCounter(Name(value.getKeyName()))
self._keyData = value._keyData
else:
raise RuntimeError(
"Unrecognized type for KeyLocator constructor: " +
repr(type(value)))
self._changeCount = 0
def getType(self):
"""
Get the key locator type. If KeyLocatorType.KEYNAME, you may also
getKeyName(). If KeyLocatorType.KEY_LOCATOR_DIGEST, you may also
getKeyData() to get the digest.
:return: The key locator type, or None if not specified.
:rtype: an int from KeyLocatorType
"""
return self._type
def getKeyName(self):
"""
Get the key name. This is meaningful if getType() is
KeyLocatorType.KEYNAME.
:return: The key name. If not specified, the Name is empty.
:rtype: Name
"""
return self._keyName.get()
def getKeyData(self):
"""
Get the key data. This is the digest bytes if getType() is
KeyLocatorType.KEY_LOCATOR_DIGEST.
:return: The key data as a Blob, which isNull() if unspecified.
:rtype: Blob
"""
return self._keyData
def setType(self, type):
"""
Set the key locator type. If KeyLocatorType.KEYNAME, you must also
setKeyName(). If KeyLocatorType.KEY_LOCATOR_DIGEST, you must also
setKeyData() to the digest.
:param type: The key locator type. If None, the type is unspecified.
:type type: an int from KeyLocatorType
"""
self._type = None if type == None or type < 0 else type
self._changeCount += 1
def setKeyName(self, keyName):
"""
Set key name to a copy of the given Name. This is the name if
getType() is KeyLocatorType.KEYNAME.
:param Name keyName: The key name which is copied.
"""
self._keyName.set(keyName if type(keyName) is Name else Name(keyName))
self._changeCount += 1
def setKeyData(self, keyData):
"""
Set the key data to the given value. This is the digest bytes if
getType() is KeyLocatorType.KEY_LOCATOR_DIGEST.
:param keyData: The array with the key data bytes. If keyData is not a
Blob, then create a new Blob to copy the bytes (otherwise
take another pointer to the same Blob).
:type keyData: A Blob or an array type with int elements
"""
self._keyData = keyData if type(keyData) is Blob else Blob(keyData)
self._changeCount += 1
def clear(self):
"""
Clear the fields and set the type to None.
"""
self._type = None
self._keyName.get().clear()
self._keyData = Blob()
self._changeCount += 1
#.........这里部分代码省略.........
示例4: Interest
# 需要导入模块: from pyndn.util.change_counter import ChangeCounter [as 别名]
# 或者: from pyndn.util.change_counter.ChangeCounter import set [as 别名]
#.........这里部分代码省略.........
def getNonce(self):
"""
Return the nonce value from the incoming interest. If you change any of
the fields in this Interest object, then the nonce value is cleared.
:return: The nonce. If isNull() then the nonce is omitted.
:rtype: Blob
"""
if self._getNonceChangeCount != self.getChangeCount():
# The values have changed, so the existing nonce is invalidated.
self._nonce = Blob()
self._getNonceChangeCount = self.getChangeCount()
return self._nonce
def getScope(self):
"""
Get the interest scope.
:return: The scope, or None if not specified.
:rtype: int
"""
return self._scope
def getInterestLifetimeMilliseconds(self):
"""
Get the interest lifetime.
:return: The interest lifetime in milliseconds, or None if not specified.
:rtype: float
"""
return self._interestLifetimeMilliseconds
def setName(self, name):
self._name.set(name if type(name) is Name else Name(name))
self._changeCount += 1
def setMinSuffixComponents(self, minSuffixComponents):
self._minSuffixComponents = minSuffixComponents
self._changeCount += 1
def setMaxSuffixComponents(self, maxSuffixComponents):
self._maxSuffixComponents = maxSuffixComponents
self._changeCount += 1
def setKeyLocator(self, keyLocator):
"""
Set this interest to use a copy of the given keyLocator.
Note: You can also change this interest's key locator modifying
the object from getKeyLocator().
:param KeyLocator keyLocator: The KeyLocator that is copied.
"""
self._keyLocator.set(keyLocator if type(keyLocator) is KeyLocator else KeyLocator())
self._changeCount += 1
def setExclude(self, exclude):
"""
Set this interest to use a copy of the given exclude object.
Note: You can also change this interest's exclude object modifying
the object from getExclude().
:param Exclude exclude: The exlcude object that is copied.
"""
self._exclude.set(Exclude(exclude) if type(exclude) is Exclude else Exclude())
self._changeCount += 1
示例5: KeyLocator
# 需要导入模块: from pyndn.util.change_counter import ChangeCounter [as 别名]
# 或者: from pyndn.util.change_counter.ChangeCounter import set [as 别名]
class KeyLocator(object):
"""
Create a new KeyLocator object, possibly copying values from
another object.
:param KeyLocator value: (optional) If value is a KeyLocator, copy its
values. If value is omitted, set the fields to unspecified.
"""
def __init__(self, value = None):
if value == None:
self._type = None
self._keyName = ChangeCounter(Name())
self._keyData = Blob()
elif type(value) is KeyLocator:
# Copy its values.
self._type = value._type
self._keyName = ChangeCounter(Name(value.getKeyName()))
self._keyData = value._keyData
else:
raise RuntimeError(
"Unrecognized type for KeyLocator constructor: " +
str(type(value)))
self._changeCount = 0
def getType(self):
"""
Get the key locator type. If KeyLocatorType.KEYNAME, you may also
getKeyName(). If KeyLocatorType.KEY_LOCATOR_DIGEST, you may also
getKeyData() to get the digest.
:return: The key locator type, or None if not specified.
:rtype: an int from KeyLocatorType
"""
return self._type
def getKeyName(self):
"""
Get the key name. This is meaningful if getType() is
KeyLocatorType.KEYNAME.
:return: The key name. If not specified, the Name is empty.
:rtype: Name
"""
return self._keyName.get()
def getKeyData(self):
"""
Get the key data. This is the digest bytes if getType() is
KeyLocatorType.KEY_LOCATOR_DIGEST.
:return: The key data as a Blob, which isNull() if unspecified.
:rtype: Blob
"""
return self._keyData
def setType(self, type):
"""
Set the key locator type. If KeyLocatorType.KEYNAME, you must also
setKeyName(). If KeyLocatorType.KEY_LOCATOR_DIGEST, you must also
setKeyData() to set the digest.
:param type: The key locator type. If None, the type is unspecified.
:type type: an int from KeyLocatorType
"""
self._type = None if type == None or type < 0 else type
self._changeCount += 1
def setKeyName(self, keyName):
"""
Set key name to a copy of the given Name. This is the name if
getType() is KeyLocatorType.KEYNAME.
:param Name keyName: The key name which is copied.
"""
self._keyName.set(keyName if type(keyName) is Name else Name(keyName))
self._changeCount += 1
def setKeyData(self, keyData):
"""
Set the key data to the given value. This is the digest bytes if
getType() is KeyLocatorType.KEY_LOCATOR_DIGEST.
:param keyData: The array with the key data bytes. If keyData is not a
Blob, then create a new Blob to copy the bytes (otherwise
take another pointer to the same Blob).
:type keyData: A Blob or an array type with int elements
"""
self._keyData = keyData if type(keyData) is Blob else Blob(keyData)
self._changeCount += 1
def clear(self):
"""
Clear the fields and set the type to None.
"""
self._type = None
self._keyName.get().clear()
self._keyData = Blob()
self._changeCount += 1
#.........这里部分代码省略.........