summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Bogott <abogott@wikimedia.org>2012-07-02 16:28:05 -0500
committerAndrew Bogott <abogott@wikimedia.org>2012-07-03 17:38:37 -0500
commit74fe28304144d81e3bc220155a2d5f51fa480c73 (patch)
tree6d053b7e252cc96a9c1dd8eb3fa3095916aef58f
parent3ae1660b51324cea51aeec63bb58741946d87ba3 (diff)
downloadoslo-context-74fe28304144d81e3bc220155a2d5f51fa480c73.tar.gz
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
-rw-r--r--openstack/common/context.py15
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