From 02605d1e1cba2daa57bbe6b90325740d3c050f9c Mon Sep 17 00:00:00 2001 From: Alexandre Dulaunoy Date: Wed, 25 Dec 2013 09:49:27 +0100 Subject: [PATCH] Remove duplicate values from pdns results The option is by default to remove duplicate. The duplicate can be useful when you have a set of pdns in cluster to validate the result set. --- bin/qof-server.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/bin/qof-server.py b/bin/qof-server.py index e21c8ee..87d63c0 100644 --- a/bin/qof-server.py +++ b/bin/qof-server.py @@ -83,10 +83,21 @@ def getAssociatedRecords(rdata = None): records.append(v.decode(encoding='UTF-8')) return records -def JsonQOF(rrfound = None): +def RemDuplicate(d = None): + if d is None: + return False + outd = [dict(t) for t in set([tuple(o.items()) for o in d])] + return outd + + +def JsonQOF(rrfound = None, RemoveDuplicate=True): if rrfound is None: return False rrqof = "" + + if RemoveDuplicate: + rrfound=RemDuplicate(d=rrfound) + for rr in rrfound: rrqof = rrqof + json.dumps(rr) + "\n" return rrqof