summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlya Etingof <ietingof@redhat.com>2017-02-01 13:03:10 +0100
committerIlya Etingof <ietingof@redhat.com>2017-02-01 13:03:10 +0100
commit6d75ed7b21c05c959a4a56e1ff72b7e6f495512e (patch)
treea3fc45f2c9c8fda6c4d7df077865a70d68cbe97d
parent115e485259c98619a72702cc3c51651d69523c34 (diff)
downloadpysnmp-git-6d75ed7b21c05c959a4a56e1ff72b7e6f495512e.tar.gz
TextualConvention.prettyOut improved to be better compliant with SMI
-rw-r--r--CHANGES.txt2
-rw-r--r--pysnmp/smi/mibs/SNMPv2-TC.py37
2 files changed, 12 insertions, 27 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index d539e1c0..c95bfaac 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -16,6 +16,8 @@ Github `repo <https://github.com/etingof/pysnmp>`_
Original and more standard implementation can still be used
with the usmAesBlumenthalCfb192Protocol and
usmAesBlumenthalCfb192Protocol IDs respectively.
+- TextualConvention.prettyOut() improved to produce prettier and
+ more SMI-compliant output.
- Fix to NotificationType to make additional var-binds overriding
MIB objects implicitly included through NOTIFICATION-TYPE OBJECTS.
- Fix to SNMP engine boots counter persistence on Python 3.
diff --git a/pysnmp/smi/mibs/SNMPv2-TC.py b/pysnmp/smi/mibs/SNMPv2-TC.py
index 36c50a3f..c08ccee6 100644
--- a/pysnmp/smi/mibs/SNMPv2-TC.py
+++ b/pysnmp/smi/mibs/SNMPv2-TC.py
@@ -5,6 +5,7 @@
# License: http://pysnmp.sf.net/license.html
#
import sys
+import inspect
from pysnmp.smi.error import *
from pysnmp import debug
from pyasn1.compat import octets
@@ -35,12 +36,9 @@ class TextualConvention:
reference = ''
bits = ()
__integer = Integer()
- __counter32 = Counter32()
__unsigned32 = Unsigned32()
__timeticks = TimeTicks()
- __counter64 = Counter64()
__octetString = OctetString()
- __objectIdentifier = ObjectIdentifier()
def getDisplayHint(self):
return self.displayHint
@@ -62,11 +60,9 @@ class TextualConvention:
def prettyOut(self, value): # override asn1 type method
"""Implements DISPLAY-HINT evaluation"""
- if self.displayHint and (self.__integer.isSuperTypeOf(self) or
+ if self.displayHint and (self.__integer.isSuperTypeOf(self) and not self.getNamedValues() or
self.__unsigned32.isSuperTypeOf(self) or
- self.__timeticks.isSuperTypeOf(self) or
- self.__counter32.isSuperTypeOf(self) or
- self.__counter64.isSuperTypeOf(self)):
+ self.__timeticks.isSuperTypeOf(self)):
_ = lambda t, f=0: (t, f)
t, f = _(*self.displayHint.split('-'))
if t == 'x':
@@ -181,26 +177,13 @@ class TextualConvention:
# 'Unparsed display hint left: %s' % d
# )
return r
- elif self.__objectIdentifier.isSuperTypeOf(self):
- return self.__objectIdentifier.prettyOut(value)
- elif self.__octetString.isSuperTypeOf(self):
- return self.__octetString.prettyOut(value)
- else:
- return str(value)
-
-
-# elif self.bits:
-# try:
-# return self.bits[value]
-# except Exception:
-# raise SmiError(
-# 'Enumeratin resolution failure for %s: %s' % (self, sys.exc_info()[1])
-# )
-
-# XXX
-# def prettyIn(self, value):
-# # XXX parse TC syntax
-# return str(value)
+
+ for base in inspect.getmro(self.__class__):
+ if base != self.__class__ and issubclass(base, Asn1Item):
+ return base.prettyOut(self, value)
+
+ # this should never happen
+ return str(value)
class DisplayString(TextualConvention, OctetString):
subtypeSpec = OctetString.subtypeSpec + ValueSizeConstraint(0, 255)