Use `compile()` before `exec` of MIB modules

This change attaches the file name to the stack frames
what is helpful when reading traceback or debugging
interactively.
async-managed-objects
Ilya Etingof 2018-10-26 08:34:26 +02:00
parent 602c4dd304
commit 4aac8b23d5
2 changed files with 7 additions and 5 deletions

View File

@ -58,9 +58,11 @@ Revision 5.0.0, released 2018-10-??
is to unify this method call with similar methods of CommandGenerator.
This change should not compromise backward compatibility with pysnmp 4.
Revision 4.4.7, released 2018-09-XX
Revision 4.4.7, released 2018-11-XX
-----------------------------------
- Use `compile()` before `exec`'ing MIB modules to attach filename to
the stack frames (ultimately shown in traceback/debugger)
- Fixed hlapi/v3arch transport target caching to ensure transport targets
are different even if just timeout/retries options differ

View File

@ -263,7 +263,7 @@ class MibBuilder(object):
self.mibSymbols = {}
self.__mibSources = []
self.__modSeen = {}
self.__modPathsSeen = {}
self.__modPathsSeen = set()
self.__mibCompiler = None
self.setMibSources(*sources)
@ -306,19 +306,19 @@ class MibBuilder(object):
debug.logger & debug.flagBld and debug.logger('loadModule: seen %s' % modPath)
break
else:
self.__modPathsSeen[modPath] = 1
self.__modPathsSeen.add(modPath)
debug.logger & debug.flagBld and debug.logger('loadModule: evaluating %s' % modPath)
g = {'mibBuilder': self, 'userCtx': userCtx}
try:
exec (modData, g)
exec(compile(modData, modPath, 'exec'), g)
except Exception:
del self.__modPathsSeen[modPath]
raise error.MibLoadError(
'MIB module \"%s\" load error: %s' % (modPath, traceback.format_exception(*sys.exc_info()))
'MIB module \'%s\' load error: %s' % (modPath, traceback.format_exception(*sys.exc_info()))
)
self.__modSeen[modName] = modPath