Skip to content

Commit

Permalink
Fix Python 2.4-2.5 except statement
Browse files Browse the repository at this point in the history
Older Pythons do not support 'except ... as...' syntax.
  • Loading branch information
etingof committed Aug 5, 2018
1 parent 43a181b commit 8a3727a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 20 deletions.
23 changes: 15 additions & 8 deletions pysnmp/hlapi/asyncio/cmdgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
# THE POSSIBILITY OF SUCH DAMAGE.
#
import sys

from pysnmp.smi.rfc1902 import *
from pysnmp.hlapi.auth import *
from pysnmp.hlapi.context import *
Expand All @@ -41,6 +43,7 @@

try:
import asyncio

except ImportError:
import trollius as asyncio

Expand Down Expand Up @@ -137,8 +140,9 @@ def __cbFun(snmpEngine, sendRequestHandle,
try:
varBindsUnmade = vbProcessor.unmakeVarBinds(snmpEngine, varBinds,
lookupMib)
except Exception as e:
future.set_exception(e)
except Exception:
ex = sys.exc_info()[1]
future.set_exception(ex)
else:
future.set_result(
(errorIndication, errorStatus, errorIndex, varBindsUnmade)
Expand Down Expand Up @@ -242,8 +246,9 @@ def __cbFun(snmpEngine, sendRequestHandle,
try:
varBindsUnmade = vbProcessor.unmakeVarBinds(snmpEngine, varBinds,
lookupMib)
except Exception as e:
future.set_exception(e)
except Exception:
ex = sys.exc_info()[1]
future.set_exception(ex)
else:
future.set_result(
(errorIndication, errorStatus, errorIndex, varBindsUnmade)
Expand Down Expand Up @@ -353,8 +358,9 @@ def __cbFun(snmpEngine, sendRequestHandle,
varBindTableRow,
lookupMib)
for varBindTableRow in varBindTable]
except Exception as e:
future.set_exception(e)
except Exception:
ex = sys.exc_info()[1]
future.set_exception(ex)
else:
future.set_result(
(errorIndication, errorStatus, errorIndex, varBindsUnmade)
Expand Down Expand Up @@ -493,8 +499,9 @@ def __cbFun(snmpEngine, sendRequestHandle,
varBindTableRow,
lookupMib)
for varBindTableRow in varBindTable]
except Exception as e:
future.set_exception(e)
except Exception:
ex = sys.exc_info()[1]
future.set_exception(ex)
else:
future.set_result(
(errorIndication, errorStatus, errorIndex, varBindsUnmade)
Expand Down
8 changes: 6 additions & 2 deletions pysnmp/hlapi/asyncio/ntforg.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
# Authors: Matt Hooks <[email protected]>
# Zachary Lorusso <[email protected]>
#
import sys

from pysnmp.smi.rfc1902 import *
from pysnmp.hlapi.auth import *
from pysnmp.hlapi.context import *
Expand All @@ -18,6 +20,7 @@

try:
import asyncio

except ImportError:
import trollius as asyncio

Expand Down Expand Up @@ -127,8 +130,9 @@ def __cbFun(snmpEngine, sendRequestHandle,
try:
varBindsUnmade = vbProcessor.unmakeVarBinds(snmpEngine, varBinds,
lookupMib)
except Exception as e:
future.set_exception(e)
except Exception:
ex = sys.exc_info()[1]
future.set_exception(ex)
else:
future.set_result(
(errorIndication, errorStatus, errorIndex, varBindsUnmade)
Expand Down
22 changes: 14 additions & 8 deletions pysnmp/hlapi/twisted/cmdgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# Copyright (c) 2005-2018, Ilya Etingof <[email protected]>
# License: http://snmplabs.com/pysnmp/license.html
#
import sys

from pysnmp.smi.rfc1902 import *
from pysnmp.hlapi.auth import *
from pysnmp.hlapi.context import *
Expand Down Expand Up @@ -120,8 +122,9 @@ def __cbFun(snmpEngine, sendRequestHandle,
try:
varBindsUnmade = vbProcessor.unmakeVarBinds(snmpEngine, varBinds, lookupMib)

except Exception as e:
deferred.errback(Failure(e))
except Exception:
ex = sys.exc_info()[1]
deferred.errback(Failure(ex))

else:
deferred.callback((errorStatus, errorIndex, varBindsUnmade))
Expand Down Expand Up @@ -236,8 +239,9 @@ def __cbFun(snmpEngine, sendRequestHandle,
try:
varBindsUnmade = vbProcessor.unmakeVarBinds(snmpEngine, varBinds, lookupMib)

except Exception as e:
deferred.errback(Failure(e))
except Exception:
ex = sys.exc_info()[1]
deferred.errback(Failure(ex))

else:
deferred.callback((errorStatus, errorIndex, varBindsUnmade))
Expand Down Expand Up @@ -366,8 +370,9 @@ def __cbFun(snmpEngine, sendRequestHandle,
lookupMib)
for varBindTableRow in varBindTable]

except Exception as e:
deferred.errback(Failure(e))
except Exception:
ex = sys.exc_info()[1]
deferred.errback(Failure(ex))

else:
deferred.callback((errorStatus, errorIndex, varBindsUnmade))
Expand Down Expand Up @@ -524,8 +529,9 @@ def __cbFun(snmpEngine, sendRequestHandle,
lookupMib)
for varBindTableRow in varBindTable]

except Exception as e:
deferred.errback(Failure(e))
except Exception:
ex = sys.exc_info()[1]
deferred.errback(Failure(ex))

else:
deferred.callback((errorStatus, errorIndex, varBindsUnmade))
Expand Down
7 changes: 5 additions & 2 deletions pysnmp/hlapi/twisted/ntforg.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# Copyright (c) 2005-2018, Ilya Etingof <[email protected]>
# License: http://snmplabs.com/pysnmp/license.html
#
import sys

from pysnmp.smi.rfc1902 import *
from pysnmp.hlapi.auth import *
from pysnmp.hlapi.context import *
Expand Down Expand Up @@ -128,8 +130,9 @@ def __cbFun(snmpEngine, sendRequestHandle,
try:
varBindsUnmade = vbProcessor.unmakeVarBinds(snmpEngine, varBinds, lookupMib)

except Exception as e:
deferred.errback(Failure(e))
except Exception:
ex = sys.exc_info()[1]
deferred.errback(Failure(ex))

else:
deferred.callback((errorStatus, errorIndex, varBindsUnmade))
Expand Down

0 comments on commit 8a3727a

Please sign in to comment.