diff options
author | Ilya Etingof <etingof@gmail.com> | 2018-09-09 11:03:25 +0200 |
---|---|---|
committer | Ilya Etingof <etingof@gmail.com> | 2018-09-09 12:26:10 +0200 |
commit | 2a9466dbe4da15757f888eb88200923a57ca09b0 (patch) | |
tree | dae16e5f8de1a82378276319f259432afdb43968 | |
parent | fcd4435dd8333c6994330386b815db23c4d4de26 (diff) | |
download | pysnmp-git-2a9466dbe4da15757f888eb88200923a57ca09b0.tar.gz |
Tolerate duplicate enumerations
Possible duplicate enumerations in `Bits` and `Integer` SMI types
causes pyasn1 exception. This fix reduces duplicates prior to
passing them to pyasn1.
-rw-r--r-- | CHANGES.txt | 2 | ||||
-rw-r--r-- | pysnmp/proto/rfc1902.py | 17 |
2 files changed, 15 insertions, 4 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index c691e96e..dd86b589 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -7,6 +7,8 @@ Revision 4.4.6, released 2018-08-XX - Fixed `CommandGeneratorLcdConfigurator.unconfigure()` to fully clean up internal caches, otherwise repetitive attempts to configure the target would fail. +- Fix to tolerate possible duplicate enumerations in `Bits` and `Integer` + SMI types. Revision 4.4.5, released 2018-08-05 ----------------------------------- diff --git a/pysnmp/proto/rfc1902.py b/pysnmp/proto/rfc1902.py index 3370f478..ee82ef5a 100644 --- a/pysnmp/proto/rfc1902.py +++ b/pysnmp/proto/rfc1902.py @@ -128,12 +128,17 @@ class Integer(Integer32): @classmethod def withNamedValues(cls, **values): - """Creates a subclass with discreet named values constraint. + """Create a subclass with discreet named values constraint. + + Reduce fully duplicate enumerations along the way. """ + enums = set(cls.namedValues.items()) + enums.update(values.items()) class X(cls): - namedValues = cls.namedValues + namedval.NamedValues(*values.items()) - subtypeSpec = cls.subtypeSpec + constraint.SingleValueConstraint(*values.values()) + namedValues = namedval.NamedValues(*enums) + subtypeSpec = cls.subtypeSpec + constraint.SingleValueConstraint( + *values.values()) X.__name__ = cls.__name__ return X @@ -637,10 +642,14 @@ class Bits(OctetString): @classmethod def withNamedBits(cls, **values): """Creates a subclass with discreet named bits constraint. + + Reduce fully duplicate enumerations along the way. """ + enums = set(cls.namedValues.items()) + enums.update(values.items()) class X(cls): - namedValues = cls.namedValues + namedval.NamedValues(*values.items()) + namedValues = namedval.NamedValues(*enums) X.__name__ = cls.__name__ return X |