[postprocessor:metadata] fix traversing more than 1 level deep
for mode 'modify' and 'delete'
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user