summaryrefslogtreecommitdiffstats
path: root/openstack/common/exception.py
diff options
context:
space:
mode:
Diffstat (limited to 'openstack/common/exception.py')
-rw-r--r--openstack/common/exception.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/openstack/common/exception.py b/openstack/common/exception.py
index ba32da5..e8ea110 100644
--- a/openstack/common/exception.py
+++ b/openstack/common/exception.py
@@ -19,6 +19,7 @@
Exceptions common to OpenStack projects
"""
+import itertools
import logging
@@ -145,3 +146,20 @@ class MalformedRequestBody(OpenstackException):
class InvalidContentType(OpenstackException):
message = "Invalid content type %(content_type)s"
+
+
+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.
+ """
+
+ # import here to avoid circularity:
+ from openstack.common import context
+
+ for arg in itertools.chain(kwargs.values(), args):
+ if isinstance(arg, context.RequestContext):
+ return arg
+
+ return None