Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""
Build a file model from database record.
"""
model = base_model(path)
model["type"] = "file"
if self.fs.isfile(path):
model["last_modified"] = model["created"] = self.fs.lstat(path)["ST_MTIME"]
else:
model["last_modified"] = model["created"] = DUMMY_CREATED_DATE
if content:
try:
# Get updated format from fs.read()
content, format_ = self.fs.read(path, format)
except NoSuchFile as e:
self.no_such_entity(e.path)
except GenericFSError as e:
self.do_error(str(e), 500)
model["format"] = format_
model["content"] = content
model["mimetype"] = mimetypes.guess_type(path)[0] or "text/plain"
return model
def lstat(self, path):
raise NotImplementedError(
"Should be implemented by the file system abstraction"
)
def write(self, path, content, format):
raise NotImplementedError(
"Should be implemented by the file system abstraction"
)
class GenericFSError(Exception):
pass
class NoSuchFile(GenericFSError):
def __init__(self, path, *args, **kwargs):
self.path = path
self.message = "No such file or directory: {}".format(path)
super(NoSuchFile, self).__init__(self.message, *args, **kwargs)