def _load_index(self):
index_path = self.index_path()
if not os.path.exists(index_path):
return {}
content_type = magic.from_file(index_path, mime=True)
if content_type == 'text/plain':
logger.debug('Detected plaintext encoding for reading index')
method = open
elif content_type in ('application/gzip', 'application/x-gzip'):
logger.debug('Detected gzip encoding for reading index')
method = gzip.open
else:
raise ValueError('Index is of unknown type', content_type)
with method(index_path, 'rt') as fp:
data = json.load(fp)
return data
评论列表
文章目录