]>
Commit | Line | Data |
---|---|---|
1 | def import_module(callback): | |
2 | """ | |
3 | Handle "magic" Flask extension imports: | |
4 | ``flask.ext.foo`` is really ``flask_foo`` or ``flaskext.foo``. | |
5 | """ | |
6 | def wrapper(inference_state, import_names, module_context, *args, **kwargs): | |
7 | if len(import_names) == 3 and import_names[:2] == ('flask', 'ext'): | |
8 | # New style. | |
9 | ipath = ('flask_' + import_names[2]), | |
10 | value_set = callback(inference_state, ipath, None, *args, **kwargs) | |
11 | if value_set: | |
12 | return value_set | |
13 | value_set = callback(inference_state, ('flaskext',), None, *args, **kwargs) | |
14 | return callback( | |
15 | inference_state, | |
16 | ('flaskext', import_names[2]), | |
17 | next(iter(value_set)), | |
18 | *args, **kwargs | |
19 | ) | |
20 | return callback(inference_state, import_names, module_context, *args, **kwargs) | |
21 | return wrapper |