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:
parent
9d5580a091
commit
64d3ad2e7a
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user