Import a module or fetch an object from a module. * ``package.module`` returns `module` as a module object. * ``pack.mod:name`` returns the module variable `name` from `pack.mod`. * ``pack.mod:func()`` calls `pack.mod.func()` and returns the result. The last form a
(target, **namespace)
| 3023 | |
| 3024 | |
| 3025 | def load(target, **namespace): |
| 3026 | """ Import a module or fetch an object from a module. |
| 3027 | |
| 3028 | * ``package.module`` returns `module` as a module object. |
| 3029 | * ``pack.mod:name`` returns the module variable `name` from `pack.mod`. |
| 3030 | * ``pack.mod:func()`` calls `pack.mod.func()` and returns the result. |
| 3031 | |
| 3032 | The last form accepts not only function calls, but any type of |
| 3033 | expression. Keyword arguments passed to this function are available as |
| 3034 | local variables. Example: ``import_string('re:compile(x)', x='[a-z]')`` |
| 3035 | """ |
| 3036 | module, target = target.split(":", 1) if ':' in target else (target, None) |
| 3037 | if module not in sys.modules: __import__(module) |
| 3038 | if not target: return sys.modules[module] |
| 3039 | if target.isalnum(): return getattr(sys.modules[module], target) |
| 3040 | package_name = module.split('.')[0] |
| 3041 | namespace[package_name] = sys.modules[package_name] |
| 3042 | return eval('%s.%s' % (module, target), namespace) |
| 3043 | |
| 3044 | |
| 3045 | def load_app(target): |