def clone(self, value=univ.noValue, **kwargs):
"""Clone this instance.
If *value* is specified, use its tag as the component type selector,
and itself as the component value.
:param value: (Optional) the component value.
:type value: :py:obj:`pyasn1.type.base.Asn1ItemBase`
:return: the cloned instance.
:rtype: :py:obj:`pysnmp.proto.rfc1155.NetworkAddress`
:raise: :py:obj:`pysnmp.smi.error.SmiError`:
if the type of *value* is not allowed for this Choice instance.
"""
cloned = univ.Choice.clone(self, **kwargs)
if value is not univ.noValue:
if isinstance(value, NetworkAddress):
value = value.getComponent()
elif not isinstance(value, IpAddress):
# IpAddress is the only supported type, perhaps forever because
# this is SNMPv1.
value = IpAddress(value)
try:
tagSet = value.tagSet
except AttributeError:
raise PyAsn1Error('component value %r has no tag set' % (value,))
cloned.setComponentByType(tagSet, value)
return cloned
# RFC 1212, section 4.1.6:
#
# "(5) NetworkAddress-valued: `n+1' sub-identifiers, where `n'
# depends on the kind of address being encoded (the first
# sub-identifier indicates the kind of address, value 1
# indicates an IpAddress);"
评论列表
文章目录