summaryrefslogtreecommitdiffstats
path: root/openstack/common/exception.py
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2012-06-26 18:59:20 +0000
committerGerrit Code Review <review@openstack.org>2012-06-26 18:59:20 +0000
commit71cddc514ac194e2332817673ef76c099dc158cc (patch)
treec231d2029ec471c8200c8c5ca3eba81ea888922c /openstack/common/exception.py
parent5a93e1d790422ddf21c223ec77b0355e6b790021 (diff)
parent16916b6129f075e54c1ead915d5131f6d34218ed (diff)
downloadoslo-71cddc514ac194e2332817673ef76c099dc158cc.tar.gz
oslo-71cddc514ac194e2332817673ef76c099dc158cc.tar.xz
oslo-71cddc514ac194e2332817673ef76c099dc158cc.zip
Merge "Add common logging and notification."
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