summaryrefslogtreecommitdiff
path: root/pysnmp/smi
diff options
context:
space:
mode:
authorelie <elie>2015-10-17 20:22:30 +0000
committerelie <elie>2015-10-17 20:22:30 +0000
commita46f37c26520015e3ad8628587db3899f55d8c33 (patch)
tree6798d1e7f1a5bac03b595d4e6b27b8735bb9c1eb /pysnmp/smi
parent9e73d5b89c6121437b92f02482b4423ab526b51a (diff)
downloadpysnmp-git-a46f37c26520015e3ad8628587db3899f55d8c33.tar.gz
linted for bad-whitespace and some other issues
Diffstat (limited to 'pysnmp/smi')
-rw-r--r--pysnmp/smi/builder.py53
-rw-r--r--pysnmp/smi/compiler.py24
-rw-r--r--pysnmp/smi/indices.py4
-rw-r--r--pysnmp/smi/instrum.py2
-rw-r--r--pysnmp/smi/mibs/SNMPv2-SMI.py16
-rw-r--r--pysnmp/smi/mibs/SNMPv2-TM.py12
-rw-r--r--pysnmp/smi/rfc1902.py26
-rw-r--r--pysnmp/smi/view.py2
8 files changed, 63 insertions, 76 deletions
diff --git a/pysnmp/smi/builder.py b/pysnmp/smi/builder.py
index aa2f626c..7792d74d 100644
--- a/pysnmp/smi/builder.py
+++ b/pysnmp/smi/builder.py
@@ -135,15 +135,15 @@ class ZipMibSource(__AbstractMibSource):
return DirMibSource(self._srcName).init()
def _parseDosTime(self, dosdate, dostime):
- t = ( ((dosdate >> 9) & 0x7f) + 1980, # year
- ((dosdate >> 5) & 0x0f), # month
- dosdate & 0x1f, # mday
- (dostime >> 11) & 0x1f, # hour
- (dostime >> 5) & 0x3f, # min
- (dostime & 0x1f) * 2, # sec
- -1, # wday
- -1, # yday
- -1 ) # dst
+ t = (((dosdate >> 9) & 0x7f) + 1980, # year
+ ((dosdate >> 5) & 0x0f), # month
+ dosdate & 0x1f, # mday
+ (dostime >> 11) & 0x1f, # hour
+ (dostime >> 5) & 0x3f, # min
+ (dostime & 0x1f) * 2, # sec
+ -1, # wday
+ -1, # yday
+ -1) # dst
return time.mktime(t)
def _listdir(self):
@@ -158,9 +158,8 @@ class ZipMibSource(__AbstractMibSource):
p = os.path.join(self._srcName, f)
if p in self.__loader._files:
return self._parseDosTime(
- self.__loader._files[p][6],
- self.__loader._files[p][5]
- )
+ self.__loader._files[p][6], self.__loader._files[p][5]
+ )
else:
raise IOError(ENOENT, 'No such file in ZIP archive', p)
@@ -243,12 +242,12 @@ class MibBuilder:
# MIB modules management
def addMibSources(self, *mibSources):
- self.__mibSources.extend([ s.init() for s in mibSources ])
+ self.__mibSources.extend([s.init() for s in mibSources])
debug.logger & debug.flagBld and debug.logger('addMibSources: new MIB sources %s' % (self.__mibSources,))
def setMibSources(self, *mibSources):
- self.__mibSources = [ s.init() for s in mibSources ]
+ self.__mibSources = [s.init() for s in mibSources]
debug.logger & debug.flagBld and debug.logger('setMibSources: new MIB sources %s' % (self.__mibSources,))
def getMibSources(self):
@@ -256,17 +255,17 @@ class MibBuilder:
# Legacy/compatibility methods (won't work for .eggs)
def setMibPath(self, *mibPaths):
- self.setMibSources(*[ DirMibSource(x) for x in mibPaths ])
+ self.setMibSources(*[DirMibSource(x) for x in mibPaths])
def getMibPath(self):
paths = ()
for mibSource in self.getMibSources():
if isinstance(mibSource, DirMibSource):
- paths += ( mibSource.fullPath(), )
+ paths += (mibSource.fullPath(),)
else:
raise error.MibLoadError(
'MIB source is not a plain directory: %s' % (mibSource,)
- )
+ )
return paths
def loadModule(self, modName, **userCtx):
@@ -288,16 +287,16 @@ class MibBuilder:
debug.logger & debug.flagBld and debug.logger('loadModule: evaluating %s' % modPath)
- g = { 'mibBuilder': self,
- 'userCtx': userCtx }
+ g = {'mibBuilder': self, 'userCtx': userCtx}
try:
exec(modData, g)
+
except Exception:
del self.__modPathsSeen[modPath]
raise error.MibLoadError(
'MIB module \"%s\" load error: %s' % (modPath, traceback.format_exception(*sys.exc_info()))
- )
+ )
self.__modSeen[modName] = modPath
@@ -347,7 +346,7 @@ class MibBuilder:
if modName not in self.mibSymbols:
raise error.MibNotFoundError(
'No module %s at %s' % (modName, self)
- )
+ )
self.unexportSymbols(modName)
del self.__modPathsSeen[self.__modSeen[modName]]
del self.__modSeen[modName]
@@ -368,11 +367,11 @@ class MibBuilder:
if modName not in self.mibSymbols:
raise error.MibNotFoundError(
'No module %s loaded at %s' % (modName, self)
- )
+ )
if symName not in self.mibSymbols[modName]:
raise error.SmiError(
'No symbol %s::%s at %s' % (modName, symName, self)
- )
+ )
r = r + (self.mibSymbols[modName][symName],)
return r
@@ -389,7 +388,7 @@ class MibBuilder:
if symName in mibSymbols:
raise error.SmiError(
'Symbol %s already exported at %s' % (symName, modName)
- )
+ )
if symName != self.moduleID and \
not isinstance(symObj, classTypes):
@@ -407,9 +406,7 @@ class MibBuilder:
def unexportSymbols(self, modName, *symNames):
if modName not in self.mibSymbols:
- raise error.SmiError(
- 'No module %s at %s' % (modName, self)
- )
+ raise error.SmiError('No module %s at %s' % (modName, self))
mibSymbols = self.mibSymbols[modName]
if not symNames:
symNames = list(mibSymbols.keys())
@@ -417,7 +414,7 @@ class MibBuilder:
if symName not in mibSymbols:
raise error.SmiError(
'No symbol %s::%s at %s' % (modName, symName, self)
- )
+ )
del mibSymbols[symName]
debug.logger & debug.flagBld and debug.logger('unexportSymbols: symbol %s::%s' % (modName, symName))
diff --git a/pysnmp/smi/compiler.py b/pysnmp/smi/compiler.py
index 0f62c0dc..3bd59019 100644
--- a/pysnmp/smi/compiler.py
+++ b/pysnmp/smi/compiler.py
@@ -5,8 +5,7 @@
import os
import sys
-defaultSources = [ 'file:///usr/share/snmp/mibs',
- 'file:///usr/share/mibs' ]
+defaultSources = ['file:///usr/share/snmp/mibs', 'file:///usr/share/mibs']
if sys.platform[:3] == 'win':
defaultDest = os.path.join(os.path.expanduser("~"),
@@ -40,25 +39,16 @@ else:
if kwargs.get('ifNotAdded') and mibBuilder.getMibCompiler():
return
- compiler = MibCompiler(
- parserFactory(**smiV1Relaxed)(),
- PySnmpCodeGen(),
- PyFileWriter(kwargs.get('destination') or defaultDest)
- )
+ compiler = MibCompiler(parserFactory(**smiV1Relaxed)(),
+ PySnmpCodeGen(),
+ PyFileWriter(kwargs.get('destination') or defaultDest))
compiler.addSources(*getReadersFromUrls(*kwargs.get('sources') or defaultSources))
- compiler.addSearchers(
- StubSearcher(*baseMibs) # XXX
- )
- 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.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))])
mibBuilder.setMibCompiler(
compiler, kwargs.get('destination') or defaultDest
)
-
diff --git a/pysnmp/smi/indices.py b/pysnmp/smi/indices.py
index 504a0143..a7fddc13 100644
--- a/pysnmp/smi/indices.py
+++ b/pysnmp/smi/indices.py
@@ -54,7 +54,7 @@ class OrderedDict(dict):
return [(k, self[k]) for k in self.__keys]
def update(self, d):
- [self.__setitem__(k, v) for k,v in d.items()]
+ [self.__setitem__(k, v) for k, v in d.items()]
def sortingFun(self, keys):
keys.sort()
@@ -95,7 +95,7 @@ class OidOrderedDict(OrderedDict):
if isinstance(key, tuple):
self.__keysCache[key] = key
else:
- self.__keysCache[key] = [ int(x) for x in key.split('.') if x ]
+ self.__keysCache[key] = [int(x) for x in key.split('.') if x]
OrderedDict.__setitem__(self, key, value)
def __delitem__(self, key):
diff --git a/pysnmp/smi/instrum.py b/pysnmp/smi/instrum.py
index 080592b1..fe7334eb 100644
--- a/pysnmp/smi/instrum.py
+++ b/pysnmp/smi/instrum.py
@@ -4,7 +4,7 @@ import traceback
from pysnmp.smi import error
from pysnmp import debug
-__all__ = [ 'AbstractMibInstrumController', 'MibInstrumController' ]
+__all__ = ['AbstractMibInstrumController', 'MibInstrumController']
class AbstractMibInstrumController:
def readVars(self, vars, acInfo=(None, None)):
diff --git a/pysnmp/smi/mibs/SNMPv2-SMI.py b/pysnmp/smi/mibs/SNMPv2-SMI.py
index 86380ac3..8bae08cf 100644
--- a/pysnmp/smi/mibs/SNMPv2-SMI.py
+++ b/pysnmp/smi/mibs/SNMPv2-SMI.py
@@ -33,7 +33,7 @@ Opaque = rfc1902.Opaque
Counter64 = rfc1902.Counter64
class ExtUTCTime(OctetString):
- subtypeSpec = OctetString.subtypeSpec+ConstraintsUnion(ValueSizeConstraint(11,11), ValueSizeConstraint(13,13))
+ subtypeSpec = OctetString.subtypeSpec+ConstraintsUnion(ValueSizeConstraint(11, 11), ValueSizeConstraint(13, 13))
# MIB tree foundation class
@@ -113,7 +113,7 @@ MODULE-IDENTITY\n\
self.getOrganization(),
self.getContactInfo(),
self.getDescription(),
- ''.join([ "REVISION \"%s\"\n" % x for x in self.getRevisions() ]))
+ ''.join(["REVISION \"%s\"\n" % x for x in self.getRevisions()]))
class ObjectIdentity(MibNode):
def getStatus(self):
@@ -185,10 +185,10 @@ NOTIFICATION-TYPE\n\
STATUS %s\n\
DESCRIPTION \"%s\"\n\
%s\
-' % (', '.join([ x for x in self.getObjects() ]),
+' % (', '.join([x for x in self.getObjects()]),
self.getStatus(),
self.getDescription(),
- ''.join([ "REVISION \"%s\"\n" % x for x in self.getRevisions() ]))
+ ''.join(["REVISION \"%s\"\n" % x for x in self.getRevisions()]))
class MibIdentifier(MibNode):
def asn1Print(self):
@@ -371,7 +371,7 @@ class MibTree(ObjectType):
if name == self.name:
if acFun:
if self.maxAccess not in ('readonly',
- 'readwrite','readcreate') or \
+ 'readwrite', 'readcreate') or \
acFun(name, self.syntax, idx, 'read', acCtx):
raise error.NoAccessError(idx=idx, name=name)
else:
@@ -1108,7 +1108,7 @@ class MibTableRow(MibTree):
self.branchVersionId += 1
self.__delegate('Cleanup', name, val, idx, acInfo)
- def writeUndo(self, name, val, idx, acInfo):
+ def writeUndo(self, name, val, idx, acInfo):
self.__delegate('Undo', name, val, idx, acInfo)
# Table row management
@@ -1178,7 +1178,7 @@ class MibTable(MibTree):
def __init__(self, name):
MibTree.__init__(self, name)
-zeroDotZero = ObjectIdentity((0,0))
+zeroDotZero = ObjectIdentity((0, 0))
#dot = MibTree()
iso = MibTree((1,))
@@ -1202,7 +1202,7 @@ snmpModules = MibIdentifier(snmpV2.name +(3,))
mibBuilder.exportSymbols(
'SNMPv2-SMI', MibNode=MibNode,
Integer32=Integer32, Bits=Bits, IpAddress=IpAddress,
- Counter32=Counter32, Gauge32=Gauge32, Unsigned32=Unsigned32,
+ Counter32=Counter32, Gauge32=Gauge32, Unsigned32=Unsigned32,
TimeTicks=TimeTicks, Opaque=Opaque, Counter64=Counter64,
ExtUTCTime=ExtUTCTime,
ModuleIdentity=ModuleIdentity, ObjectIdentity=ObjectIdentity,
diff --git a/pysnmp/smi/mibs/SNMPv2-TM.py b/pysnmp/smi/mibs/SNMPv2-TM.py
index 0c6c7499..81397d4d 100644
--- a/pysnmp/smi/mibs/SNMPv2-TM.py
+++ b/pysnmp/smi/mibs/SNMPv2-TM.py
@@ -5,15 +5,15 @@ try:
from socket import inet_ntop, inet_pton, AF_INET
except ImportError:
from socket import inet_ntoa, inet_aton, AF_INET
- inet_ntop = lambda x,y: inet_ntoa(y)
- inet_pton = lambda x,y: inet_aton(y)
+ inet_ntop = lambda x, y: inet_ntoa(y)
+ inet_pton = lambda x, y: inet_aton(y)
from pyasn1.compat.octets import int2oct, oct2int
-( OctetString, ) = mibBuilder.importSymbols('ASN1', 'OctetString')
-( ConstraintsIntersection, ConstraintsUnion, SingleValueConstraint, ValueRangeConstraint, ValueSizeConstraint, ) = mibBuilder.importSymbols("ASN1-REFINEMENT", "ConstraintsIntersection", "ConstraintsUnion", "SingleValueConstraint", "ValueRangeConstraint", "ValueSizeConstraint")
-( ModuleIdentity, MibIdentifier, ObjectIdentity, snmpModules, snmpDomains, snmpProxys ) = mibBuilder.importSymbols('SNMPv2-SMI', 'ModuleIdentity', 'MibIdentifier', 'ObjectIdentity', 'snmpModules', 'snmpDomains', 'snmpProxys')
-( TextualConvention, ) = mibBuilder.importSymbols('SNMPv2-TC', 'TextualConvention')
+(OctetString,) = mibBuilder.importSymbols('ASN1', 'OctetString')
+(ConstraintsIntersection, ConstraintsUnion, SingleValueConstraint, ValueRangeConstraint, ValueSizeConstraint) = mibBuilder.importSymbols("ASN1-REFINEMENT", "ConstraintsIntersection", "ConstraintsUnion", "SingleValueConstraint", "ValueRangeConstraint", "ValueSizeConstraint")
+(ModuleIdentity, MibIdentifier, ObjectIdentity, snmpModules, snmpDomains, snmpProxys) = mibBuilder.importSymbols('SNMPv2-SMI', 'ModuleIdentity', 'MibIdentifier', 'ObjectIdentity', 'snmpModules', 'snmpDomains', 'snmpProxys')
+(TextualConvention,) = mibBuilder.importSymbols('SNMPv2-TC', 'TextualConvention')
snmpv2tm = ModuleIdentity(snmpModules.name + (19,)).setRevisions(("2002-10-16 00:00",))
diff --git a/pysnmp/smi/rfc1902.py b/pysnmp/smi/rfc1902.py
index 7052d4ce..cf8e5a50 100644
--- a/pysnmp/smi/rfc1902.py
+++ b/pysnmp/smi/rfc1902.py
@@ -79,7 +79,7 @@ class ObjectIdentity:
self.__kwargs = kwargs
self.__mibSourcesToAdd = self.__modNamesToLoad = None
self.__asn1SourcesToAdd = self.__asn1SourcesOptions = None
- self.__state = self.stDirty
+ self.__state = self.stDirty
def getMibSymbol(self):
"""Returns MIB variable symbolic identification.
@@ -290,7 +290,7 @@ class ObjectIdentity:
if self.__mibSourcesToAdd is not None:
debug.logger & debug.flagMIB and debug.logger('adding MIB sources %s' % ', '.join(self.__mibSourcesToAdd))
mibViewController.mibBuilder.addMibSources(
- *[ ZipMibSource(x) for x in self.__mibSourcesToAdd ]
+ *[ZipMibSource(x) for x in self.__mibSourcesToAdd]
)
self.__mibSourcesToAdd = None
@@ -352,7 +352,7 @@ class ObjectIdentity:
if suffix:
try:
- suffix = tuple([ int(x) for x in suffix ])
+ suffix = tuple([int(x) for x in suffix])
except ValueError:
raise SmiError('Unknown object name component %r' % (suffix,))
self.__oid = rfc1902.ObjectName(prefix + suffix)
@@ -389,10 +389,10 @@ class ObjectIdentity:
self.__indices = rowNode.getIndicesFromInstId(suffix)
elif isinstance(mibNode, MibScalar): # scalar
if suffix:
- self.__indices = ( rfc1902.ObjectName(suffix), )
+ self.__indices = (rfc1902.ObjectName(suffix),)
else:
if suffix:
- self.__indices = ( rfc1902.ObjectName(suffix), )
+ self.__indices = (rfc1902.ObjectName(suffix),)
self.__state |= self.stClean
debug.logger & debug.flagMIB and debug.logger('resolved indices are %r' % (self.__indices,))
@@ -448,10 +448,10 @@ class ObjectIdentity:
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:] ])
+ '.'.join([str(x) for x in self.__args[2:]])
)
self.__oid += instId
- self.__indices = ( instId, )
+ self.__indices = (instId,)
self.__state |= self.stClean
debug.logger & debug.flagMIB and debug.logger('resolved indices are %r' % (self.__indices,))
@@ -467,13 +467,13 @@ class ObjectIdentity:
self.__modName, self.__symName,
self.__indices and '.' or '',
'.'.join([x.isSuperTypeOf(s) and '"%s"' % x.prettyPrint()
- or x.prettyPrint() for x in self.__indices ])
+ or x.prettyPrint() for x in self.__indices])
)
else:
raise SmiError('%s object not fully initialized' % self.__class__.__name__)
def __repr__(self):
- return '%s(%s)' % (self.__class__.__name__, ', '.join([ repr(x) for x in self.__args]))
+ return '%s(%s)' % (self.__class__.__name__, ', '.join([repr(x) for x in self.__args]))
# Redirect some attrs access to the OID object to behave alike
@@ -634,7 +634,7 @@ class ObjectType:
def __init__(self, objectIdentity, objectSyntax=rfc1905.unSpecified):
if not isinstance(objectIdentity, ObjectIdentity):
raise SmiError('initializer should be ObjectIdentity instance, not %r' % (objectIdentity,))
- self.__args = [ objectIdentity, objectSyntax ]
+ self.__args = [objectIdentity, objectSyntax]
self.__state = self.stDirty
def __getitem__(self, i):
@@ -647,7 +647,7 @@ class ObjectType:
return self.prettyPrint()
def __repr__(self):
- return '%s(%s)' % (self.__class__.__name__, ', '.join([ repr(x) for x in self.__args]))
+ return '%s(%s)' % (self.__class__.__name__, ', '.join([repr(x) for x in self.__args]))
def isFullyResolved(self):
return self.__state & self.stClean
@@ -814,7 +814,7 @@ class NotificationType:
self.__objects = objects
self.__varBinds = []
self.__additionalVarBinds = []
- self.__state = self.stDirty
+ self.__state = self.stDirty
def __getitem__(self, i):
if self.__state & self.stClean:
@@ -948,6 +948,6 @@ class NotificationType:
def prettyPrint(self):
if self.__state & self.stClean:
- return ' '.join([ '%s = %s' % (x[0].prettyPrint(), x[1].prettyPrint()) for x in self.__varBinds])
+ return ' '.join(['%s = %s' % (x[0].prettyPrint(), x[1].prettyPrint()) for x in self.__varBinds])
else:
raise SmiError('%s object not fully initialized' % self.__class__.__name__)
diff --git a/pysnmp/smi/view.py b/pysnmp/smi/view.py
index df28c2cb..eeb7f8e2 100644
--- a/pysnmp/smi/view.py
+++ b/pysnmp/smi/view.py
@@ -180,7 +180,7 @@ class MibViewController:
nodeName[:-1], oidToLabelIdx, labelToOidIdx
)
suffix = suffix + nodeName[-1:]
- resLabel = label + tuple([ str(x) for x in suffix ])
+ resLabel = label + tuple([str(x) for x in suffix])
if resLabel in labelToOidIdx:
return labelToOidIdx[resLabel], resLabel, ()
resOid = oid + suffix