code: def chdir(method):
      
      def wrapper(self, dir, *args, **kw):
          dirstack = ChdirStack()
          dirstack.push(dir)
          try:
              return method(self, dir, *args, **kw)
          finally:
              dirstack.pop()
  
      return functools.wraps(method)(wrapper)
docs: Decorator executing method in directory 'dir'.