[pysnmp-dev] [PATCH] fix for loading compiled (*.{pyc, pyo}) mib files
Brought to you by:
elie
From: Jacek K. <ja...@ja...> - 2012-12-20 11:52:45
|
Hi, In the PLD Linux distribution Python 2.x modules are distributed in compiled form only (*.{pyc,pyo}, no *.py), this is also done for the MIB modules included in pysnmp. PySNMP does include code to handle that, but it is broken in the 4.2.3 release: DBG: loadModules: trying SNMPv2-MIB at DirMibSource('/usr/share/python2.7/site-packages/pysnmp/smi/mibs') DBG: bad magic in SNMPv2-MIB.pyc DBG: file SNMPv2-MIB.pyc mtime -1 DBG: file SNMPv2-MIB.py mtime -1 The magic bytes are valid in the file, but they get destroyed by the _getData() method before the test in read() method. The patch below fixes the problem. Greets, Jacek diff -dur pysnmp-4.2.3.orig/pysnmp/smi/builder.py pysnmp-4.2.3/pysnmp/smi/builder.py --- pysnmp-4.2.3.orig/pysnmp/smi/builder.py 2012-08-29 23:22:35.000000000 +0200 +++ pysnmp-4.2.3/pysnmp/smi/builder.py 2012-12-20 10:49:27.000000000 +0100 @@ -138,7 +138,7 @@ def _getData(self, f, mode=None): data = self.__loader.get_data(os.path.join(self._srcName, f)) - if sys.version_info[0] <= 2: + if sys.version_info[0] <= 2 and "b" not in mode: data = data.replace('\r\n', '\n') return data @@ -160,7 +160,7 @@ try: if f in os.listdir(self._srcName): # make FS case-sensitive data = open(os.path.join(self._srcName, f), mode).read() - if sys.version_info[0] <= 2: + if sys.version_info[0] <= 2 and "b" not in mode: data = data.replace('\r\n', '\n') return data except OSError: |