Skip to content

Commit

Permalink
Work around missing os.fspath
Browse files Browse the repository at this point in the history
Python 3.5 doesn’t know this method. Fortunately it’s simple enough to
implement.
  • Loading branch information
davidfoerster committed Oct 27, 2019
1 parent ba3d24d commit 4a90a06
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/aptsources_cleanup/util/zipfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@
__all__ = _zipfile.__all__


try:
from os import fspath

except ImportError:
def fspath(path, *, _str_types=(str, bytes)):
if isinstance(path, _str_types):
return path

path = path.__fspath__()
if not isinstance(path, _str_types):
raise TypeError(str(type(path)))
return path


class ZipFile(_zipfile.ZipFile):
"""Extends zipfile.ZipFile with in-archive resolution of symbolic links"""

Expand All @@ -27,7 +41,7 @@ def getinfo(self, name, pwd=None, *, follow_symlinks=False,
return self._resolve_path(name, pwd, fail_missing)
if isinstance(name, ZipInfo):
return name
name = os.fspath(name)
name = fspath(name)
return self._check_missing(self.NameToInfo.get(name), name, fail_missing)


Expand Down Expand Up @@ -59,7 +73,7 @@ def _resolve_path(self, path, pwd, fail_missing):
if isinstance(path, ZipInfo):
path = path.filename
else:
path = os.fspath(path)
path = fspath(path)

inspected = []
uninspected = path.split(os.sep)
Expand Down

0 comments on commit 4a90a06

Please sign in to comment.