Created
September 23, 2010 06:29
-
-
Save kosmikko/593224 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def run_in_namespace(namespace): | |
| """ | |
| Decorator for executing a function in a given namespace, then return back to the | |
| current namescape. | |
| """ | |
| def decorator(function): | |
| def wrapper(*args, **kwargs): | |
| current_namespace = namespace_manager.get_namespace() | |
| try: | |
| current_namespace = namespace_manager.get_namespace() | |
| namespace_manager.set_namespace(namespace) | |
| return function(*args, **kwargs) | |
| finally: | |
| namespace_manager.set_namespace(current_namespace) | |
| return wrapper | |
| return decorator |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment