summaryrefslogtreecommitdiff
path: root/pysnmp/proto/api
diff options
context:
space:
mode:
authorelie <elie>2015-10-17 15:34:21 +0000
committerelie <elie>2015-10-17 15:34:21 +0000
commit7ebcb3d0c1ce6b7722bf7b06b4826d27c2fa487b (patch)
tree8cdd9f0b8d08d4af24ff7ade9ead79285c037105 /pysnmp/proto/api
parent71dd5565a4b2948237a87319b57c565e18605761 (diff)
downloadpysnmp-git-7ebcb3d0c1ce6b7722bf7b06b4826d27c2fa487b.tar.gz
multiple-statements-in-one-line linted out
Diffstat (limited to 'pysnmp/proto/api')
-rw-r--r--pysnmp/proto/api/v1.py86
-rw-r--r--pysnmp/proto/api/v2c.py29
2 files changed, 76 insertions, 39 deletions
diff --git a/pysnmp/proto/api/v1.py b/pysnmp/proto/api/v1.py
index 7043478d..a7618784 100644
--- a/pysnmp/proto/api/v1.py
+++ b/pysnmp/proto/api/v1.py
@@ -29,7 +29,8 @@ class VarBindAPI:
def setOIDVal(self, varBind, oidVal):
(oid, val) = oidVal
varBind.setComponentByPosition(0, oid)
- if val is None: val = null
+ if val is None:
+ val = null
varBind.setComponentByPosition(1).getComponentByPosition(1).setComponentByType(val.getTagSet(), val, 1, verifyConstraints=False)
return varBind
@@ -46,20 +47,26 @@ class PDUAPI:
def setDefaults(self, pdu):
pdu.setComponentByPosition(
0, getNextRequestID(), verifyConstraints=False
- )
+ )
pdu.setComponentByPosition(
1, self._errorStatus, verifyConstraints=False
- )
+ )
pdu.setComponentByPosition(
2, self._errorIndex, verifyConstraints=False
- )
+ )
pdu.setComponentByPosition(3)
- def getRequestID(self, pdu): return pdu.getComponentByPosition(0)
- def setRequestID(self, pdu, value): pdu.setComponentByPosition(0, value)
+ def getRequestID(self, pdu):
+ return pdu.getComponentByPosition(0)
+
+ def setRequestID(self, pdu, value):
+ pdu.setComponentByPosition(0, value)
- def getErrorStatus(self, pdu): return pdu.getComponentByPosition(1)
- def setErrorStatus(self, pdu, value): pdu.setComponentByPosition(1, value)
+ def getErrorStatus(self, pdu):
+ return pdu.getComponentByPosition(1)
+
+ def setErrorStatus(self, pdu, value):
+ pdu.setComponentByPosition(1, value)
def getErrorIndex(self, pdu, muteErrors=False):
errorIndex = pdu.getComponentByPosition(2)
@@ -68,8 +75,9 @@ class PDUAPI:
return errorIndex.clone(len(pdu[3]))
raise error.ProtocolError(
'Error index out of range: %s > %s' % (errorIndex, len(pdu[3]))
- )
+ )
return errorIndex
+
def setErrorIndex(self, pdu, value):
pdu.setComponentByPosition(2, value)
@@ -85,11 +93,13 @@ class PDUAPI:
def setVarBindList(self, pdu, varBindList):
varBindList = pdu.setComponentByPosition(3, varBindList)
+
def getVarBinds(self, pdu):
varBinds = []
for varBind in pdu.getComponentByPosition(3):
varBinds.append(apiVarBind.getOIDVal(varBind))
return varBinds
+
def setVarBinds(self, pdu, varBinds):
varBindList = pdu.setComponentByPosition(3).getComponentByPosition(3)
varBindList.clear()
@@ -101,8 +111,8 @@ class PDUAPI:
varBindList.setComponentByPosition(idx)
apiVarBind.setOIDVal(
varBindList.getComponentByPosition(idx), varBind
- )
- idx = idx + 1
+ )
+ idx += 1
def getResponse(self, reqPDU):
rspPDU = GetResponsePDU()
@@ -115,9 +125,9 @@ class PDUAPI:
varBindRow = []
for varBind in apiPDU.getVarBinds(reqPDU):
varBindRow.append((varBind[0], null))
- return [ varBindRow ]
+ return [varBindRow]
else:
- return [ apiPDU.getVarBinds(rspPDU) ]
+ return [apiPDU.getVarBinds(rspPDU)]
apiPDU = PDUAPI()
@@ -142,25 +152,39 @@ class TrapPDUAPI:
pdu.setComponentByPosition(4, self._zeroTime, verifyConstraints=False)
pdu.setComponentByPosition(5)
- def getEnterprise(self, pdu): return pdu.getComponentByPosition(0)
- def setEnterprise(self, pdu, value): pdu.setComponentByPosition(0, value)
+ def getEnterprise(self, pdu):
+ return pdu.getComponentByPosition(0)
+
+ def setEnterprise(self, pdu, value):
+ pdu.setComponentByPosition(0, value)
def getAgentAddr(self, pdu):
return pdu.getComponentByPosition(1).getComponentByPosition(0)
+
def setAgentAddr(self, pdu, value):
pdu.setComponentByPosition(1).getComponentByPosition(1).setComponentByPosition(0, value)
- def getGenericTrap(self, pdu): return pdu.getComponentByPosition(2)
- def setGenericTrap(self, pdu, value): pdu.setComponentByPosition(2, value)
+ def getGenericTrap(self, pdu):
+ return pdu.getComponentByPosition(2)
+
+ def setGenericTrap(self, pdu, value):
+ pdu.setComponentByPosition(2, value)
+
+ def getSpecificTrap(self, pdu):
+ return pdu.getComponentByPosition(3)
+
+ def setSpecificTrap(self, pdu, value):
+ pdu.setComponentByPosition(3, value)
- def getSpecificTrap(self, pdu): return pdu.getComponentByPosition(3)
- def setSpecificTrap(self, pdu, value): pdu.setComponentByPosition(3, value)
+ def getTimeStamp(self, pdu):
+ return pdu.getComponentByPosition(4)
- def getTimeStamp(self, pdu): return pdu.getComponentByPosition(4)
- def setTimeStamp(self, pdu, value): pdu.setComponentByPosition(4, value)
+ def setTimeStamp(self, pdu, value):
+ pdu.setComponentByPosition(4, value)
def getVarBindList(self, pdu):
return pdu.getComponentByPosition(5)
+
def setVarBindList(self, pdu, varBindList):
varBindList = pdu.setComponentByPosition(5, varBindList)
@@ -169,6 +193,7 @@ class TrapPDUAPI:
for varBind in pdu.getComponentByPosition(5):
varBinds.append(apiVarBind.getOIDVal(varBind))
return varBinds
+
def setVarBinds(self, pdu, varBinds):
varBindList = pdu.setComponentByPosition(5).getComponentByPosition(5)
varBindList.clear()
@@ -193,13 +218,21 @@ class MessageAPI:
msg.setComponentByPosition(1, self._community, verifyConstraints=False)
return msg
- def getVersion(self, msg): return msg.getComponentByPosition(0)
- def setVersion(self, msg, value): msg.setComponentByPosition(0, value)
+ def getVersion(self, msg):
+ return msg.getComponentByPosition(0)
+
+ def setVersion(self, msg, value):
+ msg.setComponentByPosition(0, value)
- def getCommunity(self, msg): return msg.getComponentByPosition(1)
- def setCommunity(self, msg, value): msg.setComponentByPosition(1, value)
+ def getCommunity(self, msg):
+ return msg.getComponentByPosition(1)
+
+ def setCommunity(self, msg, value):
+ msg.setComponentByPosition(1, value)
+
+ def getPDU(self, msg):
+ return msg.getComponentByPosition(2).getComponent()
- def getPDU(self, msg): return msg.getComponentByPosition(2).getComponent()
def setPDU(self, msg, value):
msg.setComponentByPosition(2).getComponentByPosition(2).setComponentByType(value.getTagSet(), value, 1, verifyConstraints=False)
@@ -212,4 +245,3 @@ class MessageAPI:
return rspMsg
apiMessage = MessageAPI()
-
diff --git a/pysnmp/proto/api/v2c.py b/pysnmp/proto/api/v2c.py
index 18b477a3..5dbb1beb 100644
--- a/pysnmp/proto/api/v2c.py
+++ b/pysnmp/proto/api/v2c.py
@@ -43,6 +43,7 @@ apiVarBind = v1.apiVarBind
class PDUAPI(v1.PDUAPI):
_errorStatus = rfc1905._errorStatus.clone(0)
_errorIndex = univ.Integer(0).subtype(subtypeSpec=constraint.ValueRangeConstraint(0, rfc1905.max_bindings))
+
def getResponse(self, reqPDU):
rspPDU = ResponsePDU()
self.setDefaults(rspPDU)
@@ -50,19 +51,19 @@ class PDUAPI(v1.PDUAPI):
return rspPDU
def getVarBindTable(self, reqPDU, rspPDU):
- return [ apiPDU.getVarBinds(rspPDU) ]
+ return [apiPDU.getVarBinds(rspPDU)]
def setEndOfMibError(self, pdu, errorIndex):
varBindList = self.getVarBindList(pdu)
varBindList[errorIndex-1].setComponentByPosition(
1, rfc1905.endOfMibView, verifyConstraints=False
- )
+ )
def setNoSuchInstanceError(self, pdu, errorIndex):
varBindList = self.getVarBindList(pdu)
varBindList[errorIndex-1].setComponentByPosition(
1, rfc1905.noSuchInstance, verifyConstraints=False
- )
+ )
apiPDU = PDUAPI()
@@ -82,11 +83,17 @@ class BulkPDUAPI(PDUAPI):
)
pdu.setComponentByPosition(3)
- def getNonRepeaters(self, pdu): return pdu.getComponentByPosition(1)
- def setNonRepeaters(self, pdu, value): pdu.setComponentByPosition(1, value)
+ def getNonRepeaters(self, pdu):
+ return pdu.getComponentByPosition(1)
+
+ def setNonRepeaters(self, pdu, value):
+ pdu.setComponentByPosition(1, value)
+
+ def getMaxRepetitions(self, pdu):
+ return pdu.getComponentByPosition(2)
- def getMaxRepetitions(self, pdu): return pdu.getComponentByPosition(2)
- def setMaxRepetitions(self,pdu,value): pdu.setComponentByPosition(2,value)
+ def setMaxRepetitions(self,pdu,value):
+ pdu.setComponentByPosition(2,value)
def getVarBindTable(self, reqPDU, rspPDU):
nonRepeaters = self.getNonRepeaters(reqPDU)
@@ -125,11 +132,9 @@ class TrapPDUAPI(v1.PDUAPI):
_genTrap = ObjectIdentifier((1,3,6,1,6,3,1,1,5,1))
def setDefaults(self, pdu):
v1.PDUAPI.setDefaults(self, pdu)
- varBinds = [
- ( self.sysUpTime, self._zeroTime),
- # generic trap
- ( self.snmpTrapOID, self._genTrap)
- ]
+ varBinds = [(self.sysUpTime, self._zeroTime),
+ # generic trap
+ (self.snmpTrapOID, self._genTrap)]
self.setVarBinds(pdu, varBinds)
apiTrapPDU = TrapPDUAPI()