diff options
author | elie <elie> | 2010-12-13 15:18:51 +0000 |
---|---|---|
committer | elie <elie> | 2010-12-13 15:18:51 +0000 |
commit | 5131d20dc0c28cea05b32e9475666e7cbe3ef11d (patch) | |
tree | b1abf6d273b9afada5b5e1b991d9e1a7efc49353 | |
parent | a466a021fb992cd87185415a56db876e41992c85 (diff) | |
download | pysnmp-5131d20dc0c28cea05b32e9475666e7cbe3ef11d.tar.gz |
defers management changed to make [previously re-worked] Twisted API more
backward compatible
-rw-r--r-- | CHANGES | 2 | ||||
-rw-r--r-- | examples/v3arch/twisted/manager/bulkgen.py | 11 | ||||
-rw-r--r-- | examples/v3arch/twisted/manager/nextgen.py | 11 | ||||
-rw-r--r-- | pysnmp/entity/rfc3413/twisted/cmdgen.py | 18 |
4 files changed, 20 insertions, 22 deletions
@@ -9,7 +9,6 @@ Revision 4.1.15a or pyasn1 Null (v1). Built-in GETNEXT/GETBULK apps now do not require user to track end-of-mib conditions anymore -- this is now done automatically. - (WARNING: possibly backward incompatible API change!) - CommandResponder API now supports async mode of operation. - SNMP exception values now exported from rfc1905 module, and made pretty printable. @@ -28,7 +27,6 @@ Revision 4.1.15a - Twisted-based CommandResponder example added. - Fix/rework of Twisted GETNEXT/BULK CommandGenerator callback API to make it simpler and uniform with other CommandGenerators - (WARNING: backward incompatible API change!) - Fix to SNMPv3 security module to store peer SNMP engine timeline only if taken from an authenticated message. Prior to this fix SNMP engine was not been protected from spoofing. diff --git a/examples/v3arch/twisted/manager/bulkgen.py b/examples/v3arch/twisted/manager/bulkgen.py index c6f3efd..a8c4be8 100644 --- a/examples/v3arch/twisted/manager/bulkgen.py +++ b/examples/v3arch/twisted/manager/bulkgen.py @@ -40,9 +40,7 @@ config.addSocketTransport( # Twisted API follows -def receiveResponse( - (errorIndication, errorStatus, errorIndex, varBindTable, df), - ): +def receiveResponse((errorIndication, errorStatus, errorIndex, varBindTable)): if errorIndication: print 'Error: ', errorIndication reactor.stop() @@ -65,13 +63,14 @@ def receiveResponse( reactor.stop() # no more objects available return - df.addCallback(receiveResponse) # continue walking - return 1 + df = defer.Deferred() + df.addCallback(receiveResponse) + return df # this is to indicate that we wish to continue walking bulkCmdGen = cmdgen.BulkCommandGenerator() df = bulkCmdGen.sendReq( - snmpEngine, 'myRouter', 0, 25, (((1,3,6,1,2), None),) + snmpEngine, 'myRouter', 0, 25, (((1,3,6,1,2), None), ((1,3,6,1,4), None)) ) df.addCallback(receiveResponse) diff --git a/examples/v3arch/twisted/manager/nextgen.py b/examples/v3arch/twisted/manager/nextgen.py index 704b870..306c71c 100644 --- a/examples/v3arch/twisted/manager/nextgen.py +++ b/examples/v3arch/twisted/manager/nextgen.py @@ -40,9 +40,7 @@ config.addSocketTransport( # Twisted API follows -def receiveResponse( - (errorIndication, errorStatus, errorIndex, varBindTable, df) - ): +def receiveResponse((errorIndication, errorStatus, errorIndex, varBindTable)): if errorIndication: print 'Error: ', errorIndication reactor.stop() @@ -64,9 +62,10 @@ def receiveResponse( else: reactor.stop() # no more objects available return - - df.addCallback(receiveResponse) # continue walking - return 1 + + df = defer.Deferred() + df.addCallback(receiveResponse) + return df # this is to indicate that we wish to continue walking nextCmdGen = cmdgen.NextCommandGenerator() diff --git a/pysnmp/entity/rfc3413/twisted/cmdgen.py b/pysnmp/entity/rfc3413/twisted/cmdgen.py index be366f4..64cd6a6 100644 --- a/pysnmp/entity/rfc3413/twisted/cmdgen.py +++ b/pysnmp/entity/rfc3413/twisted/cmdgen.py @@ -49,15 +49,17 @@ class SetCommandGenerator(cmdgen.SetCommandGenerator): ) return df -def _cbFunWithDeferred( - sendRequestHandle, errorIndication, errorStatus, errorIndex, varBinds, cbCtx - ): - df = defer.Deferred() - cbCtx['df'].callback( - (errorIndication, errorStatus, errorIndex, varBinds, df) +def _cbFunWithDeferred(sendRequestHandle, errorIndication, + errorStatus, errorIndex, varBinds, cbCtx): + df = cbCtx['df'] + df.callback( + (errorIndication, errorStatus, errorIndex, varBinds) ) - cbCtx['df'] = df - return len(df.callbacks) + # Callback function may return another deferred to indicate + # it wishes to continue MIB walk. + if isinstance(df.result, defer.Deferred): + cbCtx['df'] = df.result + return 1 # continue walking class NextCommandGenerator(cmdgen.NextCommandGenerator): def sendReq( |