diff options
| author | Jenkins <jenkins@review.openstack.org> | 2012-06-26 18:59:20 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2012-06-26 18:59:20 +0000 |
| commit | 71cddc514ac194e2332817673ef76c099dc158cc (patch) | |
| tree | c231d2029ec471c8200c8c5ca3eba81ea888922c /openstack/common/exception.py | |
| parent | 5a93e1d790422ddf21c223ec77b0355e6b790021 (diff) | |
| parent | 16916b6129f075e54c1ead915d5131f6d34218ed (diff) | |
| download | oslo-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.py | 18 |
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 |
