diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/paste/__init__.py | 5 | ||||
-rw-r--r-- | src/paste/deploy/__init__.py | 2 | ||||
-rw-r--r-- | src/paste/deploy/config.py | 63 | ||||
-rw-r--r-- | src/paste/deploy/loadwsgi.py | 370 | ||||
-rw-r--r-- | src/paste/deploy/paster_templates.py | 18 | ||||
-rw-r--r-- | src/paste/deploy/util.py | 6 |
6 files changed, 281 insertions, 183 deletions
diff --git a/src/paste/__init__.py b/src/paste/__init__.py index cdb6121..d31480b 100644 --- a/src/paste/__init__.py +++ b/src/paste/__init__.py @@ -2,11 +2,13 @@ # Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php try: import pkg_resources + pkg_resources.declare_namespace(__name__) except ImportError: # don't prevent use of paste if pkg_resources isn't installed from pkgutil import extend_path - __path__ = extend_path(__path__, __name__) + + __path__ = extend_path(__path__, __name__) try: import modulefinder @@ -15,4 +17,3 @@ except ImportError: else: for p in __path__: modulefinder.AddPackagePath(__name__, p) - diff --git a/src/paste/deploy/__init__.py b/src/paste/deploy/__init__.py index 94c63a8..cacb9a6 100644 --- a/src/paste/deploy/__init__.py +++ b/src/paste/deploy/__init__.py @@ -1,3 +1,3 @@ # (c) 2005 Ian Bicking and contributors; written for Paste (http://pythonpaste.org) # Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php -from paste.deploy.loadwsgi import * +from paste.deploy.loadwsgi import * # noqa F401,F403 diff --git a/src/paste/deploy/config.py b/src/paste/deploy/config.py index f448350..3c24151 100644 --- a/src/paste/deploy/config.py +++ b/src/paste/deploy/config.py @@ -1,8 +1,8 @@ # (c) 2005 Ian Bicking and contributors; written for Paste (http://pythonpaste.org) # Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php """Paste Configuration Middleware and Objects""" -import threading import re +import threading # Loaded lazily wsgilib = None @@ -47,7 +47,7 @@ class DispatchingConfig: self.dispatching_id = 0 while 1: self._local_key = 'paste.processconfig_%i' % self.dispatching_id - if not self._local_key in local_dict(): + if self._local_key not in local_dict(): break self.dispatching_id += 1 finally: @@ -84,8 +84,8 @@ class DispatchingConfig: if conf is not None and popped is not conf: raise AssertionError( "The config popped (%s) is not the same as the config " - "expected (%s)" - % (popped, conf)) + "expected (%s)" % (popped, conf) + ) def push_process_config(self, conf): """ @@ -101,8 +101,8 @@ class DispatchingConfig: conf = self.current_conf() if conf is None: raise AttributeError( - "No configuration has been registered for this process " - "or thread") + "No configuration has been registered for this process " "or thread" + ) return getattr(conf, attr) def current_conf(self): @@ -119,8 +119,8 @@ class DispatchingConfig: conf = self.current_conf() if conf is None: raise TypeError( - "No configuration has been registered for this process " - "or thread") + "No configuration has been registered for this process " "or thread" + ) return conf[key] def __contains__(self, key): @@ -132,6 +132,7 @@ class DispatchingConfig: conf = self.current_conf() conf[key] = value + CONFIG = DispatchingConfig() @@ -155,6 +156,7 @@ class ConfigMiddleware: global wsgilib if wsgilib is None: import pkg_resources + pkg_resources.require('Paste') from paste import wsgilib popped_config = None @@ -180,8 +182,10 @@ class ConfigMiddleware: environ['paste.config'] = popped_config return app_iter else: + def close_config(): CONFIG.pop_thread_config(conf) + new_app_iter = wsgilib.add_close(app_iter, close_config) return new_app_iter @@ -191,6 +195,7 @@ def make_config_filter(app, global_conf, **local_conf): conf.update(local_conf) return ConfigMiddleware(app, conf) + make_config_middleware = ConfigMiddleware.__doc__ @@ -246,9 +251,16 @@ class PrefixMiddleware: You can also use ``scheme`` to explicitly set the scheme (like ``scheme = https``). """ - def __init__(self, app, global_conf=None, prefix='/', - translate_forwarded_server=True, - force_port=None, scheme=None): + + def __init__( + self, + app, + global_conf=None, + prefix='/', + translate_forwarded_server=True, + force_port=None, + scheme=None, + ): self.app = app self.prefix = prefix.rstrip('/') self.translate_forwarded_server = translate_forwarded_server @@ -265,11 +277,17 @@ class PrefixMiddleware: environ['SCRIPT_NAME'] = self.prefix if self.translate_forwarded_server: if 'HTTP_X_FORWARDED_SERVER' in environ: - environ['SERVER_NAME'] = environ['HTTP_HOST'] = environ.pop('HTTP_X_FORWARDED_SERVER').split(',')[0] + environ['SERVER_NAME'] = environ['HTTP_HOST'] = environ.pop( + 'HTTP_X_FORWARDED_SERVER' + ).split(',')[0] if 'HTTP_X_FORWARDED_HOST' in environ: - environ['HTTP_HOST'] = environ.pop('HTTP_X_FORWARDED_HOST').split(',')[0] + environ['HTTP_HOST'] = environ.pop('HTTP_X_FORWARDED_HOST').split(',')[ + 0 + ] if 'HTTP_X_FORWARDED_FOR' in environ: - environ['REMOTE_ADDR'] = environ.pop('HTTP_X_FORWARDED_FOR').split(',')[0] + environ['REMOTE_ADDR'] = environ.pop('HTTP_X_FORWARDED_FOR').split(',')[ + 0 + ] if 'HTTP_X_FORWARDED_SCHEME' in environ: environ['wsgi.url_scheme'] = environ.pop('HTTP_X_FORWARDED_SCHEME') elif 'HTTP_X_FORWARDED_PROTO' in environ: @@ -292,14 +310,23 @@ class PrefixMiddleware: def make_prefix_middleware( - app, global_conf, prefix='/', + app, + global_conf, + prefix='/', translate_forwarded_server=True, - force_port=None, scheme=None): + force_port=None, + scheme=None, +): from paste.deploy.converters import asbool + translate_forwarded_server = asbool(translate_forwarded_server) return PrefixMiddleware( - app, prefix=prefix, + app, + prefix=prefix, translate_forwarded_server=translate_forwarded_server, - force_port=force_port, scheme=scheme) + force_port=force_port, + scheme=scheme, + ) + make_prefix_middleware.__doc__ = PrefixMiddleware.__doc__ diff --git a/src/paste/deploy/loadwsgi.py b/src/paste/deploy/loadwsgi.py index c5471e5..dfa231d 100644 --- a/src/paste/deploy/loadwsgi.py +++ b/src/paste/deploy/loadwsgi.py @@ -2,11 +2,11 @@ # Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php from configparser import ConfigParser import os -import pkg_resources import re import sys from urllib.parse import unquote +import pkg_resources from paste.deploy.util import fix_call, lookup_object @@ -14,7 +14,7 @@ __all__ = ['loadapp', 'loadserver', 'loadfilter', 'appconfig'] ############################################################ -## Utility functions +# Utility functions ############################################################ @@ -54,7 +54,6 @@ def _flatten(lst): class NicerConfigParser(ConfigParser): - def __init__(self, filename, *args, **kw): ConfigParser.__init__(self, *args, **kw) self.filename = filename @@ -80,8 +79,9 @@ class NicerConfigParser(ConfigParser): def before_get(self, parser, section, option, value, defaults): try: - return self._original.before_get(parser, section, option, - value, defaults) + return self._original.before_get( + parser, section, option, value, defaults + ) except Exception: e = sys.exc_info()[1] args = list(e.args) @@ -92,7 +92,7 @@ class NicerConfigParser(ConfigParser): ############################################################ -## Object types +# Object types ############################################################ @@ -109,33 +109,43 @@ class _ObjectType: def __repr__(self): return '<{} protocols={!r} prefixes={!r}>'.format( - self.name, self.egg_protocols, self.config_prefixes) + self.name, self.egg_protocols, self.config_prefixes + ) def invoke(self, context): assert context.protocol in _flatten(self.egg_protocols) - return fix_call(context.object, - context.global_conf, **context.local_conf) + return fix_call(context.object, context.global_conf, **context.local_conf) class _App(_ObjectType): name = 'application' - egg_protocols = ['paste.app_factory', 'paste.composite_factory', - 'paste.composit_factory'] - config_prefixes = [['app', 'application'], ['composite', 'composit'], - 'pipeline', 'filter-app'] + egg_protocols = [ + 'paste.app_factory', + 'paste.composite_factory', + 'paste.composit_factory', + ] + config_prefixes = [ + ['app', 'application'], + ['composite', 'composit'], + 'pipeline', + 'filter-app', + ] def invoke(self, context): - if context.protocol in ('paste.composit_factory', - 'paste.composite_factory'): - return fix_call(context.object, - context.loader, context.global_conf, - **context.local_conf) + if context.protocol in ('paste.composit_factory', 'paste.composite_factory'): + return fix_call( + context.object, + context.loader, + context.global_conf, + **context.local_conf, + ) elif context.protocol == 'paste.app_factory': return fix_call(context.object, context.global_conf, **context.local_conf) else: assert 0, "Protocol %r unknown" % context.protocol + APP = _App() @@ -146,18 +156,20 @@ class _Filter(_ObjectType): def invoke(self, context): if context.protocol == 'paste.filter_factory': - return fix_call(context.object, - context.global_conf, **context.local_conf) + return fix_call(context.object, context.global_conf, **context.local_conf) elif context.protocol == 'paste.filter_app_factory': + def filter_wrapper(wsgi_app): # This should be an object, so it has a nicer __repr__ - return fix_call(context.object, - wsgi_app, context.global_conf, - **context.local_conf) + return fix_call( + context.object, wsgi_app, context.global_conf, **context.local_conf + ) + return filter_wrapper else: assert 0, "Protocol %r unknown" % context.protocol + FILTER = _Filter() @@ -168,18 +180,20 @@ class _Server(_ObjectType): def invoke(self, context): if context.protocol == 'paste.server_factory': - return fix_call(context.object, - context.global_conf, **context.local_conf) + return fix_call(context.object, context.global_conf, **context.local_conf) elif context.protocol == 'paste.server_runner': + def server_wrapper(wsgi_app): # This should be an object, so it has a nicer __repr__ - return fix_call(context.object, - wsgi_app, context.global_conf, - **context.local_conf) + return fix_call( + context.object, wsgi_app, context.global_conf, **context.local_conf + ) + return server_wrapper else: assert 0, "Protocol %r unknown" % context.protocol + SERVER = _Server() @@ -196,6 +210,7 @@ class _PipeLine(_ObjectType): app = filter(app) return app + PIPELINE = _PipeLine() @@ -207,6 +222,7 @@ class _FilterApp(_ObjectType): filter = context.filter_context.create() return filter(next_app) + FILTER_APP = _FilterApp() @@ -222,13 +238,15 @@ class _FilterWith(_App): # filtering a filter def composed(app): return filter(filtered(app)) + return composed + FILTER_WITH = _FilterWith() ############################################################ -## Loaders +# Loaders ############################################################ @@ -245,24 +263,23 @@ def loadserver(uri, name=None, **kw): def appconfig(uri, name=None, relative_to=None, global_conf=None): - context = loadcontext(APP, uri, name=name, - relative_to=relative_to, - global_conf=global_conf) + context = loadcontext( + APP, uri, name=name, relative_to=relative_to, global_conf=global_conf + ) return context.config() + _loaders = {} -def loadobj(object_type, uri, name=None, relative_to=None, - global_conf=None): +def loadobj(object_type, uri, name=None, relative_to=None, global_conf=None): context = loadcontext( - object_type, uri, name=name, relative_to=relative_to, - global_conf=global_conf) + object_type, uri, name=name, relative_to=relative_to, global_conf=global_conf + ) return context.create() -def loadcontext(object_type, uri, name=None, relative_to=None, - global_conf=None): +def loadcontext(object_type, uri, name=None, relative_to=None, global_conf=None): if '#' in uri: if name is None: uri, name = uri.split('#', 1) @@ -277,16 +294,19 @@ def loadcontext(object_type, uri, name=None, relative_to=None, scheme = scheme.lower() if scheme not in _loaders: raise LookupError( - "URI scheme not known: %r (from %s)" - % (scheme, ', '.join(_loaders.keys()))) + "URI scheme not known: %r (from %s)" % (scheme, ', '.join(_loaders.keys())) + ) return _loaders[scheme]( object_type, - uri, path, name=name, relative_to=relative_to, - global_conf=global_conf) + uri, + path, + name=name, + relative_to=relative_to, + global_conf=global_conf, + ) -def _loadconfig(object_type, uri, path, name, relative_to, - global_conf): +def _loadconfig(object_type, uri, path, name, relative_to, global_conf): isabs = os.path.isabs(path) # De-Windowsify the paths: path = path.replace('\\', '/') @@ -294,7 +314,8 @@ def _loadconfig(object_type, uri, path, name, relative_to, if not relative_to: raise ValueError( "Cannot resolve relative uri %r; no relative_to keyword " - "argument given" % uri) + "argument given" % uri + ) relative_to = relative_to.replace('\\', '/') if relative_to.endswith('/'): path = relative_to + path @@ -308,55 +329,49 @@ def _loadconfig(object_type, uri, path, name, relative_to, loader.update_defaults(global_conf, overwrite=False) return loader.get_context(object_type, name, global_conf) + _loaders['config'] = _loadconfig -def _loadegg(object_type, uri, spec, name, relative_to, - global_conf): +def _loadegg(object_type, uri, spec, name, relative_to, global_conf): loader = EggLoader(spec) return loader.get_context(object_type, name, global_conf) + _loaders['egg'] = _loadegg -def _loadfunc(object_type, uri, spec, name, relative_to, - global_conf): +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 +# Loaders ############################################################ class _Loader: - def get_app(self, name=None, global_conf=None): - return self.app_context( - name=name, global_conf=global_conf).create() + return self.app_context(name=name, global_conf=global_conf).create() def get_filter(self, name=None, global_conf=None): - return self.filter_context( - name=name, global_conf=global_conf).create() + return self.filter_context(name=name, global_conf=global_conf).create() def get_server(self, name=None, global_conf=None): - return self.server_context( - name=name, global_conf=global_conf).create() + return self.server_context(name=name, global_conf=global_conf).create() def app_context(self, name=None, global_conf=None): - return self.get_context( - APP, name=name, global_conf=global_conf) + return self.get_context(APP, name=name, global_conf=global_conf) def filter_context(self, name=None, global_conf=None): - return self.get_context( - FILTER, name=name, global_conf=global_conf) + return self.get_context(FILTER, name=name, global_conf=global_conf) def server_context(self, name=None, global_conf=None): - return self.get_context( - SERVER, name=name, global_conf=global_conf) + return self.get_context(SERVER, name=name, global_conf=global_conf) _absolute_re = re.compile(r'^[a-zA-Z]+:') @@ -370,13 +385,12 @@ class _Loader: class ConfigLoader(_Loader): - def __init__(self, filename): self.filename = filename = filename.strip() defaults = { 'here': os.path.dirname(os.path.abspath(filename)), - '__file__': os.path.abspath(filename) - } + '__file__': os.path.abspath(filename), + } self.parser = NicerConfigParser(filename, defaults=defaults) self.parser.optionxform = str # Don't lower-case keys with open(filename) as f: @@ -390,11 +404,13 @@ class ConfigLoader(_Loader): def get_context(self, object_type, name=None, global_conf=None): if self.absolute_name(name): - return loadcontext(object_type, name, - relative_to=os.path.dirname(self.filename), - global_conf=global_conf) - section = self.find_config_section( - object_type, name=name) + return loadcontext( + object_type, + name, + relative_to=os.path.dirname(self.filename), + global_conf=global_conf, + ) + section = self.find_config_section(object_type, name=name) defaults = self.parser.defaults() _global_conf = defaults.copy() if global_conf is not None: @@ -406,8 +422,9 @@ class ConfigLoader(_Loader): for option in self.parser.options(section): if option.startswith('set '): name = option[4:].strip() - global_additions[name] = global_conf[name] = ( - self.parser.get(section, option)) + global_additions[name] = global_conf[name] = self.parser.get( + section, option + ) elif option.startswith('get '): name = option[4:].strip() get_from_globals[name] = self.parser.get(section, option) @@ -428,40 +445,51 @@ class ConfigLoader(_Loader): del local_conf['require'] if section.startswith('filter-app:'): context = self._filter_app_context( - object_type, section, name=name, - global_conf=global_conf, local_conf=local_conf, - global_additions=global_additions) + object_type, + section, + name=name, + global_conf=global_conf, + local_conf=local_conf, + global_additions=global_additions, + ) elif section.startswith('pipeline:'): context = self._pipeline_app_context( - object_type, section, name=name, - global_conf=global_conf, local_conf=local_conf, - global_additions=global_additions) + object_type, + section, + name=name, + global_conf=global_conf, + local_conf=local_conf, + global_additions=global_additions, + ) elif 'use' in local_conf: context = self._context_from_use( - object_type, local_conf, global_conf, global_additions, - section) + object_type, local_conf, global_conf, global_additions, section + ) else: context = self._context_from_explicit( - object_type, local_conf, global_conf, global_additions, - section) + object_type, local_conf, global_conf, global_additions, section + ) if filter_with is not None: filter_with_context = LoaderContext( obj=None, object_type=FILTER_WITH, protocol=None, - global_conf=global_conf, local_conf=local_conf, - loader=self) + global_conf=global_conf, + local_conf=local_conf, + loader=self, + ) filter_with_context.filter_context = self.filter_context( - name=filter_with, global_conf=global_conf) + name=filter_with, global_conf=global_conf + ) filter_with_context.next_context = context return filter_with_context return context - def _context_from_use(self, object_type, local_conf, global_conf, - global_additions, section): + def _context_from_use( + self, object_type, local_conf, global_conf, global_additions, section + ): use = local_conf.pop('use') - context = self.get_context( - object_type, name=use, global_conf=global_conf) + context = self.get_context(object_type, name=use, global_conf=global_conf) context.global_conf.update(global_additions) context.local_conf.update(local_conf) if '__file__' in global_conf: @@ -485,8 +513,9 @@ class ConfigLoader(_Loader): return context - def _context_from_explicit(self, object_type, local_conf, global_conf, - global_addition, section): + def _context_from_explicit( + self, object_type, local_conf, global_conf, global_addition, section + ): possible = [] for protocol_options in object_type.egg_protocols: for protocol in protocol_options: @@ -495,59 +524,59 @@ class ConfigLoader(_Loader): break if len(possible) > 1: raise LookupError( - "Multiple protocols given in section %r: %s" - % (section, possible)) + "Multiple protocols given in section %r: %s" % (section, possible) + ) if not possible: - raise LookupError( - "No loader given in section %r" % section) + raise LookupError("No loader given in section %r" % section) found_protocol, found_expr = possible[0] del local_conf[found_protocol] value = import_string(found_expr) context = LoaderContext( - value, object_type, found_protocol, - global_conf, local_conf, self) + value, object_type, found_protocol, global_conf, local_conf, self + ) return context - def _filter_app_context(self, object_type, section, name, - global_conf, local_conf, global_additions): + def _filter_app_context( + self, object_type, section, name, global_conf, local_conf, global_additions + ): if 'next' not in local_conf: raise LookupError( "The [%s] section in %s is missing a 'next' setting" - % (section, self.filename)) + % (section, self.filename) + ) next_name = local_conf.pop('next') - context = LoaderContext(None, FILTER_APP, None, global_conf, - local_conf, self) - context.next_context = self.get_context( - APP, next_name, global_conf) + context = LoaderContext(None, FILTER_APP, None, global_conf, local_conf, self) + context.next_context = self.get_context(APP, next_name, global_conf) if 'use' in local_conf: context.filter_context = self._context_from_use( - FILTER, local_conf, global_conf, global_additions, - section) + FILTER, local_conf, global_conf, global_additions, section + ) else: context.filter_context = self._context_from_explicit( - FILTER, local_conf, global_conf, global_additions, - section) + FILTER, local_conf, global_conf, global_additions, section + ) return context - def _pipeline_app_context(self, object_type, section, name, - global_conf, local_conf, global_additions): + def _pipeline_app_context( + self, object_type, section, name, global_conf, local_conf, global_additions + ): if 'pipeline' not in local_conf: raise LookupError( "The [%s] section in %s is missing a 'pipeline' setting" - % (section, self.filename)) + % (section, self.filename) + ) pipeline = local_conf.pop('pipeline').split() if local_conf: raise LookupError( "The [%s] pipeline section in %s has extra " "(disallowed) settings: %s" - % (section, self.filename, ', '.join(local_conf.keys()))) - context = LoaderContext(None, PIPELINE, None, global_conf, - local_conf, self) - context.app_context = self.get_context( - APP, pipeline[-1], global_conf) + % (section, self.filename, ', '.join(local_conf.keys())) + ) + context = LoaderContext(None, PIPELINE, None, global_conf, local_conf, self) + context.app_context = self.get_context(APP, pipeline[-1], global_conf) context.filter_contexts = [ - self.get_context(FILTER, name, global_conf) - for name in pipeline[:-1]] + self.get_context(FILTER, name, global_conf) for name in pipeline[:-1] + ] return context def find_config_section(self, object_type, name=None): @@ -562,24 +591,30 @@ class ConfigLoader(_Loader): possible = [] for name_options in object_type.config_prefixes: for name_prefix in name_options: - found = self._find_sections( - self.parser.sections(), name_prefix, name) + found = self._find_sections(self.parser.sections(), name_prefix, name) if found: possible.extend(found) break if not possible: raise LookupError( "No section %r (prefixed by %s) found in config %s" - % (name, - ' or '.join(map(repr, _flatten(object_type.config_prefixes))), - self.filename)) + % ( + name, + ' or '.join(map(repr, _flatten(object_type.config_prefixes))), + self.filename, + ) + ) if len(possible) > 1: raise LookupError( "Ambiguous section names %r for section %r (prefixed by %s) " "found in config %s" - % (possible, name, - ' or '.join(map(repr, _flatten(object_type.config_prefixes))), - self.filename)) + % ( + possible, + name, + ' or '.join(map(repr, _flatten(object_type.config_prefixes))), + self.filename, + ) + ) return possible[0] def _find_sections(self, sections, name_prefix, name): @@ -590,30 +625,31 @@ class ConfigLoader(_Loader): name = 'main' for section in sections: if section.startswith(name_prefix + ':'): - if section[len(name_prefix) + 1:].strip() == name: + if section[len(name_prefix) + 1 :].strip() == name: found.append(section) return found class EggLoader(_Loader): - def __init__(self, spec): self.spec = spec def get_context(self, object_type, name=None, global_conf=None): if self.absolute_name(name): - return loadcontext(object_type, name, - global_conf=global_conf) + return loadcontext(object_type, name, global_conf=global_conf) entry_point, protocol, ep_name = self.find_egg_entry_point( - object_type, name=name) + object_type, name=name + ) return LoaderContext( entry_point, object_type, protocol, - global_conf or {}, {}, + global_conf or {}, + {}, self, distribution=pkg_resources.get_distribution(self.spec), - entry_point_name=ep_name) + entry_point_name=ep_name, + ) def find_egg_entry_point(self, object_type, name=None): """ @@ -626,10 +662,7 @@ class EggLoader(_Loader): for protocol_options in object_type.egg_protocols: for protocol in protocol_options: pkg_resources.require(self.spec) - entry = pkg_resources.get_entry_info( - self.spec, - protocol, - name) + entry = pkg_resources.get_entry_info(self.spec, protocol, name) if entry is not None: possible.append((entry.load(), protocol, entry.name)) break @@ -639,30 +672,49 @@ class EggLoader(_Loader): raise LookupError( "Entry point %r not found in egg %r (dir: %s; protocols: %s; " "entry_points: %s)" - % (name, self.spec, - dist.location, - ', '.join(_flatten(object_type.egg_protocols)), - ', '.join(_flatten([ - list((pkg_resources.get_entry_info(self.spec, prot, name) or {}).keys()) - for prot in protocol_options] or '(no entry points)')))) + % ( + name, + self.spec, + dist.location, + ', '.join(_flatten(object_type.egg_protocols)), + ', '.join( + _flatten( + [ + list( + ( + pkg_resources.get_entry_info( + self.spec, prot, name + ) + or {} + ).keys() + ) + for prot in protocol_options + ] + or '(no entry points)' + ) + ), + ) + ) if len(possible) > 1: raise LookupError( "Ambiguous entry points for %r in egg %r (protocols: %s)" - % (name, self.spec, ', '.join(_flatten(protocol_options)))) + % (name, self.spec, ', '.join(_flatten(protocol_options))) + ) return possible[0] class FuncLoader(_Loader): - """ Loader that supports specifying functions inside modules, without + """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 - if not ':' in spec: + if ':' not in spec: raise LookupError("Configuration not in format module:function") def get_context(self, object_type, name=None, global_conf=None): @@ -670,22 +722,29 @@ class FuncLoader(_Loader): return LoaderContext( obj, object_type, - None, # determine protocol from section type + None, # determine protocol from section type global_conf or {}, {}, self, - ) + ) class LoaderContext: - - def __init__(self, obj, object_type, protocol, - global_conf, local_conf, loader, - distribution=None, entry_point_name=None): + def __init__( + self, + obj, + object_type, + protocol, + global_conf, + local_conf, + loader, + distribution=None, + entry_point_name=None, + ): self.object = obj self.object_type = object_type self.protocol = protocol - #assert protocol in _flatten(object_type.egg_protocols), ( + # assert protocol in _flatten(object_type.egg_protocols), ( # "Bad protocol %r; should be one of %s" # % (protocol, ', '.join(map(repr, _flatten(object_type.egg_protocols))))) self.global_conf = global_conf @@ -710,4 +769,5 @@ class AttrDict(dict): """ A dictionary that can be assigned to. """ + pass diff --git a/src/paste/deploy/paster_templates.py b/src/paste/deploy/paster_templates.py index edfa97a..063b536 100644 --- a/src/paste/deploy/paster_templates.py +++ b/src/paste/deploy/paster_templates.py @@ -20,15 +20,23 @@ class PasteDeploy(Template): os.path.join(output_dir, 'setup.py'), 'Extra requirements', '%r,\n' % prereq, - indent=True) + indent=True, + ) command.insert_into_file( os.path.join(output_dir, 'setup.py'), 'Entry points', - (' [paste.app_factory]\n' - ' main = %(package)s.wsgiapp:make_app\n') % vars, - indent=False) + ( + ' [paste.app_factory]\n' + ' main = %(package)s.wsgiapp:make_app\n' + ) + % vars, + indent=False, + ) if command.verbose: print('*' * 72) - print('* Run "paster serve docs/devel_config.ini" to run the sample application') + print( + '* Run "paster serve docs/devel_config.ini" to run the sample' + ' application' + ) print('* on http://localhost:8080') print('*' * 72) diff --git a/src/paste/deploy/util.py b/src/paste/deploy/util.py index d30466a..6bd6132 100644 --- a/src/paste/deploy/util.py +++ b/src/paste/deploy/util.py @@ -20,9 +20,11 @@ def fix_type_error(exc_info, callable, varargs, kwargs): """ if exc_info is None: exc_info = sys.exc_info() - if (exc_info[0] != TypeError + if ( + exc_info[0] != TypeError or str(exc_info[1]).find('arguments') == -1 - or getattr(exc_info[1], '_type_error_fixed', False)): + or getattr(exc_info[1], '_type_error_fixed', False) + ): return exc_info exc_info[1]._type_error_fixed = True argspec = inspect.formatargspec(*inspect.getargspec(callable)) |