def chdir(method):
    """Decorator executing method in directory 'dir'.
    """
    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)
Decorator executing method in directory 'dir'.