diff options
author | Andrew Bogott <abogott@wikimedia.org> | 2012-07-02 16:28:05 -0500 |
---|---|---|
committer | Andrew Bogott <abogott@wikimedia.org> | 2012-07-03 17:38:37 -0500 |
commit | d9e28ba02c30255511a56a59e93da283c172dffe (patch) | |
tree | b509f07af5400eea1993b19bee0a492265f29674 /openstack | |
parent | 506486550480fb222a92447e1e8baca855d126aa (diff) | |
download | oslo-d9e28ba02c30255511a56a59e93da283c172dffe.tar.gz oslo-d9e28ba02c30255511a56a59e93da283c172dffe.tar.xz oslo-d9e28ba02c30255511a56a59e93da283c172dffe.zip |
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
Diffstat (limited to 'openstack')
-rw-r--r-- | openstack/common/context.py | 15 | ||||
-rw-r--r-- | openstack/common/exception.py | 17 | ||||
-rw-r--r-- | openstack/common/notifier/api.py | 7 |
3 files changed, 18 insertions, 21 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 diff --git a/openstack/common/exception.py b/openstack/common/exception.py index e8ea110..e5da94b 100644 --- a/openstack/common/exception.py +++ b/openstack/common/exception.py @@ -146,20 +146,3 @@ 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 diff --git a/openstack/common/notifier/api.py b/openstack/common/notifier/api.py index 6a46cd2..45af4ed 100644 --- a/openstack/common/notifier/api.py +++ b/openstack/common/notifier/api.py @@ -17,12 +17,11 @@ import inspect import uuid from openstack.common import cfg -from openstack.common import exception +from openstack.common import context from openstack.common import importutils from openstack.common import jsonutils from openstack.common import log as logging from openstack.common import timeutils -from openstack.common import utils LOG = logging.getLogger(__name__) @@ -72,8 +71,8 @@ def notify_decorator(name, fn): for key in kwarg: body['kwarg'][key] = kwarg[key] - context = exception.get_context_from_function_and_args(fn, args, kwarg) - notify(context, + ctxt = context.get_context_from_function_and_args(fn, args, kwarg) + notify(ctxt, CONF.default_publisher_id, name, CONF.default_notification_level, |