def validate_permissions(self):
        mode = self.kwargs.get('mode', 'r')
        exists = os.access(self.arg, os.F_OK)
        if not exists:
            if 'r' in mode and '+' not in mode:
                raise errors.CliValueError(
                    'File does not exist: {0!r}'.format(self.arg))
            else:
                dirname = os.path.dirname(self.arg)
                if os.access(dirname, os.W_OK):
                    return
                if not os.path.exists(dirname):
                    raise errors.CliValueError(
                        'Directory does not exist: {0!r}'.format(self.arg))
        elif os.access(self.arg, os.W_OK):
            return
        raise errors.CliValueError(
            'Permission denied: {0!r}'.format(self.arg))
dataset/ETHPy150Open epsy/clize/clize/converters.py/_FileOpener.validate_permissions/original