ulinecache.py 文件源码

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

项目:Repobot 作者: Desgard 项目源码 文件源码
def getlines(filename, module_globals=None):
        """Get the lines (as unicode) for a file from the cache.
        Update the cache if it doesn't contain an entry for this file already."""
        filename = py3compat.cast_bytes(filename, sys.getfilesystemencoding())
        lines = linecache.getlines(filename, module_globals=module_globals)

        # The bits we cache ourselves can be unicode.
        if (not lines) or isinstance(lines[0], py3compat.unicode_type):
            return lines

        readline = openpy._list_readline(lines)
        try:
            encoding, _ = openpy.detect_encoding(readline)
        except SyntaxError:
            encoding = 'ascii'
        return [l.decode(encoding, 'replace') for l in lines]

    # This is a straight copy of linecache.getline
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号