Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
class Redirect(object):
def __init__(self, location, headers=None):
headers = list(headers.items()) if headers else []
headers.append(("Location", quote(location.encode("utf8"))))
self.response = Response(HTTPStatus.FOUND, headers, None)
def get_response(self, method, request_headers):
return self.response
class NotARegularFileError(Exception):
pass
class MissingFileError(NotARegularFileError):
pass
class IsDirectoryError(MissingFileError):
pass
class FileEntry(object):
def __init__(self, path, stat_cache=None):
stat_function = os.stat if stat_cache is None else stat_cache.__getitem__
self.stat = self.stat_regular_file(path, stat_function)
self.path = path
@staticmethod
def stat_regular_file(path, stat_function):
"""