summaryrefslogtreecommitdiffstats
path: root/Lib/gzip.py
diff options
context:
space:
mode:
authorBerker Peksag <berker.peksag@gmail.com>2016-10-02 10:47:58 (GMT)
committerBerker Peksag <berker.peksag@gmail.com>2016-10-02 10:47:58 (GMT)
commit03020cfa97b6c2c80f50fb2d07025aff49c3513c (patch)
treee5198c265c47cddc2e9dcfeeb770cd98bc0f1109 /Lib/gzip.py
parent8e9045d0d8b612e5f8231e5c854625ff78a4b110 (diff)
downloadcpython-03020cfa97b6c2c80f50fb2d07025aff49c3513c.zip
cpython-03020cfa97b6c2c80f50fb2d07025aff49c3513c.tar.gz
cpython-03020cfa97b6c2c80f50fb2d07025aff49c3513c.tar.bz2
Issue #28227: gzip now supports pathlib
Patch by Ethan Furman.
Diffstat (limited to 'Lib/gzip.py')
-rw-r--r--Lib/gzip.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/Lib/gzip.py b/Lib/gzip.py
index ddf7668..76ab497 100644
--- a/Lib/gzip.py
+++ b/Lib/gzip.py
@@ -49,7 +49,7 @@ def open(filename, mode="rb", compresslevel=9,
raise ValueError("Argument 'newline' not supported in binary mode")
gz_mode = mode.replace("t", "")
- if isinstance(filename, (str, bytes)):
+ if isinstance(filename, (str, bytes, os.PathLike)):
binary_file = GzipFile(filename, gz_mode, compresslevel)
elif hasattr(filename, "read") or hasattr(filename, "write"):
binary_file = GzipFile(None, gz_mode, compresslevel, filename)
@@ -165,6 +165,8 @@ class GzipFile(_compression.BaseStream):
filename = getattr(fileobj, 'name', '')
if not isinstance(filename, (str, bytes)):
filename = ''
+ else:
+ filename = os.fspath(filename)
if mode is None:
mode = getattr(fileobj, 'mode', 'rb')