How to use the whitenoise.responders.IsDirectoryError function in whitenoise

To help you get started, we’ve selected a few whitenoise examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github evansd / whitenoise / whitenoise / responders.py View on Github external
"""
        Wrap `stat_function` to raise appropriate errors if `path` is not a
        regular file
        """
        try:
            stat_result = stat_function(path)
        except KeyError:
            raise MissingFileError(path)
        except OSError as e:
            if e.errno in (errno.ENOENT, errno.ENAMETOOLONG):
                raise MissingFileError(path)
            else:
                raise
        if not stat.S_ISREG(stat_result.st_mode):
            if stat.S_ISDIR(stat_result.st_mode):
                raise IsDirectoryError(u"Path is a directory: {0}".format(path))
            else:
                raise NotARegularFileError(u"Not a regular file: {0}".format(path))
        return stat_result
github evansd / whitenoise / whitenoise / base.py View on Github external
def find_file_at_path_with_indexes(self, path, url):
        if url.endswith("/"):
            path = os.path.join(path, self.index_file)
            return self.get_static_file(path, url)
        elif url.endswith("/" + self.index_file):
            if os.path.isfile(path):
                return self.redirect(url, url[: -len(self.index_file)])
        else:
            try:
                return self.get_static_file(path, url)
            except IsDirectoryError:
                if os.path.isfile(os.path.join(path, self.index_file)):
                    return self.redirect(url, url + "/")
        raise MissingFileError(path)