encoding = io.text_encoding(encoding)
return io.open(self, mode, buffering, encoding, errors, newline)
+ def read_text(self, encoding=None, errors=None, newline=None):
+ """
+ Open the file in text mode, read it, and close the file.
+ """
+ # Call io.text_encoding() here to ensure any warning is raised at an
+ # appropriate stack level.
+ encoding = io.text_encoding(encoding)
+ return _abc.PathBase.read_text(self, encoding, errors, newline)
+
+ def write_text(self, data, encoding=None, errors=None, newline=None):
+ """
+ Open the file in text mode, write to it, and close the file.
+ """
+ # Call io.text_encoding() here to ensure any warning is raised at an
+ # appropriate stack level.
+ encoding = io.text_encoding(encoding)
+ return _abc.PathBase.write_text(self, data, encoding, errors, newline)
+
def iterdir(self):
"""Yield path objects of the directory contents.
import functools
-import io
import ntpath
import posixpath
import sys
"""
Open the file in text mode, read it, and close the file.
"""
- encoding = io.text_encoding(encoding)
with self.open(mode='r', encoding=encoding, errors=errors, newline=newline) as f:
return f.read()
if not isinstance(data, str):
raise TypeError('data must be str, not %s' %
data.__class__.__name__)
- encoding = io.text_encoding(encoding)
with self.open(mode='w', encoding=encoding, errors=errors, newline=newline) as f:
return f.write(data)