summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlya Etingof <etingof@gmail.com>2018-09-09 11:03:25 +0200
committerIlya Etingof <etingof@gmail.com>2018-09-09 12:26:10 +0200
commit2a9466dbe4da15757f888eb88200923a57ca09b0 (patch)
treedae16e5f8de1a82378276319f259432afdb43968
parentfcd4435dd8333c6994330386b815db23c4d4de26 (diff)
downloadpysnmp-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.txt2
-rw-r--r--pysnmp/proto/rfc1902.py17
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