diff options
author | Ilya Etingof <etingof@gmail.com> | 2017-10-06 01:16:56 +0200 |
---|---|---|
committer | Ilya Etingof <etingof@gmail.com> | 2017-10-06 01:16:56 +0200 |
commit | 0f32c00d89eae2f86b2282ffc50805e059be5492 (patch) | |
tree | 1dee3b5e2faac05849bfc499a517240a80f9e4f3 | |
parent | 9d35779f1cf8dce05bb8abe12aa7a2bb0732967a (diff) | |
download | pysnmp-git-0f32c00d89eae2f86b2282ffc50805e059be5492.tar.gz |
fixed Bits.clone()/subtype()
-rw-r--r-- | CHANGES.txt | 1 | ||||
-rw-r--r-- | pysnmp/proto/rfc1902.py | 20 |
2 files changed, 12 insertions, 9 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index 5fbe9d3e..6ed56337 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -21,6 +21,7 @@ Revision 4.3.10, released 2017-10-XX - Fixed multiple bugs in SNMP table indices rendering, especially the InetAddressIPv6 type which was severely broken. - Fixed crashing Bits.prettyPrint() implementation +- Fixed crashing Bits.clone()/subtype() implementation - Fixed leaking exceptions bubbling up from the asyncio and Twisted adapters Revision 4.3.9, released 2017-07-26 diff --git a/pysnmp/proto/rfc1902.py b/pysnmp/proto/rfc1902.py index 805132c9..60e31930 100644 --- a/pysnmp/proto/rfc1902.py +++ b/pysnmp/proto/rfc1902.py @@ -609,31 +609,33 @@ class Bits(OctetString): def clone(self, *args, **kwargs): namedValues = kwargs.pop('namedValues', self.namedValues) - clone = OctetString.clone(self, *args, **kwargs) + args = args and self.prettyIn(args[0], namedValues=namedValues) + clone = OctetString.clone(self, args, **kwargs) clone.namedValues = namedValues return clone def subtype(self, *args, **kwargs): namedValues = kwargs.pop('namedValues', self.namedValues) - clone = OctetString.subtype(self, *args, **kwargs) + args = args and self.prettyIn(args[0], namedValues=namedValues) + clone = OctetString.subtype(self, args, **kwargs) clone.namedValues = namedValues return clone - def prettyIn(self, bits): + def prettyIn(self, bits, namedValues=None): if not isinstance(bits, (tuple, list)): return OctetString.prettyIn(self, bits) # raw bitstring - _octets = [] + octets = [] for bit in bits: # tuple of named bits - v = self.namedValues.getValue(bit) + v = (namedValues or self.namedValues).getValue(bit) if v is None: raise error.ProtocolError( 'Unknown named bit %s' % bit ) d, m = divmod(v, 8) - if d >= len(_octets): - _octets.extend([0] * (d - len(_octets) + 1)) - _octets[d] |= 0x01 << (7 - m) - return OctetString.prettyIn(self, _octets) + if d >= len(octets): + octets.extend([0] * (d - len(octets) + 1)) + octets[d] |= 0x01 << (7 - m) + return OctetString.prettyIn(self, octets) def prettyOut(self, value): names = [] |