summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlya Etingof <etingof@gmail.com>2016-07-03 10:28:12 +0200
committerIlya Etingof <etingof@gmail.com>2016-07-03 10:28:12 +0200
commit9b43cb8cf32f896b0cffd368f8b2b3cb5aefadd7 (patch)
treea6ae1c12d8d65126cd36b553bd5a20539509c8f8
parent960e39c6770aa1be50f07d2920592d166d2dabcf (diff)
downloadpysnmp-git-9b43cb8cf32f896b0cffd368f8b2b3cb5aefadd7.tar.gz
fix to pythonnized MIB loading when only .pyc files are present
-rw-r--r--CHANGES.txt2
-rw-r--r--pysnmp/smi/builder.py31
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 <https://github.com/etingof/pysnmp>`_
- 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('<L', pycData[:4])[0]
pycData = pycData[4:]
+ debug.logger & debug.flagBld and debug.logger(
+ 'file %s mtime %d' % (f + pycSfx, pycTime)
+ )
break
else:
debug.logger & debug.flagBld and debug.logger(
'bad magic in %s' % (f + pycSfx,)
)
- pycTime = -1
-
- # noinspection PyUnboundLocalVariable
- debug.logger & debug.flagBld and debug.logger(
- 'file %s mtime %d' % (f + pycSfx, pycTime)
- )
for pySfx, pySfxLen, pyMode in self.__sfx[imp.PY_SOURCE]:
try:
pyTime = self._getTimestamp(f + pySfx)
except IOError:
why = sys.exc_info()[1]
- if why.errno == ENOENT or ENOENT == -1:
- pyTime = -1
+ if ENOENT == -1 or why.errno == ENOENT:
+ debug.logger & debug.flagBld and debug.logger(
+ 'file %s access error: %s' % (f + pySfx, why)
+ )
else:
raise error.MibLoadError('MIB file %s access error: %s' % (f + pySfx, why))
else:
+ debug.logger & debug.flagBld and debug.logger(
+ 'file %s mtime %d' % (f + pySfx, pyTime)
+ )
break
- # noinspection PyUnboundLocalVariable
- debug.logger & debug.flagBld and debug.logger(
- 'file %s mtime %d' % (f + pySfx, pyTime)
- )
-
if pycTime != -1 and pycTime >= pyTime:
# noinspection PyUnboundLocalVariable
return marshal.loads(pycData), pycSfx