feeds: fix delete/rmv code

master
pictuga 2020-03-20 12:22:07 +01:00
parent 4735ffba45
commit 5705a0be17
1 changed files with 11 additions and 5 deletions

View File

@ -495,8 +495,9 @@ class ParserJSON(ParserBase):
return json.loads(raw) return json.loads(raw)
def remove(self): def remove(self):
# delete oneself FIXME # impossible to "delete" oneself per se but can clear all its items
pass for attr in self.root:
del self.root[attr]
def tostring(self, encoding='unicode', **k): def tostring(self, encoding='unicode', **k):
dump = json.dumps(self.root, ensure_ascii=False, **k) # ensure_ascii = False to have proper (unicode) string and not \u00 dump = json.dumps(self.root, ensure_ascii=False, **k) # ensure_ascii = False to have proper (unicode) string and not \u00
@ -556,10 +557,15 @@ class ParserJSON(ParserBase):
rrule = self._rule_parse(rule) rrule = self._rule_parse(rule)
cur = self.root cur = self.root
for node in rrule[:-1]: try:
cur = cur[node] for node in rrule[:-1]:
cur = cur[node]
del cur[rrule[-1]] del cur[rrule[-1]]
except KeyError:
# nothing to delete
pass
def rule_set(self, rule, value): def rule_set(self, rule, value):
if '[]' in rule: if '[]' in rule: