[postprocessor:metadata] fix traversing more than 1 level deep

for mode 'modify' and 'delete'
This commit is contained in:
Mike Fährmann
2023-04-25 14:17:25 +02:00
parent 5297ee0cd9
commit 7459e4abce
2 changed files with 43 additions and 26 deletions

View File

@@ -124,10 +124,8 @@ class MetadataPP(PostProcessor):
for key, func in self.fields.items():
obj = kwdict
try:
while "[" in key:
name, _, key = key.partition("[")
obj = obj[name]
key = key.rstrip("]")
if "[" in key:
obj, key = _traverse(obj, key)
obj[key] = func(kwdict)
except Exception:
pass
@@ -137,10 +135,8 @@ class MetadataPP(PostProcessor):
for key in self.fields:
obj = kwdict
try:
while "[" in key:
name, _, key = key.partition("[")
obj = obj[name]
key = key.rstrip("]")
if "[" in key:
obj, key = _traverse(obj, key)
del obj[key]
except Exception:
pass
@@ -214,4 +210,15 @@ class MetadataPP(PostProcessor):
)
def _traverse(obj, key):
name, _, key = key.partition("[")
obj = obj[name]
while "[" in key:
name, _, key = key.partition("[")
obj = obj[name.rstrip("]")]
return obj, key.strip("]")
__postprocessor__ = MetadataPP