diff options
author | elie <elie> | 2015-03-07 18:00:57 +0000 |
---|---|---|
committer | elie <elie> | 2015-03-07 18:00:57 +0000 |
commit | f1e6e02a2fe9870600e025b57631c93645812c71 (patch) | |
tree | 02095cdc1d64b1e1f93459fac584b7f82c479075 | |
parent | d8996aaf996852529ce337adfcc05d839ce84707 (diff) | |
download | pysnmp-f1e6e02a2fe9870600e025b57631c93645812c71.tar.gz |
fix to smi.builder to explicitly fail on any MIB file access error but ENOENT
-rw-r--r-- | CHANGES | 2 | ||||
-rw-r--r-- | pysnmp/smi/builder.py | 25 |
2 files changed, 22 insertions, 5 deletions
@@ -112,6 +112,8 @@ Revision 4.2.6rc2 - Fix to file descriptor leak at MibBuilder. - Fix to rfc2576.v2ToV1() to ignore impossible errorStatus. - Fix to rfc2576.v1ToV2() to reset ErrorStatus==noSuchName on proxying. +- Fix to smi.builder to explicitly fail on any MIB file access error + but ENOENT. Revision 4.2.5 -------------- diff --git a/pysnmp/smi/builder.py b/pysnmp/smi/builder.py index 5840b08..d92e84d 100644 --- a/pysnmp/smi/builder.py +++ b/pysnmp/smi/builder.py @@ -1,5 +1,9 @@ # MIB modules loader import os, sys, imp, struct, marshal, time, traceback +try: + from errno import ENOENT +except ImportError: + ENOENT = -1 from pysnmp.smi import error from pysnmp import debug @@ -55,7 +59,11 @@ class __AbstractMibSource: try: pycData = self._getData(f + pycSfx, pycMode) except IOError: - pycTime = -1 + why = sys.exc_info()[1] + if why.errno == ENOENT or ENOENT == -1: + pycTime = -1 + else: + raise error.SmiError('MIB file %s access error: %s' % (f+pycSfx, why)) else: if self.__magic == pycData[:4]: pycData = pycData[4:] @@ -76,7 +84,11 @@ class __AbstractMibSource: try: pyTime = self._getTimestamp(f+pySfx) except (IOError, OSError): - pyTime = -1 + why = sys.exc_info()[1] + if why.errno == ENOENT or ENOENT == -1: + pyTime = -1 + else: + raise error.SmiError('MIB file %s access error: %s' % (f+pySfx, why)) else: break @@ -166,9 +178,12 @@ class DirMibSource(__AbstractMibSource): data = fp.read() fp.close() return data - except OSError: - pass - raise IOError # pretend there's no such file + except (IOError, OSError): + why = sys.exc_info()[1] + if why.errno != ENOENT and ENOENT != -1: + raise error.SmiError('MIB file %s access error: %s' % (os.path.join(self._srcName, f), why)) + + raise IOError(ENOENT, 'No such file or directory') class MibBuilder: loadTexts = 0 |