mercurial/extensions.py
changeset 34014 47e52f079a57
parent 33837 0646608368a9
child 34048 0e0ac8f09048
equal deleted inserted replaced
34013:da07367d683b 34014:47e52f079a57
   397 
   397 
   398     if currcls is object:
   398     if currcls is object:
   399         raise AttributeError(r"type '%s' has no property '%s'" % (
   399         raise AttributeError(r"type '%s' has no property '%s'" % (
   400             cls, propname))
   400             cls, propname))
   401 
   401 
       
   402 class wrappedfunction(object):
       
   403     '''context manager for temporarily wrapping a function'''
       
   404 
       
   405     def __init__(self, container, funcname, wrapper):
       
   406         assert callable(wrapper)
       
   407         self._container = container
       
   408         self._funcname = funcname
       
   409         self._wrapper = wrapper
       
   410 
       
   411     def __enter__(self):
       
   412         wrapfunction(self._container, self._funcname, self._wrapper)
       
   413 
       
   414     def __exit__(self, exctype, excvalue, traceback):
       
   415         unwrapfunction(self._container, self._funcname, self._wrapper)
       
   416 
   402 def wrapfunction(container, funcname, wrapper):
   417 def wrapfunction(container, funcname, wrapper):
   403     '''Wrap the function named funcname in container
   418     '''Wrap the function named funcname in container
   404 
   419 
   405     Replace the funcname member in the given container with the specified
   420     Replace the funcname member in the given container with the specified
   406     wrapper. The container is typically a module, class, or instance.
   421     wrapper. The container is typically a module, class, or instance.