filesys.py 文件源码

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

项目:srctools 作者: TeamSpen210 项目源码 文件源码
def open_str(self, name: str, encoding='utf8'):
        """Return a string buffer for a 'file'. 

        This performs universal newlines conversion.
        The encoding argument is ignored for files which are
        originally text.
        """
        # We don't need this, but it should match other filesystems.
        self._check_open()

        try:
            filename, data = self._mapping[self._clean_path(name)]
        except KeyError:
            raise FileNotFoundError(name)
        if isinstance(data, bytes):
            # Decode on the fly, with universal newlines.
            return io.TextIOWrapper(
                io.BytesIO(data),
                encoding=encoding,
            )
        else:
            # None = universal newlines mode directly.
            # No encoding is needed obviously.
            return io.StringIO(data, newline=None)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号