Skip to content
Prev Previous commit
Next Next commit
In readers.MultiplexedPath, re-use Traversable.joinpath.
  • Loading branch information
jaraco committed Jun 16, 2022
commit 64403234fdbc3b9df60a57ff1ee76778a03a83b4
19 changes: 10 additions & 9 deletions importlib_resources/readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,16 @@ def is_dir(self):
def is_file(self):
return False

def joinpath(self, child):
# first try to find child in current paths
for file in self.iterdir():
if file.name == child:
return file
# if it does not exist, construct it with the first path
return self._paths[0] / child

__truediv__ = joinpath
def joinpath(self, *descendants):
try:
return super().joinpath(*descendants)
except abc.TraversalError as exc:
# One of the paths didn't resolve.
msg, target, names = exc.args
if names:
raise
# It was the last; construct result with the first path.
return self._paths[0].joinpath(target)

def open(self, *args, **kwargs):
raise FileNotFoundError(f'{self} is not a file')
Expand Down