summaryrefslogtreecommitdiffstats
path: root/openstack/common/context.py
diff options
context:
space:
mode:
Diffstat (limited to 'openstack/common/context.py')
-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