diff options
author | Ilya Etingof <etingof@gmail.com> | 2019-02-09 17:47:15 +0100 |
---|---|---|
committer | Ilya Etingof <etingof@gmail.com> | 2019-02-09 17:47:15 +0100 |
commit | 2b5603ecf98c1c47e94a405bd98054d1703af9e7 (patch) | |
tree | d0f544c895b238fbb5660dbf23b3d54c31bfa0b9 /pysnmp/proto | |
parent | 05b982f4b1cfa143d6fa607a6b9b24d3a77981a1 (diff) | |
download | pysnmp-git-2b5603ecf98c1c47e94a405bd98054d1703af9e7.tar.gz |
Drop Python < 2.6 except statement compatibility trick
Diffstat (limited to 'pysnmp/proto')
-rw-r--r-- | pysnmp/proto/mpmod/rfc2576.py | 4 | ||||
-rw-r--r-- | pysnmp/proto/mpmod/rfc3412.py | 7 | ||||
-rw-r--r-- | pysnmp/proto/rfc3412.py | 12 | ||||
-rw-r--r-- | pysnmp/proto/secmod/rfc2576.py | 8 | ||||
-rw-r--r-- | pysnmp/proto/secmod/rfc3414/service.py | 32 | ||||
-rw-r--r-- | pysnmp/proto/secmod/rfc7860/auth/hmacsha2.py | 8 |
6 files changed, 37 insertions, 34 deletions
diff --git a/pysnmp/proto/mpmod/rfc2576.py b/pysnmp/proto/mpmod/rfc2576.py index b355868f..9c050430 100644 --- a/pysnmp/proto/mpmod/rfc2576.py +++ b/pysnmp/proto/mpmod/rfc2576.py @@ -292,8 +292,8 @@ class SnmpV1MessageProcessingModel(AbstractMessageProcessingModel): debug.logger & debug.flagMP and debug.logger( 'prepareDataElements: SM returned securityEngineId %r securityName %r' % (securityEngineId, securityName)) - except error.StatusInformation: - statusInformation = sys.exc_info()[1] + except error.StatusInformation as exc: + statusInformation = exc snmpEngine.observer.storeExecutionContext( snmpEngine, 'rfc2576.prepareDataElements:sm-failure', diff --git a/pysnmp/proto/mpmod/rfc3412.py b/pysnmp/proto/mpmod/rfc3412.py index 58f3acc0..bda72cd9 100644 --- a/pysnmp/proto/mpmod/rfc3412.py +++ b/pysnmp/proto/mpmod/rfc3412.py @@ -530,8 +530,8 @@ class SnmpV3MessageProcessingModel(AbstractMessageProcessingModel): ) debug.logger & debug.flagMP and debug.logger('prepareDataElements: SM succeeded') - except error.StatusInformation: - statusInformation, origTraceback = sys.exc_info()[1:3] + except error.StatusInformation as exc: + statusInformation = exc debug.logger & debug.flagMP and debug.logger( 'prepareDataElements: SM failed, statusInformation %s' % statusInformation) @@ -596,8 +596,11 @@ class SnmpV3MessageProcessingModel(AbstractMessageProcessingModel): if sys.version_info[0] <= 2: raise statusInformation else: + origTraceback = sys.exc_info()[2] + try: raise statusInformation.with_traceback(origTraceback) + finally: # Break cycle between locals and traceback object # (seems to be irrelevant on Py3 but just in case) diff --git a/pysnmp/proto/rfc3412.py b/pysnmp/proto/rfc3412.py index 23f61933..11194984 100644 --- a/pysnmp/proto/rfc3412.py +++ b/pysnmp/proto/rfc3412.py @@ -330,8 +330,8 @@ class MsgAndPduDispatcher(object): debug.logger & debug.flagDsp and debug.logger('receiveMessage: MP succeded') - except error.StatusInformation: - statusInformation = sys.exc_info()[1] + except error.StatusInformation as exc: + statusInformation = exc if 'sendPduHandle' in statusInformation: # Dropped REPORT -- re-run pending reqs queue as some # of them may be waiting for this REPORT @@ -345,8 +345,8 @@ class MsgAndPduDispatcher(object): ) return restOfWholeMsg - except PyAsn1Error: - debug.logger & debug.flagMP and debug.logger('receiveMessage: %s' % (sys.exc_info()[1],)) + except PyAsn1Error as exc: + debug.logger & debug.flagMP and debug.logger('receiveMessage: %s' % exc) snmpInASNParseErrs, = snmpEngine.msgAndPduDsp.mibInstrumController.mibBuilder.importSymbols('__SNMPv2-MIB', 'snmpInASNParseErrs') snmpInASNParseErrs.syntax += 1 @@ -395,9 +395,9 @@ class MsgAndPduDispatcher(object): destTransportAddress ) - except PySnmpError: + except PySnmpError as exc: debug.logger & debug.flagDsp and debug.logger( - 'receiveMessage: report failed, statusInformation %s' % sys.exc_info()[1]) + 'receiveMessage: report failed, statusInformation %s' % exc) else: debug.logger & debug.flagDsp and debug.logger('receiveMessage: reporting succeeded') diff --git a/pysnmp/proto/secmod/rfc2576.py b/pysnmp/proto/secmod/rfc2576.py index 4cbb2f74..4b49b83a 100644 --- a/pysnmp/proto/secmod/rfc2576.py +++ b/pysnmp/proto/secmod/rfc2576.py @@ -358,9 +358,9 @@ class SnmpV1SecurityModel(base.AbstractSecurityModel): try: return securityParameters, encoder.encode(msg) - except PyAsn1Error: + except PyAsn1Error as exc: debug.logger & debug.flagMP and debug.logger( - 'generateRequestMsg: serialization failure: %s' % sys.exc_info()[1]) + 'generateRequestMsg: serialization failure: %s' % exc) raise error.StatusInformation(errorIndication=errind.serializationError) def generateResponseMsg(self, snmpEngine, messageProcessingModel, @@ -388,9 +388,9 @@ class SnmpV1SecurityModel(base.AbstractSecurityModel): try: return communityName, encoder.encode(msg) - except PyAsn1Error: + except PyAsn1Error as exc: debug.logger & debug.flagMP and debug.logger( - 'generateResponseMsg: serialization failure: %s' % sys.exc_info()[1]) + 'generateResponseMsg: serialization failure: %s' % exc) raise error.StatusInformation(errorIndication=errind.serializationError) def processIncomingMsg(self, snmpEngine, messageProcessingModel, diff --git a/pysnmp/proto/secmod/rfc3414/service.py b/pysnmp/proto/secmod/rfc3414/service.py index a999b027..b9fa9a2c 100644 --- a/pysnmp/proto/secmod/rfc3414/service.py +++ b/pysnmp/proto/secmod/rfc3414/service.py @@ -294,9 +294,9 @@ class SnmpUSMSecurityModel(AbstractSecurityModel): debug.logger & debug.flagSM and debug.logger('__generateRequestOrResponseMsg: clone user info') - except PyAsn1Error: + except PyAsn1Error as exc: debug.logger & debug.flagSM and debug.logger( - '__generateRequestOrResponseMsg: %s' % (sys.exc_info()[1],)) + '__generateRequestOrResponseMsg: %s' % exc) snmpInGenErrs, = mibBuilder.importSymbols('__SNMPv2-MIB', 'snmpInGenErrs') snmpInGenErrs.syntax += 1 raise error.StatusInformation( @@ -389,9 +389,9 @@ class SnmpUSMSecurityModel(AbstractSecurityModel): try: dataToEncrypt = encoder.encode(scopedPDU) - except PyAsn1Error: + except PyAsn1Error as exc: debug.logger & debug.flagSM and debug.logger( - '__generateRequestOrResponseMsg: scopedPDU serialization error: %s' % sys.exc_info()[1]) + '__generateRequestOrResponseMsg: scopedPDU serialization error: %s' % exc) raise error.StatusInformation( errorIndication=errind.serializationError ) @@ -458,9 +458,9 @@ class SnmpUSMSecurityModel(AbstractSecurityModel): try: msg.setComponentByPosition(2, encoder.encode(securityParameters), verifyConstraints=False) - except PyAsn1Error: + except PyAsn1Error as exc: debug.logger & debug.flagSM and debug.logger( - '__generateRequestOrResponseMsg: securityParameters serialization error: %s' % sys.exc_info()[1]) + '__generateRequestOrResponseMsg: securityParameters serialization error: %s' % exc) raise error.StatusInformation( errorIndication=errind.serializationError ) @@ -471,9 +471,9 @@ class SnmpUSMSecurityModel(AbstractSecurityModel): try: wholeMsg = encoder.encode(msg) - except PyAsn1Error: + except PyAsn1Error as exc: debug.logger & debug.flagSM and debug.logger( - '__generateRequestOrResponseMsg: msg serialization error: %s' % sys.exc_info()[1]) + '__generateRequestOrResponseMsg: msg serialization error: %s' % exc) raise error.StatusInformation( errorIndication=errind.serializationError ) @@ -495,9 +495,9 @@ class SnmpUSMSecurityModel(AbstractSecurityModel): try: msg.setComponentByPosition(2, encoder.encode(securityParameters), verifyConstraints=False, matchTags=False, matchConstraints=False) - except PyAsn1Error: + except PyAsn1Error as exc: debug.logger & debug.flagSM and debug.logger( - '__generateRequestOrResponseMsg: secutiryParameters serialization error: %s' % sys.exc_info()[1]) + '__generateRequestOrResponseMsg: secutiryParameters serialization error: %s' % exc) raise error.StatusInformation( errorIndication=errind.serializationError ) @@ -507,9 +507,9 @@ class SnmpUSMSecurityModel(AbstractSecurityModel): '__generateRequestOrResponseMsg: plain outgoing msg: %s' % msg.prettyPrint()) authenticatedWholeMsg = encoder.encode(msg) - except PyAsn1Error: + except PyAsn1Error as exc: debug.logger & debug.flagSM and debug.logger( - '__generateRequestOrResponseMsg: msg serialization error: %s' % sys.exc_info()[1]) + '__generateRequestOrResponseMsg: msg serialization error: %s' % exc) raise error.StatusInformation( errorIndication=errind.serializationError ) @@ -682,8 +682,8 @@ class SnmpUSMSecurityModel(AbstractSecurityModel): maxSizeResponseScopedPDU=maxSizeResponseScopedPDU ) - except PyAsn1Error: - debug.logger & debug.flagSM and debug.logger('processIncomingMsg: %s' % (sys.exc_info()[1],)) + except PyAsn1Error as exc: + debug.logger & debug.flagSM and debug.logger('processIncomingMsg: %s' % exc) snmpInGenErrs, = mibBuilder.importSymbols('__SNMPv2-MIB', 'snmpInGenErrs') snmpInGenErrs.syntax += 1 raise error.StatusInformation(errorIndication=errind.invalidMsg) @@ -948,9 +948,9 @@ class SnmpUSMSecurityModel(AbstractSecurityModel): try: scopedPDU, rest = decoder.decode(decryptedData, asn1Spec=scopedPduSpec) - except PyAsn1Error: + except PyAsn1Error as exc: debug.logger & debug.flagSM and debug.logger( - 'processIncomingMsg: scopedPDU decoder failed %s' % sys.exc_info()[0]) + 'processIncomingMsg: scopedPDU decoder failed %s' % exc) raise error.StatusInformation( errorIndication=errind.decryptionError, msgUserName=msgUserName diff --git a/pysnmp/proto/secmod/rfc7860/auth/hmacsha2.py b/pysnmp/proto/secmod/rfc7860/auth/hmacsha2.py index a043be2c..219b90d6 100644 --- a/pysnmp/proto/secmod/rfc7860/auth/hmacsha2.py +++ b/pysnmp/proto/secmod/rfc7860/auth/hmacsha2.py @@ -82,8 +82,8 @@ class HmacSha2(base.AbstractAuthenticationService): try: mac = hmac.new(authKey.asOctets(), wholeMsg, self.__hashAlgo) - except errind.ErrorIndication: - raise error.StatusInformation(errorIndication=sys.exc_info()[1]) + except errind.ErrorIndication as exc: + raise error.StatusInformation(errorIndication=exc) # 7.3.1.4 mac = mac.digest()[:self.__digestLength] @@ -111,8 +111,8 @@ class HmacSha2(base.AbstractAuthenticationService): try: mac = hmac.new(authKey.asOctets(), authenticatedWholeMsg, self.__hashAlgo) - except errind.ErrorIndication: - raise error.StatusInformation(errorIndication=sys.exc_info()[1]) + except errind.ErrorIndication as exc: + raise error.StatusInformation(errorIndication=exc) # 7.3.2.5 mac = mac.digest()[:self.__digestLength] |