mercurial/demandimport.py
changeset 25327 2e7804110b14
parent 23643 2205d00b6d2b
child 25673 fa1f04529775
--- a/mercurial/demandimport.py	Thu May 28 14:14:11 2015 -0400
+++ b/mercurial/demandimport.py	Thu May 28 16:11:26 2015 -0400
@@ -25,6 +25,8 @@
 '''
 
 import __builtin__, os, sys
+from contextlib import contextmanager
+
 _origimport = __import__
 
 nothing = object()
@@ -179,3 +181,16 @@
 def disable():
     "disable global demand-loading of modules"
     __builtin__.__import__ = _origimport
+
+@contextmanager
+def deactivated():
+    "context manager for disabling demandimport in 'with' blocks"
+    demandenabled = isenabled()
+    if demandenabled:
+        disable()
+
+    try:
+        yield
+    finally:
+        if demandenabled:
+            enable()