From 9b43cb8cf32f896b0cffd368f8b2b3cb5aefadd7 Mon Sep 17 00:00:00 2001 From: Ilya Etingof Date: Sun, 3 Jul 2016 10:28:12 +0200 Subject: fix to pythonnized MIB loading when only .pyc files are present --- CHANGES.txt | 2 ++ pysnmp/smi/builder.py | 31 ++++++++++++++++--------------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index f648f374..af5c4ddf 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -12,6 +12,8 @@ Github `repo `_ - Fix to NotificationType to make additional var-binds overriding MIB objects implicitly included through NOTIFICATION-TYPE OBJECTS. - Fix to SNMP engine boots counter persistence on Python 3. +- Fix to Pythonized MIBs loading when only .pyc files are + present (e.g. py2exe/cx_freeze environments). Revision 4.3.2, released 2016-02-12 ----------------------------------- diff --git a/pysnmp/smi/builder.py b/pysnmp/smi/builder.py index bee2bcfc..abee7ccf 100644 --- a/pysnmp/smi/builder.py +++ b/pysnmp/smi/builder.py @@ -72,13 +72,17 @@ class __AbstractMibSource(object): return self._listdir() def read(self, f): + pycTime = pyTime = -1 + for pycSfx, pycSfxLen, pycMode in self.__sfx[imp.PY_COMPILED]: try: pycData = self._getData(f + pycSfx, pycMode) except IOError: why = sys.exc_info()[1] - if why.errno == ENOENT or ENOENT == -1: - pycTime = -1 + if ENOENT == -1 or why.errno == ENOENT: + debug.logger & debug.flagBld and debug.logger( + 'file %s access error: %s' % (f + pycSfx, why) + ) else: raise error.MibLoadError('MIB file %s access error: %s' % (f + pycSfx, why)) else: @@ -86,35 +90,32 @@ class __AbstractMibSource(object): pycData = pycData[4:] pycTime = struct.unpack('= pyTime: # noinspection PyUnboundLocalVariable return marshal.loads(pycData), pycSfx -- cgit v1.2.1