[path] implement dynamic length directories (#1350)

append directory segments for each item of a list (or general non-string
iterable), which can be returned with the 'I' specifier
This commit is contained in:
Mike Fährmann
2025-12-18 09:53:26 +01:00
parent 73db1846e1
commit c3d8602418
3 changed files with 16 additions and 9 deletions

View File

@@ -282,12 +282,20 @@ class PathFormat():
segments = []
strip = self.strip
for fmt in formatters:
segment = fmt(kwdict).strip()
if strip and segment not in {".", ".."}:
# remove trailing dots and spaces (#647)
segment = segment.rstrip(strip)
if segment:
segments.append(self.clean_segment(segment))
segment = fmt(kwdict)
if segment.__class__ is str:
segment = segment.strip()
if strip and segment not in {".", ".."}:
segment = segment.rstrip(strip)
if segment:
segments.append(self.clean_segment(segment))
else: # assume list
for segment in segment:
segment = segment.strip()
if strip and segment not in {".", ".."}:
segment = segment.rstrip(strip)
if segment:
segments.append(self.clean_segment(segment))
return segments
except Exception as exc:
raise exception.DirectoryFormatError(exc)