local.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:S4 作者: MichaelAquilina 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号