assert list(root.glob("**/*.txt")) == list(root.rglob("*.txt"))
+ @pass_alpharep
+ def test_glob_dirs(self, alpharep):
+ root = zipfile.Path(alpharep)
+ assert list(root.glob('b')) == [zipfile.Path(alpharep, "b/")]
+ assert list(root.glob('b*')) == [zipfile.Path(alpharep, "b/")]
+
+ @pass_alpharep
+ def test_glob_subdir(self, alpharep):
+ root = zipfile.Path(alpharep)
+ assert list(root.glob('g/h')) == [zipfile.Path(alpharep, "g/h/")]
+ assert list(root.glob('g*/h*')) == [zipfile.Path(alpharep, "g/h/")]
+
@pass_alpharep
def test_glob_subdirs(self, alpharep):
root = zipfile.Path(alpharep)
'two-slash.txt',
'parent.txt',
]
+
+ @pass_alpharep
+ def test_interface(self, alpharep):
+ from importlib.resources.abc import Traversable
+
+ zf = zipfile.Path(alpharep)
+ assert isinstance(zf, Traversable)
class Path:
"""
- A pathlib-compatible interface for zip files.
+ A :class:`importlib.resources.abc.Traversable` interface for zip files.
+
+ Implements many of the features users enjoy from
+ :class:`pathlib.Path`.
Consider a zip file with this structure::
def translate(pattern):
+ return match_dirs(translate_core(pattern))
+
+
+def match_dirs(pattern):
+ """
+ Ensure that zipfile.Path directory names are matched.
+
+ zipfile.Path directory names always end in a slash.
+ """
+ return rf'{pattern}[/]?'
+
+
+def translate_core(pattern):
r"""
Given a glob pattern, produce a regex that matches it.