def METHOD_NAME(method, mode):
    """Open path with context or close stream at the end."""
    def decorator(path_or_stream):
        """Open the path if needed."""
        if isinstance(path_or_stream, (str, Path)):
            return method(Path(path_or_stream).open(mode))
        return method(path_or_stream)
    return decorator