From aa91642cc3e8723439c9e55f16c20735b0d1668d Mon Sep 17 00:00:00 2001 From: Ilya Etingof Date: Tue, 5 Apr 2016 23:06:55 +0200 Subject: pep8 reformatted --- .../asyncore/agent/cmdrsp/custom-mib-controller.py | 4 +- pysnmp/cache.py | 2 + pysnmp/debug.py | 3 +- pysnmp/smi/compiler.py | 7 ++- pysnmp/smi/error.py | 24 +++++++++ pysnmp/smi/exval.py | 1 - pysnmp/smi/indices.py | 5 ++ pysnmp/smi/instrum.py | 62 ++++++++++++---------- pysnmp/smi/rfc1902.py | 52 +++++++++++------- pysnmp/smi/view.py | 35 ++++++------ 10 files changed, 128 insertions(+), 67 deletions(-) diff --git a/examples/v3arch/asyncore/agent/cmdrsp/custom-mib-controller.py b/examples/v3arch/asyncore/agent/cmdrsp/custom-mib-controller.py index 54aec899..1a03e725 100644 --- a/examples/v3arch/asyncore/agent/cmdrsp/custom-mib-controller.py +++ b/examples/v3arch/asyncore/agent/cmdrsp/custom-mib-controller.py @@ -53,8 +53,8 @@ snmpContext = context.SnmpContext(snmpEngine) # any Managed Objects attached. It supports only GET's and # always echos request var-binds in response. class EchoMibInstrumController(instrum.AbstractMibInstrumController): - def readVars(self, vars, acInfo=(None, None)): - return [(ov[0], v2c.OctetString('You queried OID %s' % ov[0])) for ov in vars] + def readVars(self, varBinds, acInfo=(None, None)): + return [(ov[0], v2c.OctetString('You queried OID %s' % ov[0])) for ov in varBinds] # Create a custom Management Instrumentation Controller and register at diff --git a/pysnmp/cache.py b/pysnmp/cache.py index 00fc047b..12910d41 100644 --- a/pysnmp/cache.py +++ b/pysnmp/cache.py @@ -6,6 +6,8 @@ # # Limited-size dictionary-like class to use for caches # + + class Cache: def __init__(self, maxSize=256): self.__maxSize = maxSize diff --git a/pysnmp/debug.py b/pysnmp/debug.py index 75b7df46..80d7d6ec 100644 --- a/pysnmp/debug.py +++ b/pysnmp/debug.py @@ -122,4 +122,5 @@ def setLogger(l): def hexdump(octets): - return ' '.join(['%s%.2X' % (n % 16 == 0 and ('\n%.5d: ' % n) or '', x) for n, x in zip(range(len(octets)), octs2ints(octets))]) + return ' '.join( + ['%s%.2X' % (n % 16 == 0 and ('\n%.5d: ' % n) or '', x) for n, x in zip(range(len(octets)), octs2ints(octets))]) diff --git a/pysnmp/smi/compiler.py b/pysnmp/smi/compiler.py index 84dde53d..c76463b7 100644 --- a/pysnmp/smi/compiler.py +++ b/pysnmp/smi/compiler.py @@ -31,12 +31,15 @@ try: except ImportError: from pysnmp.smi import error + def addMibCompilerDecorator(errorMsg): def addMibCompiler(mibBuilder, **kwargs): if not kwargs.get('ifAvailable'): raise error.SmiError('MIB compiler not available: %s' % errorMsg) + return addMibCompiler + addMibCompiler = addMibCompilerDecorator(sys.exc_info()[1]) else: @@ -53,7 +56,9 @@ else: compiler.addSearchers(StubSearcher(*baseMibs)) compiler.addSearchers(*[PyPackageSearcher(x.fullPath()) for x in mibBuilder.getMibSources()]) - compiler.addBorrowers(*[PyFileBorrower(x, genTexts=mibBuilder.loadTexts) for x in getReadersFromUrls(*kwargs.get('borrowers') or defaultBorrowers, **dict(lowcaseMatching=False))]) + compiler.addBorrowers(*[PyFileBorrower(x, genTexts=mibBuilder.loadTexts) for x in + getReadersFromUrls(*kwargs.get('borrowers') or defaultBorrowers, + **dict(lowcaseMatching=False))]) mibBuilder.setMibCompiler( compiler, kwargs.get('destination') or defaultDest diff --git a/pysnmp/smi/error.py b/pysnmp/smi/error.py index a7c30aa8..34d74a95 100644 --- a/pysnmp/smi/error.py +++ b/pysnmp/smi/error.py @@ -7,15 +7,19 @@ from pyasn1.error import PyAsn1Error from pysnmp.error import PySnmpError + class SmiError(PySnmpError, PyAsn1Error): pass + class MibLoadError(SmiError): pass + class MibNotFoundError(MibLoadError): pass + class MibOperationError(SmiError): def __init__(self, **kwargs): self.__outArgs = kwargs @@ -38,65 +42,85 @@ class MibOperationError(SmiError): def update(self, d): self.__outArgs.update(d) + # Aligned with SNMPv2 PDU error-status class GenError(MibOperationError): pass + class NoAccessError(MibOperationError): pass + class WrongTypeError(MibOperationError): pass + class WrongLengthError(MibOperationError): pass + class WrongEncodingError(MibOperationError): pass + class WrongValueError(MibOperationError): pass + class NoCreationError(MibOperationError): pass + class InconsistentValueError(MibOperationError): pass + class ResourceUnavailableError(MibOperationError): pass + class CommitFailedError(MibOperationError): pass + class UndoFailedError(MibOperationError): pass + class AuthorizationError(MibOperationError): pass + class NotWritableError(MibOperationError): pass + class InconsistentNameError(MibOperationError): pass + # Aligned with SNMPv2 Var-Bind exceptions class NoSuchObjectError(MibOperationError): pass + class NoSuchInstanceError(MibOperationError): pass + class EndOfMibViewError(MibOperationError): pass + # Row management class TableRowManagement(MibOperationError): pass + class RowCreationWanted(TableRowManagement): pass + class RowDestructionWanted(TableRowManagement): pass diff --git a/pysnmp/smi/exval.py b/pysnmp/smi/exval.py index 8279682a..86dadb56 100644 --- a/pysnmp/smi/exval.py +++ b/pysnmp/smi/exval.py @@ -9,4 +9,3 @@ from pysnmp.proto import rfc1905 noSuchObject = rfc1905.noSuchObject noSuchInstance = rfc1905.noSuchInstance endOfMibView = endOfMib = rfc1905.endOfMibView - diff --git a/pysnmp/smi/indices.py b/pysnmp/smi/indices.py index 621a2af4..733bcebd 100644 --- a/pysnmp/smi/indices.py +++ b/pysnmp/smi/indices.py @@ -6,8 +6,10 @@ # from bisect import bisect + class OrderedDict(dict): """Ordered dictionary used for indices""" + def __init__(self, **kwargs): self.__keys = [] self.__dirty = True @@ -91,8 +93,10 @@ class OrderedDict(dict): self.__order() return self.__keysLens + class OidOrderedDict(OrderedDict): """OID-ordered dictionary used for indices""" + def __init__(self, **kwargs): self.__keysCache = {} OrderedDict.__init__(self, **kwargs) @@ -109,6 +113,7 @@ class OidOrderedDict(OrderedDict): if key in self.__keysCache: del self.__keysCache[key] OrderedDict.__delitem__(self, key) + __delattr__ = __delitem__ def sortingFun(self, keys): diff --git a/pysnmp/smi/instrum.py b/pysnmp/smi/instrum.py index b1a9d515..9df7b988 100644 --- a/pysnmp/smi/instrum.py +++ b/pysnmp/smi/instrum.py @@ -11,16 +11,18 @@ from pysnmp import debug __all__ = ['AbstractMibInstrumController', 'MibInstrumController'] + class AbstractMibInstrumController: - def readVars(self, vars, acInfo=(None, None)): + def readVars(self, varBinds, acInfo=(None, None)): raise error.NoSuchInstanceError(idx=0) - def readNextVars(self, vars, acInfo=(None, None)): + def readNextVars(self, varBinds, acInfo=(None, None)): raise error.EndOfMibViewError(idx=0) - def writeVars(self, vars, acInfo=(None, None)): + def writeVars(self, varBinds, acInfo=(None, None)): raise error.NoSuchObjectError(idx=0) + class MibInstrumController(AbstractMibInstrumController): fsmReadVar = { # ( state, status ) -> newState @@ -72,9 +74,9 @@ class MibInstrumController(AbstractMibInstrumController): (MibScalarInstance, MibScalar, MibTableColumn, MibTableRow, MibTable) = self.mibBuilder.importSymbols( - 'SNMPv2-SMI', 'MibScalarInstance', 'MibScalar', - 'MibTableColumn', 'MibTableRow', 'MibTable' - ) + 'SNMPv2-SMI', 'MibScalarInstance', 'MibScalar', + 'MibTableColumn', 'MibTableRow', 'MibTable' + ) mibTree, = self.mibBuilder.importSymbols('SNMPv2-SMI', 'iso') @@ -144,18 +146,18 @@ class MibInstrumController(AbstractMibInstrumController): else: raise error.SmiError( 'Orphan MIB scalar instance %r at %r' % (inst, self) - ) + ) lastBuildSyms[inst.name] = inst.typeName # Attach Table Columns to Table Rows for col in cols.values(): - rowName = col.name[:-1] # XXX + rowName = col.name[:-1] # XXX if rowName in rows: rows[rowName].registerSubtrees(col) else: raise error.SmiError( 'Orphan MIB table column %r at %r' % (col, self) - ) + ) lastBuildSyms[col.name] = rowName # Attach Table Rows to MIB tree @@ -181,14 +183,14 @@ class MibInstrumController(AbstractMibInstrumController): # MIB instrumentation - def flipFlopFsm(self, fsmTable, inputNameVals, acInfo): + def flipFlopFsm(self, fsmTable, inputVarBinds, acInfo): self.__indexMib() - debug.logger & debug.flagIns and debug.logger('flipFlopFsm: inputNameVals %r' % (inputNameVals,)) + debug.logger & debug.flagIns and debug.logger('flipFlopFsm: input var-binds %r' % (inputVarBinds,)) mibTree, = self.mibBuilder.importSymbols('SNMPv2-SMI', 'iso') - outputNameVals = [] + outputVarBinds = [] state, status = 'start', 'ok' origExc = None - while 1: + while True: k = (state, status) if k in fsmTable: fsmState = fsmTable[k] @@ -199,35 +201,39 @@ class MibInstrumController(AbstractMibInstrumController): else: raise error.SmiError( 'Unresolved FSM state %s, %s' % (state, status) - ) - debug.logger & debug.flagIns and debug.logger('flipFlopFsm: state %s status %s -> fsmState %s' % (state, status, fsmState)) + ) + debug.logger & debug.flagIns and debug.logger( + 'flipFlopFsm: state %s status %s -> fsmState %s' % (state, status, fsmState)) state = fsmState status = 'ok' if state == 'stop': break idx = 0 - for name, val in inputNameVals: + for name, val in inputVarBinds: f = getattr(mibTree, state, None) if f is None: raise error.SmiError( 'Unsupported state handler %s at %s' % (state, self) - ) + ) try: # Convert to tuple to avoid ObjectName instantiation # on subscription rval = f(tuple(name), val, idx, acInfo) except error.SmiError: exc_t, exc_v, exc_tb = sys.exc_info() - debug.logger & debug.flagIns and debug.logger('flipFlopFsm: fun %s exception %s for %s=%r with traceback: %s' % (f, exc_t, name, val, traceback.format_exception(exc_t, exc_v, exc_tb))) + debug.logger & debug.flagIns and debug.logger( + 'flipFlopFsm: fun %s exception %s for %s=%r with traceback: %s' % ( + f, exc_t, name, val, traceback.format_exception(exc_t, exc_v, exc_tb))) if origExc is None: # Take the first exception origExc, origTraceback = exc_v, exc_tb status = 'err' break else: - debug.logger & debug.flagIns and debug.logger('flipFlopFsm: fun %s suceeded for %s=%r' % (f, name, val)) + debug.logger & debug.flagIns and debug.logger( + 'flipFlopFsm: fun %s suceeded for %s=%r' % (f, name, val)) if rval is not None: - outputNameVals.append((rval[0], rval[1])) - idx = idx + 1 + outputVarBinds.append((rval[0], rval[1])) + idx += 1 if origExc: if sys.version_info[0] <= 2: raise origExc @@ -238,13 +244,13 @@ class MibInstrumController(AbstractMibInstrumController): # Break cycle between locals and traceback object # (seems to be irrelevant on Py3 but just in case) del origTraceback - return outputNameVals + return outputVarBinds - def readVars(self, vars, acInfo=(None, None)): - return self.flipFlopFsm(self.fsmReadVar, vars, acInfo) + def readVars(self, varBinds, acInfo=(None, None)): + return self.flipFlopFsm(self.fsmReadVar, varBinds, acInfo) - def readNextVars(self, vars, acInfo=(None, None)): - return self.flipFlopFsm(self.fsmReadNextVar, vars, acInfo) + def readNextVars(self, varBinds, acInfo=(None, None)): + return self.flipFlopFsm(self.fsmReadNextVar, varBinds, acInfo) - def writeVars(self, vars, acInfo=(None, None)): - return self.flipFlopFsm(self.fsmWriteVar, vars, acInfo) + def writeVars(self, varBinds, acInfo=(None, None)): + return self.flipFlopFsm(self.fsmWriteVar, varBinds, acInfo) diff --git a/pysnmp/smi/rfc1902.py b/pysnmp/smi/rfc1902.py index a56b5277..ce6de571 100644 --- a/pysnmp/smi/rfc1902.py +++ b/pysnmp/smi/rfc1902.py @@ -16,6 +16,7 @@ from pysnmp import debug __all__ = ['ObjectIdentity', 'ObjectType', 'NotificationType'] + class ObjectIdentity: """Create an object representing MIB variable ID. @@ -355,7 +356,8 @@ class ObjectIdentity: addMibCompiler(mibViewController.mibBuilder, ifAvailable=True, ifNotAdded=True) else: - debug.logger & debug.flagMIB and debug.logger('adding MIB compiler with source paths %s' % ', '.join(self.__asn1SourcesToAdd)) + debug.logger & debug.flagMIB and debug.logger( + 'adding MIB compiler with source paths %s' % ', '.join(self.__asn1SourcesToAdd)) addMibCompiler( mibViewController.mibBuilder, sources=self.__asn1SourcesToAdd, @@ -375,7 +377,8 @@ class ObjectIdentity: if self.__state & self.stClean: return self - MibScalar, MibTableColumn = mibViewController.mibBuilder.importSymbols('SNMPv2-SMI', 'MibScalar', 'MibTableColumn') + MibScalar, MibTableColumn = mibViewController.mibBuilder.importSymbols('SNMPv2-SMI', 'MibScalar', + 'MibTableColumn') self.__indices = () @@ -418,7 +421,8 @@ class ObjectIdentity: self.__oid ) - debug.logger & debug.flagMIB and debug.logger('resolved %r into prefix %r and suffix %r' % (self.__args, prefix, suffix)) + debug.logger & debug.flagMIB and debug.logger( + 'resolved %r into prefix %r and suffix %r' % (self.__args, prefix, suffix)) modName, symName, _ = mibViewController.getNodeLocation(prefix) @@ -435,7 +439,7 @@ class ObjectIdentity: debug.logger & debug.flagMIB and debug.logger('resolved prefix %r into MIB node %r' % (prefix, mibNode)) - if isinstance(mibNode, MibTableColumn): # table column + if isinstance(mibNode, MibTableColumn): # table column if suffix: rowModName, rowSymName, _ = mibViewController.getNodeLocation( mibNode.name[:-1] @@ -444,7 +448,7 @@ class ObjectIdentity: rowModName, rowSymName ) self.__indices = rowNode.getIndicesFromInstId(suffix) - elif isinstance(mibNode, MibScalar): # scalar + elif isinstance(mibNode, MibScalar): # scalar if suffix: self.__indices = (rfc1902.ObjectName(suffix),) else: @@ -486,9 +490,10 @@ class ObjectIdentity: ) self.__label = label - debug.logger & debug.flagMIB and debug.logger('resolved %r into prefix %r and suffix %r' % (self.__args, prefix, suffix)) + debug.logger & debug.flagMIB and debug.logger( + 'resolved %r into prefix %r and suffix %r' % (self.__args, prefix, suffix)) - if isinstance(mibNode, MibTableColumn): # table + if isinstance(mibNode, MibTableColumn): # table rowModName, rowSymName, _ = mibViewController.getNodeLocation( mibNode.name[:-1] ) @@ -501,8 +506,9 @@ class ObjectIdentity: self.__oid += instIds self.__indices = rowNode.getIndicesFromInstId(instIds) except PyAsn1Error: - raise SmiError('Instance index %r to OID convertion failure at object %r: %s' % (self.__args[2:], mibNode.getLabel(), sys.exc_info()[1])) - elif self.__args[2:]: # any other kind of MIB node with indices + raise SmiError('Instance index %r to OID convertion failure at object %r: %s' % ( + self.__args[2:], mibNode.getLabel(), sys.exc_info()[1])) + elif self.__args[2:]: # any other kind of MIB node with indices if self.__args[2:]: instId = rfc1902.ObjectName( '.'.join([str(x) for x in self.__args[2:]]) @@ -522,9 +528,8 @@ class ObjectIdentity: s = rfc1902.OctetString() return '%s::%s%s%s' % ( self.__modName, self.__symName, - self.__indices and '.' or '', - '.'.join([x.isSuperTypeOf(s) and '"%s"' % x.prettyPrint() - or x.prettyPrint() for x in self.__indices]) + self.__indices and '.' or '', + '.'.join([x.isSuperTypeOf(s) and '"%s"' % x.prettyPrint() or x.prettyPrint() for x in self.__indices]) ) else: raise SmiError('%s object not fully initialized' % self.__class__.__name__) @@ -628,6 +633,7 @@ class ObjectIdentity: else: raise SmiError('%s object not properly initialized for accessing %s' % (self.__class__.__name__, attr)) + # A two-element sequence of ObjectIdentity and SNMP data type object class ObjectType: """Create an object representing MIB variable. @@ -688,6 +694,7 @@ class ObjectType: """ stDirty, stClean = 1, 2 + def __init__(self, objectIdentity, objectSyntax=rfc1905.unSpecified): if not isinstance(objectIdentity, ObjectIdentity): raise SmiError('initializer should be ObjectIdentity instance, not %r' % (objectIdentity,)) @@ -837,7 +844,8 @@ class ObjectType: self.__args[0].resolveWithMib(mibViewController) - MibScalar, MibTableColumn = mibViewController.mibBuilder.importSymbols('SNMPv2-SMI', 'MibScalar', 'MibTableColumn') + MibScalar, MibTableColumn = mibViewController.mibBuilder.importSymbols('SNMPv2-SMI', 'MibScalar', + 'MibTableColumn') if not isinstance(self.__args[0].getMibNode(), (MibScalar, MibTableColumn)): @@ -856,7 +864,9 @@ class ObjectType: try: self.__args[1] = self.__args[0].getMibNode().getSyntax().clone(self.__args[1]) except PyAsn1Error: - raise SmiError('MIB object %r having type %r failed to cast value %r: %s' % (self.__args[0].prettyPrint(), self.__args[0].getMibNode().getSyntax().__class__.__name__, self.__args[1], sys.exc_info()[1])) + raise SmiError('MIB object %r having type %r failed to cast value %r: %s' % ( + self.__args[0].prettyPrint(), self.__args[0].getMibNode().getSyntax().__class__.__name__, self.__args[1], + sys.exc_info()[1])) if self.__args[1].isSuperTypeOf(rfc1902.ObjectIdentifier()): self.__args[1] = ObjectIdentity(self.__args[1]).resolveWithMib(mibViewController) @@ -874,6 +884,7 @@ class ObjectType: else: raise SmiError('%s object not fully initialized' % self.__class__.__name__) + class NotificationType: """Create an object representing SNMP Notification. @@ -935,11 +946,12 @@ class NotificationType: >>> from pysnmp.smi.rfc1902 import * >>> NotificationType(ObjectIdentity('1.3.6.1.6.3.1.1.5.3')) NotificationType(ObjectIdentity('1.3.6.1.6.3.1.1.5.3'), (), {}) - >>> NotificationType(ObjectIdentity('IP-MIB', 'linkDown'), ObjectName('3.5)) + >>> NotificationType(ObjectIdentity('IP-MIB', 'linkDown'), ObjectName('3.5')) NotificationType(ObjectIdentity('1.3.6.1.6.3.1.1.5.3'), ObjectName('3.5'), {}) """ stDirty, stClean = 1, 2 + def __init__(self, objectIdentity, instanceIndex=(), objects={}): if not isinstance(objectIdentity, ObjectIdentity): raise SmiError('initializer should be ObjectIdentity instance, not %r' % (objectIdentity,)) @@ -1142,13 +1154,17 @@ class NotificationType: if isinstance(mibNode, SmiNotificationType): for notificationObject in mibNode.getObjects(): - objectIdentity = ObjectIdentity(*notificationObject+self.__instanceIndex).resolveWithMib(mibViewController) + objectIdentity = ObjectIdentity(*notificationObject + self.__instanceIndex).resolveWithMib( + mibViewController) self.__varBinds.append( - ObjectType(objectIdentity, self.__objects.get(notificationObject, rfc1905.unSpecified)).resolveWithMib(mibViewController) + ObjectType(objectIdentity, + self.__objects.get(notificationObject, rfc1905.unSpecified)).resolveWithMib( + mibViewController) ) varBindsLocation[objectIdentity] = len(self.__varBinds) - 1 else: - debug.logger & debug.flagMIB and debug.logger('WARNING: MIB object %r is not NOTIFICATION-TYPE (MIB not loaded?)' % (self.__objectIdentity,)) + debug.logger & debug.flagMIB and debug.logger( + 'WARNING: MIB object %r is not NOTIFICATION-TYPE (MIB not loaded?)' % (self.__objectIdentity,)) for varBinds in self.__additionalVarBinds: if not isinstance(varBinds, ObjectType): diff --git a/pysnmp/smi/view.py b/pysnmp/smi/view.py index b396d1d6..849bc329 100644 --- a/pysnmp/smi/view.py +++ b/pysnmp/smi/view.py @@ -13,16 +13,19 @@ __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 self.lastBuildId = -1 + self.__mibSymbolsIdx = OrderedDict() # Indexing part @@ -41,7 +44,7 @@ class MibViewController: # # Module name -> module-scope indices - self.__mibSymbolsIdx = OrderedDict() + self.__mibSymbolsIdx.clear() # Oid <-> label indices @@ -76,13 +79,12 @@ class MibViewController: # Types & MIB vars indices for n, v in self.mibBuilder.mibSymbols[modName].items(): - if n == self.mibBuilder.moduleID: # do not index this - continue # special symbol + if n == self.mibBuilder.moduleID: # do not index this + continue # special symbol if isinstance(v, classTypes): if n in mibMod['typeToModIdx']: raise error.SmiError( - 'Duplicate SMI type %s::%s, has %s' % \ - (modName, n, mibMod['typeToModIdx'][n]) + 'Duplicate SMI type %s::%s, has %s' % (modName, n, mibMod['typeToModIdx'][n]) ) globMibMod['typeToModIdx'][n] = modName mibMod['typeToModIdx'][n] = modName @@ -91,16 +93,15 @@ class MibViewController: continue if n in mibMod['varToNameIdx']: raise error.SmiError( - 'Duplicate MIB variable %s::%s has %s' % \ - (modName, n, mibMod['varToNameIdx'][n]) + 'Duplicate MIB variable %s::%s has %s' % (modName, n, mibMod['varToNameIdx'][n]) ) globMibMod['varToNameIdx'][n] = v.name mibMod['varToNameIdx'][n] = v.name # Potentionally ambiguous mapping ahead globMibMod['oidToModIdx'][v.name] = modName mibMod['oidToModIdx'][v.name] = modName - globMibMod['oidToLabelIdx'][v.name] = (n, ) - mibMod['oidToLabelIdx'][v.name] = (n, ) + globMibMod['oidToLabelIdx'][v.name] = (n,) + mibMod['oidToLabelIdx'][v.name] = (n,) else: raise error.SmiError( 'Unexpected object %s::%s' % (modName, n) @@ -124,12 +125,12 @@ class MibViewController: elif keydiff < 0: baseLabel = () keyLen = len(key) - i = keyLen-1 + i = keyLen - 1 while i: k = key[:i] if k in oidToLabelIdx: baseLabel = oidToLabelIdx[k] - if i != keyLen-1: + if i != keyLen - 1: baseLabel += key[i:-1] break i -= 1 @@ -207,9 +208,10 @@ class MibViewController: if oid == label: raise error.NoSuchObjectError( str='Can\'t resolve node name %s::%s at %s' % - (modName, nodeName, self) + (modName, nodeName, self) ) - debug.logger & debug.flagMIB and debug.logger('getNodeNameByOid: resolved %s:%s -> %s.%s' % (modName, nodeName, label, suffix)) + debug.logger & debug.flagMIB and debug.logger( + 'getNodeNameByOid: resolved %s:%s -> %s.%s' % (modName, nodeName, label, suffix)) return oid, label, suffix def getNodeNameByDesc(self, nodeName, modName=''): @@ -224,7 +226,8 @@ class MibViewController: raise error.NoSuchObjectError( str='No such symbol %s::%s at %s' % (modName, nodeName, self) ) - debug.logger & debug.flagMIB and debug.logger('getNodeNameByDesc: resolved %s:%s -> %s' % (modName, nodeName, oid)) + debug.logger & debug.flagMIB and debug.logger( + 'getNodeNameByDesc: resolved %s:%s -> %s' % (modName, nodeName, oid)) return self.getNodeNameByOid(oid, modName) def getNodeName(self, nodeName, modName=''): @@ -268,7 +271,7 @@ class MibViewController: try: return self.getNodeName( self.__mibSymbolsIdx[modName]['oidToLabelIdx'].nextKey(oid) + suffix, modName - ) + ) except KeyError: raise error.NoSuchObjectError( str='No name next to %s::%s at %s' % (modName, nodeName, self) @@ -279,7 +282,7 @@ class MibViewController: if len(oid) < 2: raise error.NoSuchObjectError( str='No parent name for %s::%s at %s' % - (modName, nodeName, self) + (modName, nodeName, self) ) return oid[:-1], label[:-1], oid[-1:] + suffix -- cgit v1.2.1