Commit beee150c authored by Tomas Krizek's avatar Tomas Krizek Committed by Petr Špaček

pylint fixes

parent 0716e7c7
......@@ -25,7 +25,7 @@ def process_diff(field_weights, field_stats, qwire, diff):
qmsg = dns.message.from_wire(qwire)
question = (qmsg.question[0].name, qmsg.question[0].rdtype)
field_mismatches = field_stats.setdefault(field, {})
field_mismatches = field_stats.setdefault(field, {}) # pylint: disable=undefined-loop-variable
mismatch = diff[significant_field]
mismatch_key = (mismatch.exp_val, mismatch.got_val)
mismatch_counter = field_mismatches.setdefault(mismatch_key, collections.Counter())
......@@ -43,9 +43,7 @@ def process_results(field_weights, diff_generator):
}
field_stats = {}
# print('diffs = {')
for qid, qwire, others_agree, target_diff in diff_generator:
# print(qid, others_agree, target_diff)
for _, qwire, others_agree, target_diff in diff_generator:
if not others_agree:
global_stats['others_disagree'] += 1
continue
......@@ -53,13 +51,9 @@ def process_results(field_weights, diff_generator):
if not target_diff: # everybody agreed, nothing to count
continue
# print('(%s, %s): ' % (qid, question))
# print(target_diff, ',')
global_stats['target_disagrees'] += 1
process_diff(field_weights, field_stats, qwire, target_diff)
# print('}')
return global_stats, field_stats
......@@ -79,8 +73,7 @@ def combine_stats(counters):
def mismatch2str(mismatch):
if not isinstance(mismatch[0], str):
return (' '.join(mismatch[0]), ' '.join(mismatch[1]))
else:
return mismatch
return mismatch
def maxlen(iterable):
......@@ -119,10 +112,10 @@ def print_results(gstats, field_weights, counters, n=10):
'count', maxcntlen,
'% of mismatches'))
for field, n in (field_sums.most_common()):
for field, count in field_sums.most_common():
print('{:{}} {:{}} {:3.0f} %'.format(
field, maxnamelen + 3,
n, maxcntlen + 3, 100.0 * n / target_disagrees))
count, maxcntlen + 3, 100.0 * n / target_disagrees))
for field in field_weights:
if field not in field_mismatch_sums:
......@@ -140,26 +133,25 @@ def print_results(gstats, field_weights, counters, n=10):
'count', maxcntlen,
'% of mismatches'
))
for mismatch, n in (field_mismatch_sums[field].most_common()):
for mismatch, count in field_mismatch_sums[field].most_common():
mismatch = mismatch2str(mismatch)
print('{:{}} != {:{}} {:{}} {:3.0f} %'.format(
str(mismatch[0]), maxvallen,
str(mismatch[1]), maxvallen,
n, maxcntlen,
100.0 * n / target_disagrees))
100.0 * count / target_disagrees))
for field in field_weights:
if field not in counters:
continue
for mismatch, n in (field_mismatch_sums[field].most_common()):
for mismatch, count in field_mismatch_sums[field].most_common():
print('')
print('== Field "%s" mismatch %s query details' % (field, mismatch))
counter = counters[field][mismatch]
print_field_queries(field, counter, n)
print_field_queries(counter, count)
def print_field_queries(field, counter, n):
# print('queries leading to mismatch in field "%s":' % field)
def print_field_queries(counter, n):
for query, count in counter.most_common(n):
qname, qtype = query
qtype = dns.rdatatype.to_text(qtype)
......
......@@ -22,15 +22,20 @@ def write_blobs(blob_dict, workdir):
outfile.write(v)
config = dbhelper.env_open.copy()
config.update({
'path': sys.argv[1],
'readonly': True
})
lenv = lmdb.Environment(**config)
db = lenv.open_db(key=b'answers', **dbhelper.db_open, create=False)
qid = str(int(sys.argv[2])).encode('ascii')
blobs = read_blobs_lmdb(lenv, db, qid)
write_blobs(blobs, sys.argv[3])
lenv.close()
def main():
config = dbhelper.env_open.copy()
config.update({
'path': sys.argv[1],
'readonly': True
})
lenv = lmdb.Environment(**config)
db = lenv.open_db(key=b'answers', **dbhelper.db_open, create=False)
qid = str(int(sys.argv[2])).encode('ascii')
blobs = read_blobs_lmdb(lenv, db, qid)
write_blobs(blobs, sys.argv[3])
lenv.close()
if __name__ == '__main__':
main()
......@@ -18,6 +18,7 @@ import dbhelper
class DataMismatch(Exception):
def __init__(self, exp_val, got_val):
super(DataMismatch, self).__init__(exp_val, got_val)
self.exp_val = exp_val
self.got_val = got_val
......@@ -58,14 +59,12 @@ def compare_rrs_types(exp_val, got_val, skip_rrsigs):
def rr_ordering_key(rrset):
if rrset.covers:
return (rrset.covers, 1) # RRSIGs go to the end of RRtype list
else:
return (rrset.rdtype, 0)
return (rrset.rdtype, 0)
def key_to_text(rrtype, rrsig):
if not rrsig:
return dns.rdatatype.to_text(rrtype)
else:
return 'RRSIG(%s)' % dns.rdatatype.to_text(rrtype)
return 'RRSIG(%s)' % dns.rdatatype.to_text(rrtype)
if skip_rrsigs:
exp_val = (rrset for rrset in exp_val
......@@ -81,16 +80,16 @@ def compare_rrs_types(exp_val, got_val, skip_rrsigs):
raise DataMismatch(exp_types, got_types)
def match_part(exp_msg, got_msg, code):
def match_part(exp_msg, got_msg, code): # pylint: disable=inconsistent-return-statements
""" Compare scripted reply to given message using single criteria. """
if code == 'opcode':
return compare_val(exp_msg.opcode(), got_msg.opcode())
elif code == 'qtype':
if len(exp_msg.question) == 0:
if not exp_msg.question:
return True
return compare_val(exp_msg.question[0].rdtype, got_msg.question[0].rdtype)
elif code == 'qname':
if len(exp_msg.question) == 0:
if not exp_msg.question:
return True
return compare_val(exp_msg.question[0].name, got_msg.question[0].name)
elif code == 'qcase':
......@@ -154,7 +153,7 @@ def decode_wire_dict(wire_dict: Dict[str, dataformat.Reply]) \
# convert from wire format to DNS message object
try:
answers[k] = dns.message.from_wire(v.wire)
except Exception as ex:
except Exception:
# answers[k] = ex # decoding failed, record it!
continue
return answers
......@@ -194,7 +193,7 @@ def compare(answers, criteria, target):
others.remove(target)
except ValueError:
return (False, None) # HACK, target did not reply
if len(others) == 0:
if not others:
return (False, None) # HACK, not enough targets to compare
random_other = others[0]
......@@ -286,7 +285,7 @@ def main():
initializer=worker_init,
initargs=(args.envdir, config['diff']['criteria'], config['diff']['target'])
) as p:
for i in p.imap_unordered(compare_lmdb_wrapper, qid_stream, chunksize=10):
for _ in p.imap_unordered(compare_lmdb_wrapper, qid_stream, chunksize=10):
pass
......
......@@ -7,7 +7,7 @@ for i in range(0, 256):
if i in allowed_bytes:
trans[i] = bytes(chr(i), encoding='ascii')
else:
trans[i] = ('\%03i' % i).encode('ascii')
trans[i] = (r'\%03i' % i).encode('ascii')
# pprint(trans)
while True:
......
......@@ -40,7 +40,7 @@ def parse_pcap(pcap_file):
"""
i = 0
pcap_file = dpkt.pcap.Reader(pcap_file)
for ts, wire in pcap_file:
for _, wire in pcap_file:
i += 1
yield (i, wire, '')
......@@ -51,7 +51,7 @@ def wrk_process_line(args: Tuple[int, str, str]) -> Tuple[bytes, bytes]:
Skips over empty lines, raises for malformed inputs.
"""
qid, line, log_repr = args
qid, line, _ = args
try:
wire = wire_from_text(line)
......@@ -80,11 +80,11 @@ def wrk_process_wire_packet(qid: int, wire_packet: bytes, log_repr: str) -> Tupl
if not blacklist.is_blacklisted(wire_packet):
key = dbhelper.qid2key(qid)
return key, wire_packet
else:
logging.debug('Query "%s" blacklisted (skipping query ID %d)',
log_repr if log_repr else repr(blacklist.extract_packet(wire_packet)),
qid)
return None, None
logging.debug('Query "%s" blacklisted (skipping query ID %d)',
log_repr if log_repr else repr(blacklist.extract_packet(wire_packet)),
qid)
return None, None
def int_or_fromtext(value, fromtext):
......
......@@ -46,9 +46,9 @@ def read_repro_lmdb(levn, qdb, reprodb):
def main():
lenv, qdb, ddb, reprodb = open_db(sys.argv[1])
lenv, qdb, _, reprodb = open_db(sys.argv[1])
repro_stream = read_repro_lmdb(lenv, qdb, reprodb)
for qid, qwire, (count, others_agreed, diff_matched) in repro_stream:
for _, qwire, (count, others_agreed, diff_matched) in repro_stream:
if not count == others_agreed == diff_matched:
continue
try:
......
......@@ -58,7 +58,7 @@ def _recv_msg(sock, isstream):
"""
if isstream: # parse preambule
blength = sock.recv(2) # TODO: does not work with TLS: , socket.MSG_WAITALL)
if len(blength) == 0: # stream closed
if not blength: # stream closed
raise ConnectionError('TCP recv length == 0')
(length, ) = struct.unpack('!H', blength)
else:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment