mercurial/extensions.py
changeset 34014 47e52f079a57
parent 33837 0646608368a9
child 34048 0e0ac8f09048
--- a/mercurial/extensions.py	Tue Aug 29 18:20:50 2017 -0700
+++ b/mercurial/extensions.py	Mon Aug 21 16:46:05 2017 -0700
@@ -399,6 +399,21 @@
         raise AttributeError(r"type '%s' has no property '%s'" % (
             cls, propname))
 
+class wrappedfunction(object):
+    '''context manager for temporarily wrapping a function'''
+
+    def __init__(self, container, funcname, wrapper):
+        assert callable(wrapper)
+        self._container = container
+        self._funcname = funcname
+        self._wrapper = wrapper
+
+    def __enter__(self):
+        wrapfunction(self._container, self._funcname, self._wrapper)
+
+    def __exit__(self, exctype, excvalue, traceback):
+        unwrapfunction(self._container, self._funcname, self._wrapper)
+
 def wrapfunction(container, funcname, wrapper):
     '''Wrap the function named funcname in container