diff options
author | elie <elie> | 2011-11-06 20:37:09 +0000 |
---|---|---|
committer | elie <elie> | 2011-11-06 20:37:09 +0000 |
commit | f0406dd01c46230ebbcd4f8c4a47fdbc270e64ef (patch) | |
tree | cae924c26bc40e6caafde18e657ab7fbb8794bbe /pysnmp/smi/view.py | |
parent | 6781949a085961ff2eb6f4603a52249e99c4ce7d (diff) | |
download | pysnmp-git-f0406dd01c46230ebbcd4f8c4a47fdbc270e64ef.tar.gz |
major overhawl aimed at Python 2.4 through 3.2 compatibility
Diffstat (limited to 'pysnmp/smi/view.py')
-rw-r--r-- | pysnmp/smi/view.py | 41 |
1 files changed, 20 insertions, 21 deletions
diff --git a/pysnmp/smi/view.py b/pysnmp/smi/view.py index fcdd7168..e7afd2ba 100644 --- a/pysnmp/smi/view.py +++ b/pysnmp/smi/view.py @@ -1,11 +1,19 @@ # MIB modules management -from types import ClassType, InstanceType, TupleType +import sys from pysnmp.smi.indices import OrderedDict, OidOrderedDict from pysnmp.smi import error from pysnmp import debug __all__ = [ 'MibViewController' ] +if sys.version_info[0] <= 2: + import types + classTypes = (types.ClassType, type) + instanceTypes = (types.InstanceType, object) +else: + classTypes = (type,) + instanceTypes = (object,) + class MibViewController: def __init__(self, mibBuilder): self.mibBuilder = mibBuilder @@ -34,26 +42,17 @@ class MibViewController: # This is potentionally ambiguous mapping. Sort modules in # ascending age for resolution - def __sortFun(x, y, s=self.mibBuilder.mibSymbols): + def __sortFun(x, s=self.mibBuilder.mibSymbols): if "PYSNMP_MODULE_ID" in s[x]: - m1 = s[x]["PYSNMP_MODULE_ID"] - else: - m1 = None - if "PYSNMP_MODULE_ID" in s[y]: - m2 = s[y]["PYSNMP_MODULE_ID"] + m = s[x]["PYSNMP_MODULE_ID"] + r = m.getRevisions() + if r: + return r[0] else: - m2 = None - r1 = r2 = "1970-01-01 00:00" - if m1: - r = m1.getRevisions() - if r: r1 = r[0] - if m2: - r = m2.getRevisions() - if r: r2 = r[0] - return cmp(r1, r2) + return "1970-01-01 00:00" - modNames = self.mibBuilder.mibSymbols.keys() - modNames.sort(__sortFun) + modNames = list(self.mibBuilder.mibSymbols.keys()) + modNames.sort(key=__sortFun) # Index modules names for modName in [ '' ] + modNames: @@ -74,7 +73,7 @@ class MibViewController: for n, v in self.mibBuilder.mibSymbols[modName].items(): if n == "PYSNMP_MODULE_ID": # do not index this special symbol continue - if type(v) == ClassType: + if isinstance(v, classTypes): if n in mibMod['typeToModIdx']: raise error.SmiError( 'Duplicate SMI type %s::%s, has %s' % \ @@ -82,7 +81,7 @@ class MibViewController: ) globMibMod['typeToModIdx'][n] = modName mibMod['typeToModIdx'][n] = modName - elif type(v) == InstanceType: + elif isinstance(v, instanceTypes): if isinstance(v, MibScalarInstance): continue if n in mibMod['varToNameIdx']: @@ -175,7 +174,7 @@ class MibViewController: nodeName[:-1], oidToLabelIdx, labelToOidIdx ) suffix = suffix + nodeName[-1:] - resLabel = label + suffix + resLabel = label + tuple([ str(x) for x in suffix ]) if resLabel in labelToOidIdx: return labelToOidIdx[resLabel], resLabel, () resOid = oid + suffix |