1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-22 18:53:21 +01:00

detect circular references with -K (fixes #2609)

This commit is contained in:
Mike Fährmann 2022-05-20 20:47:25 +02:00
parent 9d5580a091
commit 64d3ad2e7a
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88

View File

@ -574,21 +574,31 @@ class KeywordJob(Job):
KeywordJob(extr or url, self).run()
raise exception.StopExtraction()
def print_kwdict(self, kwdict, prefix=""):
def print_kwdict(self, kwdict, prefix="", markers=None):
"""Print key-value pairs in 'kwdict' with formatting"""
write = sys.stdout.write
suffix = "]" if prefix else ""
markerid = id(kwdict)
if markers is None:
markers = {markerid}
elif markerid in markers:
write("{}\n <circular reference>\n".format(prefix[:-1]))
return # ignore circular reference
else:
markers.add(markerid)
for key, value in sorted(kwdict.items()):
if key[0] == "_" and not self.private:
continue
key = prefix + key + suffix
if isinstance(value, dict):
self.print_kwdict(value, key + "[")
self.print_kwdict(value, key + "[", markers)
elif isinstance(value, list):
if value and isinstance(value[0], dict):
self.print_kwdict(value[0], key + "[][")
self.print_kwdict(value[0], key + "[][", markers)
else:
write(key + "[]\n")
for val in value: