summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlya Etingof <etingof@gmail.com>2018-10-26 08:34:26 +0200
committerIlya Etingof <etingof@gmail.com>2018-10-26 08:34:26 +0200
commit5057a1fd59e1f1e5818f5da945677835bae38ad9 (patch)
tree916406881ad2472b100bc821f50ad1c4ad21891f
parent1315e5e9799caed8be6d2eabb8601b2b136a5238 (diff)
downloadpysnmp-git-5057a1fd59e1f1e5818f5da945677835bae38ad9.tar.gz
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.
-rw-r--r--CHANGES.txt4
-rw-r--r--pysnmp/smi/builder.py8
2 files changed, 7 insertions, 5 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index b815edb3..f2563d03 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,7 +1,9 @@
-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
diff --git a/pysnmp/smi/builder.py b/pysnmp/smi/builder.py
index 8b81b06c..a622d140 100644
--- a/pysnmp/smi/builder.py
+++ b/pysnmp/smi/builder.py
@@ -263,7 +263,7 @@ class MibBuilder(object):
self.mibSymbols = {}
self.__mibSources = []
self.__modSeen = {}
- self.__modPathsSeen = {}
+ self.__modPathsSeen = set()
self.__mibCompiler = None
self.setMibSources(*sources)
@@ -321,19 +321,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