diff options
author | Jason Stitt <jason@countergram.com> | 2010-11-11 08:49:55 -0600 |
---|---|---|
committer | Jason Stitt <jason@countergram.com> | 2010-11-11 08:49:55 -0600 |
commit | f819a48f6744e2a26386f0035cfb9bc989772514 (patch) | |
tree | 3d07fc7d5065d6882f845cc49a5d3e8ed22742a2 /paste/deploy/loadwsgi.py | |
parent | d66a3541af72d509c886259a81e2e21d62e03eda (diff) | |
download | pastedeploy-f819a48f6744e2a26386f0035cfb9bc989772514.tar.gz |
Added a new loader using the call: protocol that uses an object path and not an egg
Diffstat (limited to 'paste/deploy/loadwsgi.py')
-rw-r--r-- | paste/deploy/loadwsgi.py | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/paste/deploy/loadwsgi.py b/paste/deploy/loadwsgi.py index bae77ae..6b373d0 100644 --- a/paste/deploy/loadwsgi.py +++ b/paste/deploy/loadwsgi.py @@ -278,6 +278,14 @@ def _loadegg(object_type, uri, spec, name, relative_to, _loaders['egg'] = _loadegg +def _loadfunc(object_type, uri, spec, name, relative_to, + global_conf): + + loader = FuncLoader(spec) + return loader.get_context(object_type, name, global_conf) + +_loaders['call'] = _loadfunc + ############################################################ ## Loaders ############################################################ @@ -428,6 +436,20 @@ class ConfigLoader(_Loader): context.global_conf['__file__'] = global_conf['__file__'] # @@: Should loader be overwritten? context.loader = self + + if context.protocol is None: + # Determine protocol from section type + section_protocol = section.split(':', 1)[0] + if section_protocol in ('application','app'): + context.protocol = 'paste.app_factory' + elif section_protocol in ('composit','composite'): + context.protocol = 'paste.composit_factory' + else: + # This will work with 'server' and 'filter', otherwise it + # could fail but there is an error message already for + # bad protocols + context.protocol = 'paste.%s_factory' % context_protocol + return context def _context_from_explicit(self, object_type, local_conf, global_conf, @@ -596,6 +618,38 @@ class EggLoader(_Loader): % (name, self.spec, ', '.join(_flatten(protocol_options)))) return possible[0] + +class FuncLoader(_Loader): + """ Loader that supports specifying functions inside modules, without + using eggs at all. Configuration should be in the format: + use = call:my.module.path:function_name + + Dot notation is supported in both the module and function name, e.g.: + use = call:my.module.path:object.method + """ + def __init__(self, spec): + self.spec = spec + try: + self.module_path, self.func_name = self.spec.split(':') + except ValueError: + raise LookupError("Configuration not in format module:function") + self.module_name = self.module_path.split('.', 1)[-1] + + def get_context(self, object_type, name=None, global_conf=None): + module = __import__(self.module_path, {}, {}, [self.module_name], 0) + obj = module + for part in self.func_name.split('.'): + obj = getattr(obj, part) + return LoaderContext( + obj, + object_type, + None, # determine protocol from section type + global_conf or {}, + {}, + self, + ) + + class LoaderContext(object): def __init__(self, obj, object_type, protocol, |