def testsuite(testdata):
    inflater = nghttp2.HDInflater()

    for casenum, item  in enumerate(testdata['cases']):
        if 'header_table_size' in item:
            hd_table_size = int(item['header_table_size'])
            inflater.change_table_size(hd_table_size)
        compressed = a2b_hex(item['wire'])
        # sys.stderr.write('#{} WIRE:\n{}\n'.format(casenum+1, item['wire']))
        # TODO decompressed headers are not necessarily UTF-8 strings
        hdrs = [(k.decode('utf-8'), v.decode('utf-8')) \
                for k, v in inflater.inflate(compressed)]

        expected_hdrs = [(list(x.keys())[0],
                          list(x.values())[0]) for x in item['headers']]
        if hdrs != expected_hdrs:
            if 'seqno' in item:
                seqno = item['seqno']
            else:
                seqno = casenum

            sys.stderr.write('FAIL seqno#{}\n'.format(seqno))
            sys.stderr.write('expected:\n')
            for k, v in expected_hdrs:
                sys.stderr.write('{}: {}\n'.format(k, v))
            sys.stderr.write(', but got:\n')
            for k, v in hdrs:
                sys.stderr.write('{}: {}\n'.format(k, v))
            raise Exception('test failure')
    sys.stderr.write('PASS\n')
Example #2
0
 def __init__(self):
     self._d = nghttp2.HDInflater()