Floris Bruynooghe avatar Floris Bruynooghe committed 271b063

Add zipimport patch

Comments (0)

Files changed (2)

 # Placed by Bitbucket


+# HG changeset patch
+# Parent 4b55ad40552efab8d7c76dedcdc44bde8ba0f401
+# User Floris Bruynooghe <flub@devork.be>
+# Date 1324248062 -3600
+When loading from a ZipImport source accept both .pyc and .pyo files
+The zipimport module itself does not correctly choose between .pyc and
+.pyo files, it will use .pyc when python is invoked with -O and will
+also use .pyo if it is not.  This patch emulates that surprising
+diff --git a/pysnmp/smi/builder.py b/pysnmp/smi/builder.py
+--- a/pysnmp/smi/builder.py
++++ b/pysnmp/smi/builder.py
+@@ -51,6 +51,12 @@ class __AbstractMibSource:
+             if typ not in self.__sfx:
+                 self.__sfx[typ] = []
+             self.__sfx[typ].append((sfx, len(sfx), mode))
++            if isinstance(self, ZipMibSource) and typ == imp.PY_COMPILED:
++                # zipimport is not fussy about the type of bytecode
++                if sfx == '.pyc':
++                    self.__sfx[typ].append(('.pyo', len('.pyo'), mode))
++                elif sfx == '.pyo':
++                    self.__sfx[typ].append(('.pyc', len('.pyc'), mode))
+         debug.logger & debug.flagBld and debug.logger('trying %s' % self)
+     def __repr__(self):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.