summaryrefslogtreecommitdiff
path: root/pysnmp/smi/mibs
diff options
context:
space:
mode:
authorIlya Etingof <etingof@gmail.com>2019-02-09 17:47:15 +0100
committerIlya Etingof <etingof@gmail.com>2019-02-09 17:47:15 +0100
commit2b5603ecf98c1c47e94a405bd98054d1703af9e7 (patch)
treed0f544c895b238fbb5660dbf23b3d54c31bfa0b9 /pysnmp/smi/mibs
parent05b982f4b1cfa143d6fa607a6b9b24d3a77981a1 (diff)
downloadpysnmp-git-2b5603ecf98c1c47e94a405bd98054d1703af9e7.tar.gz
Drop Python < 2.6 except statement compatibility trick
Diffstat (limited to 'pysnmp/smi/mibs')
-rw-r--r--pysnmp/smi/mibs/SNMPv2-SMI.py41
-rw-r--r--pysnmp/smi/mibs/SNMPv2-TC.py24
2 files changed, 27 insertions, 38 deletions
diff --git a/pysnmp/smi/mibs/SNMPv2-SMI.py b/pysnmp/smi/mibs/SNMPv2-SMI.py
index 52e3ea11..03a085a1 100644
--- a/pysnmp/smi/mibs/SNMPv2-SMI.py
+++ b/pysnmp/smi/mibs/SNMPv2-SMI.py
@@ -532,9 +532,7 @@ class ManagedMibObject(ObjectType):
except error.NoSuchInstanceError:
val = exval.noSuchInstance
- except error.SmiError:
- exc = sys.exc_info()[1]
-
+ except error.SmiError as exc:
(debug.logger & debug.flagIns and
debug.logger('%s: exception %r' % (self, exc)))
@@ -605,9 +603,7 @@ class ManagedMibObject(ObjectType):
except error.NoSuchInstanceError:
val = exval.noSuchInstance
- except error.SmiError:
- exc = sys.exc_info()[1]
-
+ except error.SmiError as exc:
(debug.logger & debug.flagIns and
debug.logger('%s: exception %r' % (self, exc)))
@@ -650,9 +646,7 @@ class ManagedMibObject(ObjectType):
except error.NoSuchInstanceError:
val = exval.noSuchInstance
- except error.SmiError:
- exc = sys.exc_info()[1]
-
+ except error.SmiError as exc:
(debug.logger & debug.flagIns and
debug.logger('%s: exception %r' % (self, exc)))
@@ -891,8 +885,7 @@ class ManagedMibObject(ObjectType):
try:
node = self.getBranch(name, **context)
- except (error.NoSuchInstanceError, error.NoSuchObjectError):
- exc = sys.exc_info()[1]
+ except (error.NoSuchInstanceError, error.NoSuchObjectError) as exc:
cbFun(varBind, **dict(context, error=exc))
else:
@@ -958,8 +951,7 @@ class ManagedMibObject(ObjectType):
try:
node = self.getBranch(name, **context)
- except (error.NoSuchInstanceError, error.NoSuchObjectError):
- exc = sys.exc_info()[1]
+ except (error.NoSuchInstanceError, error.NoSuchObjectError) as exc:
cbFun(varBind, **dict(context, error=exc))
else:
@@ -1023,8 +1015,7 @@ class ManagedMibObject(ObjectType):
try:
node = self.getBranch(name, **context)
- except (error.NoSuchInstanceError, error.NoSuchObjectError):
- exc = sys.exc_info()[1]
+ except (error.NoSuchInstanceError, error.NoSuchObjectError) as exc:
cbFun(varBind, **dict(context, error=exc))
else:
@@ -1609,14 +1600,13 @@ class MibScalarInstance(ManagedMibObject):
else:
return self.syntax.clone(value)
- except PyAsn1Error:
- exc_t, exc_v, exc_tb = sys.exc_info()
+ except PyAsn1Error as exc:
debug.logger & debug.flagIns and debug.logger('setValue: %s=%r failed with traceback %s' % (
- self.name, value, traceback.format_exception(exc_t, exc_v, exc_tb)))
- if isinstance(exc_v, error.TableRowManagement):
- raise exc_v
+ self.name, value, traceback.format_exception(*sys.exc_info())))
+ if isinstance(exc, error.TableRowManagement):
+ raise exc
else:
- raise error.WrongValueError(name=name, idx=context.get('idx'), msg=exc_v)
+ raise error.WrongValueError(name=name, idx=context.get('idx'), msg=exc)
#
# Subtree traversal
@@ -1937,16 +1927,14 @@ class MibScalarInstance(ManagedMibObject):
try:
instances[self.ST_CREATE][idx] = self.setValue(val, name, **context)
- except error.MibOperationError:
+ except error.MibOperationError as exc:
# SMI exceptions may carry additional content
- exc = sys.exc_info()[1]
if 'syntax' in exc:
instances[self.ST_CREATE][idx] = exc['syntax']
cbFun(varBind, **dict(context, error=exc))
return
else:
- exc = sys.exc_info()[1]
exc = error.WrongValueError(name=name, idx=context.get('idx'), msg=exc)
cbFun(varBind, **dict(context, error=exc))
return
@@ -3264,8 +3252,9 @@ class MibTableRow(ManagedMibObject):
mibObj, = mibBuilder.importSymbols(modName, symName)
try:
syntax, instId = self.oidToValue(mibObj.syntax, instId, impliedFlag, indices)
- except PyAsn1Error:
- debug.logger & debug.flagIns and debug.logger('error resolving table indices at %s, %s: %s' % (self.__class__.__name__, instId, sys.exc_info()[1]))
+ except PyAsn1Error as exc:
+ debug.logger & debug.flagIns and debug.logger(
+ 'error resolving table indices at %s, %s: %s' % (self.__class__.__name__, instId, exc))
indices = [instId]
instId = ()
break
diff --git a/pysnmp/smi/mibs/SNMPv2-TC.py b/pysnmp/smi/mibs/SNMPv2-TC.py
index 2242b91e..1367e936 100644
--- a/pysnmp/smi/mibs/SNMPv2-TC.py
+++ b/pysnmp/smi/mibs/SNMPv2-TC.py
@@ -62,9 +62,9 @@ class TextualConvention(object):
elif displayHintType == 'd':
try:
return '%.*f' % (int(decimalPrecision), float(value) / pow(10, int(decimalPrecision)))
- except Exception:
+ except Exception as exc:
raise SmiError(
- 'float evaluation error: %s' % sys.exc_info()[1]
+ 'float evaluation error: %s' % exc
)
elif displayHintType == 'o':
return '0%o' % value
@@ -148,10 +148,10 @@ class TextualConvention(object):
try:
number |= octets.oct2int(numberString[0])
numberString = numberString[1:]
- except Exception:
+ except Exception as exc:
raise SmiError(
'Display format eval failure: %s: %s'
- % (numberString, sys.exc_info()[1])
+ % (numberString, exc)
)
if displayFormat == 'x':
outputValue += '%02x' % number
@@ -210,23 +210,23 @@ class TextualConvention(object):
return base.prettyIn(self, -int(value[3:], 16))
else:
return base.prettyIn(self, int(value[2:], 16))
- except Exception:
+ except Exception as exc:
raise SmiError(
- 'integer evaluation error: %s' % sys.exc_info()[1]
+ 'integer evaluation error: %s' % exc
)
elif displayHintType == 'd':
try:
return base.prettyIn(self, int(float(value) * 10**int(decimalPrecision)))
- except Exception:
+ except Exception as exc:
raise SmiError(
- 'float evaluation error: %s' % sys.exc_info()[1]
+ 'float evaluation error: %s' % exc
)
elif displayHintType == 'o' and (value.startswith('0') or value.startswith('-0')):
try:
return base.prettyIn(self, int(value, 8))
- except Exception:
+ except Exception as exc:
raise SmiError(
- 'octal evaluation error: %s' % sys.exc_info()[1]
+ 'octal evaluation error: %s' % exc
)
elif displayHintType == 'b' and (value.startswith('B') or value.startswith('-B')):
negative = value.startswith('-')
@@ -328,10 +328,10 @@ class TextualConvention(object):
try:
num = int(octets.octs2str(runningValue[:guessedOctetLength]), numBase[displayFormat])
- except Exception:
+ except Exception as exc:
raise SmiError(
'Display format eval failure: %s: %s'
- % (runningValue[:guessedOctetLength], sys.exc_info()[1])
+ % (runningValue[:guessedOctetLength], exc)
)
num_as_bytes = []