diff options
author | Jan Cholasta <jcholast@redhat.com> | 2016-03-02 11:00:23 +0100 |
---|---|---|
committer | Martin Basti <mbasti@redhat.com> | 2016-03-03 10:06:18 +0100 |
commit | e5520dc3479f2b1fad947dfd3d52426aef546a37 (patch) | |
tree | 4c496cd19ac8f79c54d6f7c686a52252c11f53e5 /ipalib/request.py | |
parent | 6851e560dd1c9f4df98fd6b9d3063cd7dcc3bafc (diff) | |
download | freeipa-e5520dc3479f2b1fad947dfd3d52426aef546a37.tar.gz freeipa-e5520dc3479f2b1fad947dfd3d52426aef546a37.tar.xz freeipa-e5520dc3479f2b1fad947dfd3d52426aef546a37.zip |
ipalib: provide per-call command context
Add context which is valid for the duration of command call. The context
is accessible using the `context` attribute of Command and Object plugins.
Reviewed-By: Martin Basti <mbasti@redhat.com>
Diffstat (limited to 'ipalib/request.py')
-rw-r--r-- | ipalib/request.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/ipalib/request.py b/ipalib/request.py index 9484be58f..d851ba84d 100644 --- a/ipalib/request.py +++ b/ipalib/request.py @@ -22,6 +22,7 @@ Per-request thread-local data. """ +import contextlib import threading from ipalib.base import ReadOnly, lock @@ -32,6 +33,26 @@ from ipalib.constants import CALLABLE_ERROR context = threading.local() +class _FrameContext(object): + pass + + +@contextlib.contextmanager +def context_frame(): + try: + frame_back = context.current_frame + except AttributeError: + pass + context.current_frame = _FrameContext() + try: + yield + finally: + try: + context.current_frame = frame_back + except UnboundLocalError: + del context.current_frame + + class Connection(ReadOnly): """ Base class for connection objects stored on `request.context`. |