summaryrefslogtreecommitdiffstats
path: root/Lib/pathlib.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/pathlib.py')
-rw-r--r--Lib/pathlib.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/Lib/pathlib.py b/Lib/pathlib.py
index 531a699..5c9284b 100644
--- a/Lib/pathlib.py
+++ b/Lib/pathlib.py
@@ -1241,6 +1241,8 @@ class Path(PurePath):
Open the file pointed by this path and return a file object, as
the built-in open() function does.
"""
+ if "b" not in mode:
+ encoding = io.text_encoding(encoding)
return io.open(self, mode, buffering, encoding, errors, newline,
opener=self._opener)
@@ -1255,6 +1257,7 @@ class Path(PurePath):
"""
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) as f:
return f.read()
@@ -1274,6 +1277,7 @@ class Path(PurePath):
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)