def metadata(self, filename): """ Fetches all available metadata for a given file """ meta = self.get_metadata(filename) # Fixes backend mime misdetection meta['mime'] = meta.get('mime') or files.mime(filename, self.DEFAULT_MIME) return meta
def get_metadata(self, filename): """Fetches all available metadata""" dest = self.path(filename) with open(dest, 'rb', buffering=0) as f: checksum = 'sha1:{0}'.format(sha1(f)) return { 'checksum': checksum, 'size': os.path.getsize(dest), 'mime': files.mime(filename), 'modified': datetime.fromtimestamp(os.path.getmtime(dest)), }
def test_mime_default_to_custom(): default = 'application/octet-stream' assert files.mime('test', default=default) == default
def test_mime_default_to_none(): assert files.mime('test') is None assert files.mime('test', default=None) is None
def test_mime_known_type(): assert files.mime('test.txt') == 'text/plain' assert files.mime('test.csv') == 'text/csv'