From 6b7ade9f3fb9ebb68bcb0c0911b2a831d4f10333 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Tue, 29 Dec 2020 17:01:31 +0900 Subject: [PATCH 1/2] Require python3 for python scripts --- author.py | 4 +- genauthoritychartbl.py | 2 +- gendowncasetbl.py | 2 +- genheaderfunc.py | 2 +- genlibtokenlookup.py | 44 +++++++++++----------- genmethodfunc.py | 3 +- gennghttpxfun.py | 2 +- gennmchartbl.py | 2 +- gentokenlookup.py | 48 ++++++++++++------------ genvchartbl.py | 2 +- help2rst.py | 4 +- mkcipherlist.py | 23 ++++++------ mkhufftbl.py | 83 +++++++++++++++++++++--------------------- mkstatichdtbl.py | 11 +++--- 14 files changed, 113 insertions(+), 119 deletions(-) diff --git a/author.py b/author.py index 760da009..4bf97c49 100755 --- a/author.py +++ b/author.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # script to extract commit author's name from standard input. The # input should be :, one per line. @@ -49,4 +49,4 @@ for name in names: ndict[lowname] = name for name in sorted(ndict.values()): - print name + print(name) diff --git a/genauthoritychartbl.py b/genauthoritychartbl.py index 39d63d37..1b100283 100755 --- a/genauthoritychartbl.py +++ b/genauthoritychartbl.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import sys def name(i): diff --git a/gendowncasetbl.py b/gendowncasetbl.py index aa98ae55..04aeda75 100755 --- a/gendowncasetbl.py +++ b/gendowncasetbl.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import sys def name(i): diff --git a/genheaderfunc.py b/genheaderfunc.py index b61d6576..71927609 100755 --- a/genheaderfunc.py +++ b/genheaderfunc.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 from gentokenlookup import gentokenlookup diff --git a/genlibtokenlookup.py b/genlibtokenlookup.py index 9477d07d..12a8533e 100755 --- a/genlibtokenlookup.py +++ b/genlibtokenlookup.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 HEADERS = [ (':authority', 0), @@ -96,47 +96,47 @@ def build_header(headers): def gen_enum(): name = '' - print 'typedef enum {' + print('typedef enum {') for k, token in HEADERS: if token is None: - print ' {},'.format(to_enum_hd(k)) + print(' {},'.format(to_enum_hd(k))) else: if name != k: name = k - print ' {} = {},'.format(to_enum_hd(k), token) - print '} nghttp2_token;' + print(' {} = {},'.format(to_enum_hd(k), token)) + print('} nghttp2_token;') def gen_index_header(): - print '''\ + print('''\ static int32_t lookup_token(const uint8_t *name, size_t namelen) { - switch (namelen) {''' + switch (namelen) {''') b = build_header(HEADERS) for size in sorted(b.keys()): ents = b[size] - print '''\ - case {}:'''.format(size) - print '''\ - switch (name[{}]) {{'''.format(size - 1) + print('''\ + case {}:'''.format(size)) + print('''\ + switch (name[{}]) {{'''.format(size - 1)) for c in sorted(ents.keys()): headers = sorted(ents[c]) - print '''\ - case '{}':'''.format(c) + print('''\ + case '{}':'''.format(c)) for k in headers: - print '''\ + print('''\ if (memeq("{}", name, {})) {{ return {}; - }}'''.format(k[:-1], size - 1, to_enum_hd(k)) - print '''\ - break;''' - print '''\ + }}'''.format(k[:-1], size - 1, to_enum_hd(k))) + print('''\ + break;''') + print('''\ } - break;''' - print '''\ + break;''') + print('''\ } return -1; -}''' +}''') if __name__ == '__main__': gen_enum() - print '' + print() gen_index_header() diff --git a/genmethodfunc.py b/genmethodfunc.py index 43cae6e9..436a77a8 100755 --- a/genmethodfunc.py +++ b/genmethodfunc.py @@ -1,5 +1,4 @@ -#!/usr/bin/env python -from __future__ import unicode_literals +#!/usr/bin/env python3 from io import StringIO from gentokenlookup import gentokenlookup diff --git a/gennghttpxfun.py b/gennghttpxfun.py index 1be4d56c..f119a079 100755 --- a/gennghttpxfun.py +++ b/gennghttpxfun.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 from gentokenlookup import gentokenlookup diff --git a/gennmchartbl.py b/gennmchartbl.py index d04b92c5..b75b9a67 100755 --- a/gennmchartbl.py +++ b/gennmchartbl.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import sys def name(i): diff --git a/gentokenlookup.py b/gentokenlookup.py index 8be15d51..82778580 100644 --- a/gentokenlookup.py +++ b/gentokenlookup.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 def to_enum_hd(k, prefix): res = prefix @@ -24,46 +24,46 @@ def build_header(headers): return res def gen_enum(tokens, prefix): - print '''\ -enum {''' + print('''\ +enum {''') for k in sorted(tokens): - print '''\ - {},'''.format(to_enum_hd(k, prefix)) - print '''\ + print('''\ + {},'''.format(to_enum_hd(k, prefix))) + print('''\ {}MAXIDX, -}};'''.format(prefix) +}};'''.format(prefix)) def gen_index_header(tokens, prefix, value_type, comp_fun, return_type, fail_value): - print '''\ + print('''\ {} lookup_token(const {} *name, size_t namelen) {{ - switch (namelen) {{'''.format(return_type, value_type) + switch (namelen) {{'''.format(return_type, value_type)) b = build_header(tokens) for size in sorted(b.keys()): ents = b[size] - print '''\ - case {}:'''.format(size) - print '''\ - switch (name[{}]) {{'''.format(size - 1) + print('''\ + case {}:'''.format(size)) + print('''\ + switch (name[{}]) {{'''.format(size - 1)) for c in sorted(ents.keys()): headers = sorted(ents[c]) - print '''\ - case '{}':'''.format(c) + print('''\ + case '{}':'''.format(c)) for k in headers: - print '''\ + print('''\ if ({}("{}", name, {})) {{ return {}; - }}'''.format(comp_fun, k[:-1], size - 1, to_enum_hd(k, prefix)) - print '''\ - break;''' - print '''\ + }}'''.format(comp_fun, k[:-1], size - 1, to_enum_hd(k, prefix))) + print('''\ + break;''') + print('''\ } - break;''' - print '''\ + break;''') + print('''\ }} return {}; -}}'''.format(fail_value) +}}'''.format(fail_value)) def gentokenlookup(tokens, prefix, value_type='uint8_t', comp_fun='util::streq_l', return_type='int', fail_value='-1'): gen_enum(tokens, prefix) - print '' + print() gen_index_header(tokens, prefix, value_type, comp_fun, return_type, fail_value) diff --git a/genvchartbl.py b/genvchartbl.py index a70a8811..4e4d4d96 100755 --- a/genvchartbl.py +++ b/genvchartbl.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import sys def name(i): diff --git a/help2rst.py b/help2rst.py index 4e585aac..245f669a 100755 --- a/help2rst.py +++ b/help2rst.py @@ -1,10 +1,8 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- # script to produce rst file from program's help output. -from __future__ import unicode_literals -from __future__ import print_function import sys import re import argparse diff --git a/mkcipherlist.py b/mkcipherlist.py index 093a9177..e366f5e5 100755 --- a/mkcipherlist.py +++ b/mkcipherlist.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- # This script read cipher suite list csv file [1] and prints out id @@ -8,7 +8,6 @@ # [1] http://www.iana.org/assignments/tls-parameters/tls-parameters-4.csv # [2] http://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml -from __future__ import unicode_literals import re import sys import csv @@ -295,7 +294,7 @@ blacklist = [ ciphers = [] found = set() -for hl, name, _, _ in csv.reader(sys.stdin): +for hl, name, _, _, _ in csv.reader(sys.stdin): if name not in blacklist: continue @@ -306,21 +305,21 @@ for hl, name, _, _ in csv.reader(sys.stdin): id = high + low[2:] + 'u' ciphers.append((id, name)) -print '''\ -enum {''' +print('''\ +enum {''') for id, name in ciphers: - print '{} = {},'.format(name, id) + print('{} = {},'.format(name, id)) -print '''\ +print('''\ }; -''' +''') for id, name in ciphers: - print '''\ -case {}:'''.format(name) + print('''\ +case {}:'''.format(name)) if len(found) != len(blacklist): - print '{} found out of {}; not all cipher was found: {}'.format( + print('{} found out of {}; not all cipher was found: {}'.format( len(found), len(blacklist), - found.symmetric_difference(blacklist)) + found.symmetric_difference(blacklist))) diff --git a/mkhufftbl.py b/mkhufftbl.py index 08e88a8c..6c8cca98 100755 --- a/mkhufftbl.py +++ b/mkhufftbl.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- # This script reads Huffman Code table [1] and generates symbol table @@ -7,10 +7,9 @@ # # [1] http://http2.github.io/http2-spec/compression.html -from __future__ import unicode_literals import re import sys -import StringIO +from io import StringIO # From [1] HUFFMAN_CODE_TABLE = """\ @@ -363,8 +362,8 @@ NGHTTP2_HUFF_SYM = 1 << 15 def _print_transition_table(node): if node.term is not None: return - print '/* {} */'.format(node.id) - print '{' + print('/* {} */'.format(node.id)) + print('{') for nd, sym in node.trans: flags = 0 if sym is None: @@ -382,38 +381,38 @@ def _print_transition_table(node): flags |= NGHTTP2_HUFF_ACCEPTED elif nd.accept: flags |= NGHTTP2_HUFF_ACCEPTED - print ' {{0x{:02x}, {}}},'.format(id | flags, out) - print '},' + print(' {{0x{:02x}, {}}},'.format(id | flags, out)) + print('},') _print_transition_table(node.left) _print_transition_table(node.right) def huffman_tree_print_transition_table(ctx): _print_transition_table(ctx.root) - print '/* 256 */' - print '{' - print ' {0x100, 0},' - print ' {0x100, 0},' - print ' {0x100, 0},' - print ' {0x100, 0},' - print ' {0x100, 0},' - print ' {0x100, 0},' - print ' {0x100, 0},' - print ' {0x100, 0},' - print ' {0x100, 0},' - print ' {0x100, 0},' - print ' {0x100, 0},' - print ' {0x100, 0},' - print ' {0x100, 0},' - print ' {0x100, 0},' - print ' {0x100, 0},' - print ' {0x100, 0},' - print '},' + print('/* 256 */') + print('{') + print(' {0x100, 0},') + print(' {0x100, 0},') + print(' {0x100, 0},') + print(' {0x100, 0},') + print(' {0x100, 0},') + print(' {0x100, 0},') + print(' {0x100, 0},') + print(' {0x100, 0},') + print(' {0x100, 0},') + print(' {0x100, 0},') + print(' {0x100, 0},') + print(' {0x100, 0},') + print(' {0x100, 0},') + print(' {0x100, 0},') + print(' {0x100, 0},') + print(' {0x100, 0},') + print('},') if __name__ == '__main__': ctx = Context() symbol_tbl = [(None, 0) for i in range(257)] - for line in StringIO.StringIO(HUFFMAN_CODE_TABLE): + for line in StringIO(HUFFMAN_CODE_TABLE): m = re.match( r'.*\(\s*(\d+)\)\s+([|01]+)\s+(\S+)\s+\[\s*(\d+)\].*', line) if m: @@ -430,40 +429,40 @@ if __name__ == '__main__': huffman_tree_set_node_id(ctx) huffman_tree_build_transition_table(ctx) - print '''\ + print('''\ typedef struct { uint32_t nbits; uint32_t code; } nghttp2_huff_sym; -''' +''') - print '''\ -const nghttp2_huff_sym huff_sym_table[] = {''' + print('''\ +const nghttp2_huff_sym huff_sym_table[] = {''') for i in range(257): nbits = symbol_tbl[i][0] k = int(symbol_tbl[i][1], 16) k = k << (32 - nbits) - print '''\ + print('''\ {{ {}, 0x{}u }}{}\ -'''.format(symbol_tbl[i][0], hex(k)[2:], ',' if i < 256 else '') - print '};' - print '' +'''.format(symbol_tbl[i][0], hex(k)[2:], ',' if i < 256 else '')) + print('};') + print() - print '''\ + print('''\ enum {{ NGHTTP2_HUFF_ACCEPTED = {}, NGHTTP2_HUFF_SYM = {}, }} nghttp2_huff_decode_flag; -'''.format(NGHTTP2_HUFF_ACCEPTED, NGHTTP2_HUFF_SYM) +'''.format(NGHTTP2_HUFF_ACCEPTED, NGHTTP2_HUFF_SYM)) - print '''\ + print('''\ typedef struct { uint16_t fstate; uint8_t sym; } nghttp2_huff_decode; -''' +''') - print '''\ -const nghttp2_huff_decode huff_decode_table[][16] = {''' + print('''\ +const nghttp2_huff_decode huff_decode_table[][16] = {''') huffman_tree_print_transition_table(ctx) - print '};' + print('};') diff --git a/mkstatichdtbl.py b/mkstatichdtbl.py index 4eec1124..994a7736 100755 --- a/mkstatichdtbl.py +++ b/mkstatichdtbl.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- # This scripts reads static table entries [1] and generates @@ -7,7 +7,6 @@ # # [1] http://http2.github.io/http2-spec/compression.html -from __future__ import unicode_literals import re, sys def hd_map_hash(name): @@ -27,11 +26,11 @@ for line in sys.stdin: val = m.group(3).strip() if m.group(3) else '' entries.append((int(m.group(1)), m.group(2), val)) -print 'static nghttp2_hd_entry static_table[] = {' +print('static nghttp2_hd_entry static_table[] = {') idx = 0 for i, ent in enumerate(entries): if entries[idx][1] != ent[1]: idx = i - print 'MAKE_STATIC_ENT("{}", "{}", {}, {}u),'\ - .format(ent[1], ent[2], entries[idx][0] - 1, hd_map_hash(ent[1])) -print '};' + print('MAKE_STATIC_ENT("{}", "{}", {}, {}u),'\ + .format(ent[1], ent[2], entries[idx][0] - 1, hd_map_hash(ent[1]))) +print('};') From 28ba0b37e17e4daa901b622b0865dae61ee709a3 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Tue, 29 Dec 2020 17:31:46 +0900 Subject: [PATCH 2/2] Update document reference --- mkhufftbl.py | 2 +- mkstatichdtbl.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mkhufftbl.py b/mkhufftbl.py index 6c8cca98..a9f10d75 100755 --- a/mkhufftbl.py +++ b/mkhufftbl.py @@ -5,7 +5,7 @@ # and decoding tables in C language. The resulting code is used in # lib/nghttp2_hd_huffman.h and lib/nghttp2_hd_huffman_data.c # -# [1] http://http2.github.io/http2-spec/compression.html +# [1] https://httpwg.org/specs/rfc7541.html import re import sys diff --git a/mkstatichdtbl.py b/mkstatichdtbl.py index 994a7736..20f0c153 100755 --- a/mkstatichdtbl.py +++ b/mkstatichdtbl.py @@ -5,7 +5,7 @@ # nghttp2_hd_static_entry table. This table is used in # lib/nghttp2_hd.c. # -# [1] http://http2.github.io/http2-spec/compression.html +# [1] https://httpwg.org/specs/rfc7541.html import re, sys