summaryrefslogtreecommitdiff
path: root/paste
diff options
context:
space:
mode:
Diffstat (limited to 'paste')
-rw-r--r--paste/configmiddleware.py16
-rw-r--r--paste/docsupport/extract.py17
-rw-r--r--paste/docsupport/metadata.py9
-rw-r--r--paste/pyconfig.py23
4 files changed, 60 insertions, 5 deletions
diff --git a/paste/configmiddleware.py b/paste/configmiddleware.py
index a08ee0d..ddbe4ec 100644
--- a/paste/configmiddleware.py
+++ b/paste/configmiddleware.py
@@ -1,9 +1,25 @@
from paste import CONFIG
from paste import wsgilib
+from paste.docsupport import metadata
+
+__all__ = ['ConfigMiddleware']
class ConfigMiddleware(object):
+ """
+ A WSGI middleware that adds a ``paste.config`` key to the request
+ environment, as well as registering the configuration temporarily
+ (for the length of the request) with ``paste.CONFIG``.
+ """
+
+ _wsgi_add1 = metadata.WSGIKey('paste.config',
+ interface='paste.pyconfig.Config')
+
def __init__(self, application, config):
+ """
+ This delegates all requests to `application`, adding a *copy*
+ of the configuration `config`.
+ """
self.application = application
self.config = config
diff --git a/paste/docsupport/extract.py b/paste/docsupport/extract.py
index effd509..e0836df 100644
--- a/paste/docsupport/extract.py
+++ b/paste/docsupport/extract.py
@@ -115,10 +115,12 @@ class MethodExtractor(Extractor):
def extract(self):
if not self.obj.__doc__:
return
- sig = self.make_sig(self.obj)
+ sig = self.make_sig()
self.context.writekey('def %s(%s)' % (self.obj.func_name, sig),
monospace=False)
self.context.writedoc(self.obj.__doc__)
+ if self.get_attr('proxy'):
+ self.context.writedoc(self.get_attr('proxy').__doc__)
if getattr(self.obj, 'returns', None):
returns = self.obj.returns
if isinstance(returns, str):
@@ -126,8 +128,10 @@ class MethodExtractor(Extractor):
self.context.extract(self.obj.returns)
self.context.endkey()
- def make_sig(self, func):
- args, varargs, varkw, defaults = inspect.getargspec(func)
+ def make_sig(self):
+ proxy = self.get_attr('proxy')
+ args, varargs, varkw, defaults = inspect.getargspec(
+ proxy or self.obj)
sig = []
args.reverse()
for arg in args:
@@ -143,6 +147,13 @@ class MethodExtractor(Extractor):
sig.append('**%s' % varkw)
return ', '.join(sig)
+ def get_attr(self, attr):
+ if not getattr(self.obj, attr, None):
+ return None
+ value = getattr(self.obj, attr)
+ if isinstance(value, str):
+ value = self.obj.func_globals[value]
+ return value
############################################################
## Context
diff --git a/paste/docsupport/metadata.py b/paste/docsupport/metadata.py
index aa8879b..2677a0a 100644
--- a/paste/docsupport/metadata.py
+++ b/paste/docsupport/metadata.py
@@ -1,8 +1,12 @@
+# @@: There are too many imports here; this shouldn't have much
+# overhead except during extraction, but everything in this
+# module has to be imported regardless.
import sys
import copy
import types
import inspect
from itertools import count
+from paste.util import import_string
from paste.util.classinit import ClassInitMeta
from paste.util.classinstance import classinstancemethod
@@ -30,7 +34,10 @@ class DocItem(object):
stack = None
def get_object(self, name):
- return getattr(sys.modules[self.call_module_name], name)
+ if '.' in name:
+ return import_string.eval_import(name)
+ else:
+ return getattr(sys.modules[self.call_module_name], name)
def writeto(self, context):
raise NotImplementedError
diff --git a/paste/pyconfig.py b/paste/pyconfig.py
index d0192c6..96a32ab 100644
--- a/paste/pyconfig.py
+++ b/paste/pyconfig.py
@@ -13,6 +13,9 @@ values (but will not delete previous values). You can use attribute
or dictionary access to get values.
"""
+__all__ = ['Config', 'setup_config', 'parse_commandline',
+ 'DispatchingConfig', 'make_bool', 'make_list']
+
import types
import os
import sys
@@ -42,7 +45,11 @@ def local_dict():
config_local.wsgi_dict = result = {}
return result
-class Config(UserDict.DictMixin):
+class Config(UserDict.DictMixin, object):
+
+ """
+ A dictionary-like object that represents configuration.
+ """
def __init__(self, with_default=False):
self.namespaces = []
@@ -131,16 +138,29 @@ class Config(UserDict.DictMixin):
return include
def load(self, filename, default=False):
+ """
+ Load the `filename`, which is a Python-syntax configuration
+ file. If default is a positive value, do not put the values
+ at the top of the configuration stack (used to insert default
+ values that may already be overrided by a loaded
+ configuration).
+ """
namespace = self.read_file(filename)
self.load_dict(namespace, default)
def load_dict(self, d, default=False):
+ """
+ Like `load`, but loads a dictionary (doesn't do any parsing).
+ """
if default:
self.namespaces.insert(default, d)
else:
self.namespaces.insert(0, d)
def load_commandline(self, *args, **kw):
+ """
+ Loads a command line.
+ """
if 'default' in kw:
default = kw['default']
del kw['default']
@@ -149,6 +169,7 @@ class Config(UserDict.DictMixin):
options, args = parse_commandline(*args, **kw)
self.load_dict(options, default=default)
return args
+ load_commandline.proxy = 'parse_commandline'
def update_sys_path(self):
update_sys_path(self.get('sys_path'), self.get('verbose'))