From 1f20a11284e3e9bcfc08939c48e3ab590da7c7a4 Mon Sep 17 00:00:00 2001 From: Ron DuPlain Date: Mon, 16 Jan 2012 09:23:40 -0500 Subject: [PATCH] Fall back to imports w/exotic pkg loaders, #380. Needs a test, which likely requires introducing a mock library. --- flask/helpers.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/flask/helpers.py b/flask/helpers.py index 48748dff..3c9a5669 100644 --- a/flask/helpers.py +++ b/flask/helpers.py @@ -526,10 +526,17 @@ def find_package(import_name): # For .egg, zipimporter does not have get_filename until Python 2.7. if hasattr(loader, 'get_filename'): filename = loader.get_filename(root_mod_name) - else: + elif hasattr(loader, 'archive'): # zipimporter's loader.archive points to the .egg or .zip # archive filename is dropped in call to dirname below. filename = loader.archive + else: + # At least one loader is missing both get_filename and archive: + # Google App Engine's HardenedModulesHook + # + # Fall back to imports. + __import__(import_name) + filename = sys.modules[import_name].__file__ package_path = os.path.abspath(os.path.dirname(filename)) # package_path ends with __init__.py for a package if loader.is_package(root_mod_name):