|
|
@ -21,9 +21,16 @@ |
|
|
|
""" |
|
|
|
""" |
|
|
|
import sys |
|
|
|
import sys |
|
|
|
import os |
|
|
|
import os |
|
|
|
|
|
|
|
import warnings |
|
|
|
from ._compat import reraise |
|
|
|
from ._compat import reraise |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ExtDeprecationWarning(DeprecationWarning): |
|
|
|
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
warnings.simplefilter('always', ExtDeprecationWarning) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ExtensionImporter(object): |
|
|
|
class ExtensionImporter(object): |
|
|
|
"""This importer redirects imports from this submodule to other locations. |
|
|
|
"""This importer redirects imports from this submodule to other locations. |
|
|
|
This makes it possible to transition from the old flaskext.name to the |
|
|
|
This makes it possible to transition from the old flaskext.name to the |
|
|
@ -49,13 +56,21 @@ class ExtensionImporter(object): |
|
|
|
sys.meta_path[:] = [x for x in sys.meta_path if self != x] + [self] |
|
|
|
sys.meta_path[:] = [x for x in sys.meta_path if self != x] + [self] |
|
|
|
|
|
|
|
|
|
|
|
def find_module(self, fullname, path=None): |
|
|
|
def find_module(self, fullname, path=None): |
|
|
|
if fullname.startswith(self.prefix): |
|
|
|
if fullname.startswith(self.prefix) and \ |
|
|
|
|
|
|
|
fullname != 'flask.ext.ExtDeprecationWarning': |
|
|
|
return self |
|
|
|
return self |
|
|
|
|
|
|
|
|
|
|
|
def load_module(self, fullname): |
|
|
|
def load_module(self, fullname): |
|
|
|
if fullname in sys.modules: |
|
|
|
if fullname in sys.modules: |
|
|
|
return sys.modules[fullname] |
|
|
|
return sys.modules[fullname] |
|
|
|
|
|
|
|
|
|
|
|
modname = fullname.split('.', self.prefix_cutoff)[self.prefix_cutoff] |
|
|
|
modname = fullname.split('.', self.prefix_cutoff)[self.prefix_cutoff] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
warnings.warn( |
|
|
|
|
|
|
|
"Importing flask.ext.{x} is deprecated, use flask_{x} instead." |
|
|
|
|
|
|
|
.format(x=modname), ExtDeprecationWarning |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
for path in self.module_choices: |
|
|
|
for path in self.module_choices: |
|
|
|
realname = path % modname |
|
|
|
realname = path % modname |
|
|
|
try: |
|
|
|
try: |
|
|
@ -83,6 +98,14 @@ class ExtensionImporter(object): |
|
|
|
module = sys.modules[fullname] = sys.modules[realname] |
|
|
|
module = sys.modules[fullname] = sys.modules[realname] |
|
|
|
if '.' not in modname: |
|
|
|
if '.' not in modname: |
|
|
|
setattr(sys.modules[self.wrapper_module], modname, module) |
|
|
|
setattr(sys.modules[self.wrapper_module], modname, module) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if realname.startswith('flaskext.'): |
|
|
|
|
|
|
|
warnings.warn( |
|
|
|
|
|
|
|
"Detected extension named flaskext.{x}, please rename it " |
|
|
|
|
|
|
|
"to flask_{x}. The old form is deprecated." |
|
|
|
|
|
|
|
.format(x=modname), ExtDeprecationWarning |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
return module |
|
|
|
return module |
|
|
|
raise ImportError('No module named %s' % fullname) |
|
|
|
raise ImportError('No module named %s' % fullname) |
|
|
|
|
|
|
|
|
|
|
|