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)
评论列表
文章目录