diff options
| author | Andrew Bogott <abogott@wikimedia.org> | 2012-07-02 16:28:05 -0500 |
|---|---|---|
| committer | Andrew Bogott <abogott@wikimedia.org> | 2012-07-03 17:38:37 -0500 |
| commit | d9e28ba02c30255511a56a59e93da283c172dffe (patch) | |
| tree | b509f07af5400eea1993b19bee0a492265f29674 /openstack/common/context.py | |
| parent | 506486550480fb222a92447e1e8baca855d126aa (diff) | |
| download | oslo-d9e28ba02c30255511a56a59e93da283c172dffe.tar.gz oslo-d9e28ba02c30255511a56a59e93da283c172dffe.tar.xz oslo-d9e28ba02c30255511a56a59e93da283c172dffe.zip | |
Move get_context_from_function_and_args() to context.py
Word on the street is that exception.py may soon be deprecated,
and context.py is a better place anyway.
(Also removed an import of utils.py because /it/ imports exception.py.)
Change-Id: I856fc6f4558cc01ddca350ee4cfd4684db47475b
Diffstat (limited to 'openstack/common/context.py')
| -rw-r--r-- | openstack/common/context.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/openstack/common/context.py b/openstack/common/context.py index 35724e9..dd7dd04 100644 --- a/openstack/common/context.py +++ b/openstack/common/context.py @@ -22,6 +22,7 @@ Projects should subclass this class if they wish to enhance the request context or provide additional information in their specific WSGI pipeline. """ +import itertools import uuid @@ -64,3 +65,17 @@ def get_admin_context(show_deleted="no"): is_admin=True, show_deleted=show_deleted) return context + + +def get_context_from_function_and_args(function, args, kwargs): + """Find an arg of type RequestContext and return it. + + This is useful in a couple of decorators where we don't + know much about the function we're wrapping. + """ + + for arg in itertools.chain(kwargs.values(), args): + if isinstance(arg, RequestContext): + return arg + + return None |
