[kupfer] core: Update _import_plugin_fake to work with zipimported modules



commit 12344ed3d81957630b5a843dbbc746622a81514f
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Sat Feb 6 14:01:08 2010 +0100

    core: Update _import_plugin_fake to work with zipimported modules
    
    The loader interface is slightly different with a zipimporter, so we
    need to adjust the "fake plugin importer" to take this into account.

 kupfer/core/plugins.py |   13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)
---
diff --git a/kupfer/core/plugins.py b/kupfer/core/plugins.py
index 4aaee23..e2cdd60 100644
--- a/kupfer/core/plugins.py
+++ b/kupfer/core/plugins.py
@@ -180,11 +180,20 @@ def _import_plugin_fake(modpath, error=None):
 	loader = pkgutil.get_loader(modpath)
 	if not loader:
 		return None
+
+	try:
+		filename = loader.get_filename()
+	except AttributeError:
+		try:
+			filename = loader.archive + loader.prefix
+		except AttributeError:
+			filename = "<%s>" % modpath
+
 	env = {
 		"__name__": modpath,
-		"__file__": loader.get_filename(),
+		"__file__": filename,
 	}
-	code = _truncate_code(loader.get_code(), info_attributes)
+	code = _truncate_code(loader.get_code(modpath), info_attributes)
 	try:
 		eval(code, env)
 	except Exception, exc:



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]