Require python3 for python scripts

This commit is contained in:
Tatsuhiro Tsujikawa 2020-12-29 17:01:31 +09:00
parent 465367294f
commit 6b7ade9f3f
14 changed files with 113 additions and 119 deletions

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
# script to extract commit author's name from standard input. The # script to extract commit author's name from standard input. The
# input should be <AUTHOR>:<EMAIL>, one per line. # input should be <AUTHOR>:<EMAIL>, one per line.
@ -49,4 +49,4 @@ for name in names:
ndict[lowname] = name ndict[lowname] = name
for name in sorted(ndict.values()): for name in sorted(ndict.values()):
print name print(name)

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
import sys import sys
def name(i): def name(i):

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
import sys import sys
def name(i): def name(i):

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
from gentokenlookup import gentokenlookup from gentokenlookup import gentokenlookup

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
HEADERS = [ HEADERS = [
(':authority', 0), (':authority', 0),
@ -96,47 +96,47 @@ def build_header(headers):
def gen_enum(): def gen_enum():
name = '' name = ''
print 'typedef enum {' print('typedef enum {')
for k, token in HEADERS: for k, token in HEADERS:
if token is None: if token is None:
print ' {},'.format(to_enum_hd(k)) print(' {},'.format(to_enum_hd(k)))
else: else:
if name != k: if name != k:
name = k name = k
print ' {} = {},'.format(to_enum_hd(k), token) print(' {} = {},'.format(to_enum_hd(k), token))
print '} nghttp2_token;' print('} nghttp2_token;')
def gen_index_header(): def gen_index_header():
print '''\ print('''\
static int32_t lookup_token(const uint8_t *name, size_t namelen) { static int32_t lookup_token(const uint8_t *name, size_t namelen) {
switch (namelen) {''' switch (namelen) {''')
b = build_header(HEADERS) b = build_header(HEADERS)
for size in sorted(b.keys()): for size in sorted(b.keys()):
ents = b[size] ents = b[size]
print '''\ print('''\
case {}:'''.format(size) case {}:'''.format(size))
print '''\ print('''\
switch (name[{}]) {{'''.format(size - 1) switch (name[{}]) {{'''.format(size - 1))
for c in sorted(ents.keys()): for c in sorted(ents.keys()):
headers = sorted(ents[c]) headers = sorted(ents[c])
print '''\ print('''\
case '{}':'''.format(c) case '{}':'''.format(c))
for k in headers: for k in headers:
print '''\ print('''\
if (memeq("{}", name, {})) {{ if (memeq("{}", name, {})) {{
return {}; return {};
}}'''.format(k[:-1], size - 1, to_enum_hd(k)) }}'''.format(k[:-1], size - 1, to_enum_hd(k)))
print '''\ print('''\
break;''' break;''')
print '''\ print('''\
} }
break;''' break;''')
print '''\ print('''\
} }
return -1; return -1;
}''' }''')
if __name__ == '__main__': if __name__ == '__main__':
gen_enum() gen_enum()
print '' print()
gen_index_header() gen_index_header()

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
from __future__ import unicode_literals
from io import StringIO from io import StringIO
from gentokenlookup import gentokenlookup from gentokenlookup import gentokenlookup

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
from gentokenlookup import gentokenlookup from gentokenlookup import gentokenlookup

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
import sys import sys
def name(i): def name(i):

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
def to_enum_hd(k, prefix): def to_enum_hd(k, prefix):
res = prefix res = prefix
@ -24,46 +24,46 @@ def build_header(headers):
return res return res
def gen_enum(tokens, prefix): def gen_enum(tokens, prefix):
print '''\ print('''\
enum {''' enum {''')
for k in sorted(tokens): for k in sorted(tokens):
print '''\ print('''\
{},'''.format(to_enum_hd(k, prefix)) {},'''.format(to_enum_hd(k, prefix)))
print '''\ print('''\
{}MAXIDX, {}MAXIDX,
}};'''.format(prefix) }};'''.format(prefix))
def gen_index_header(tokens, prefix, value_type, comp_fun, return_type, fail_value): def gen_index_header(tokens, prefix, value_type, comp_fun, return_type, fail_value):
print '''\ print('''\
{} lookup_token(const {} *name, size_t namelen) {{ {} 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) b = build_header(tokens)
for size in sorted(b.keys()): for size in sorted(b.keys()):
ents = b[size] ents = b[size]
print '''\ print('''\
case {}:'''.format(size) case {}:'''.format(size))
print '''\ print('''\
switch (name[{}]) {{'''.format(size - 1) switch (name[{}]) {{'''.format(size - 1))
for c in sorted(ents.keys()): for c in sorted(ents.keys()):
headers = sorted(ents[c]) headers = sorted(ents[c])
print '''\ print('''\
case '{}':'''.format(c) case '{}':'''.format(c))
for k in headers: for k in headers:
print '''\ print('''\
if ({}("{}", name, {})) {{ if ({}("{}", name, {})) {{
return {}; return {};
}}'''.format(comp_fun, k[:-1], size - 1, to_enum_hd(k, prefix)) }}'''.format(comp_fun, k[:-1], size - 1, to_enum_hd(k, prefix)))
print '''\ print('''\
break;''' break;''')
print '''\ print('''\
} }
break;''' break;''')
print '''\ print('''\
}} }}
return {}; 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'): def gentokenlookup(tokens, prefix, value_type='uint8_t', comp_fun='util::streq_l', return_type='int', fail_value='-1'):
gen_enum(tokens, prefix) gen_enum(tokens, prefix)
print '' print()
gen_index_header(tokens, prefix, value_type, comp_fun, return_type, fail_value) gen_index_header(tokens, prefix, value_type, comp_fun, return_type, fail_value)

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
import sys import sys
def name(i): def name(i):

View File

@ -1,10 +1,8 @@
#!/usr/bin/env python #!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# script to produce rst file from program's help output. # script to produce rst file from program's help output.
from __future__ import unicode_literals
from __future__ import print_function
import sys import sys
import re import re
import argparse import argparse

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# This script read cipher suite list csv file [1] and prints out id # 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 # [1] http://www.iana.org/assignments/tls-parameters/tls-parameters-4.csv
# [2] http://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml # [2] http://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml
from __future__ import unicode_literals
import re import re
import sys import sys
import csv import csv
@ -295,7 +294,7 @@ blacklist = [
ciphers = [] ciphers = []
found = set() found = set()
for hl, name, _, _ in csv.reader(sys.stdin): for hl, name, _, _, _ in csv.reader(sys.stdin):
if name not in blacklist: if name not in blacklist:
continue continue
@ -306,21 +305,21 @@ for hl, name, _, _ in csv.reader(sys.stdin):
id = high + low[2:] + 'u' id = high + low[2:] + 'u'
ciphers.append((id, name)) ciphers.append((id, name))
print '''\ print('''\
enum {''' enum {''')
for id, name in ciphers: for id, name in ciphers:
print '{} = {},'.format(name, id) print('{} = {},'.format(name, id))
print '''\ print('''\
}; };
''' ''')
for id, name in ciphers: for id, name in ciphers:
print '''\ print('''\
case {}:'''.format(name) case {}:'''.format(name))
if len(found) != len(blacklist): 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), len(found), len(blacklist),
found.symmetric_difference(blacklist)) found.symmetric_difference(blacklist)))

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# This script reads Huffman Code table [1] and generates symbol table # This script reads Huffman Code table [1] and generates symbol table
@ -7,10 +7,9 @@
# #
# [1] http://http2.github.io/http2-spec/compression.html # [1] http://http2.github.io/http2-spec/compression.html
from __future__ import unicode_literals
import re import re
import sys import sys
import StringIO from io import StringIO
# From [1] # From [1]
HUFFMAN_CODE_TABLE = """\ HUFFMAN_CODE_TABLE = """\
@ -363,8 +362,8 @@ NGHTTP2_HUFF_SYM = 1 << 15
def _print_transition_table(node): def _print_transition_table(node):
if node.term is not None: if node.term is not None:
return return
print '/* {} */'.format(node.id) print('/* {} */'.format(node.id))
print '{' print('{')
for nd, sym in node.trans: for nd, sym in node.trans:
flags = 0 flags = 0
if sym is None: if sym is None:
@ -382,38 +381,38 @@ def _print_transition_table(node):
flags |= NGHTTP2_HUFF_ACCEPTED flags |= NGHTTP2_HUFF_ACCEPTED
elif nd.accept: elif nd.accept:
flags |= NGHTTP2_HUFF_ACCEPTED flags |= NGHTTP2_HUFF_ACCEPTED
print ' {{0x{:02x}, {}}},'.format(id | flags, out) print(' {{0x{:02x}, {}}},'.format(id | flags, out))
print '},' print('},')
_print_transition_table(node.left) _print_transition_table(node.left)
_print_transition_table(node.right) _print_transition_table(node.right)
def huffman_tree_print_transition_table(ctx): def huffman_tree_print_transition_table(ctx):
_print_transition_table(ctx.root) _print_transition_table(ctx.root)
print '/* 256 */' print('/* 256 */')
print '{' 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 ' {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('},')
if __name__ == '__main__': if __name__ == '__main__':
ctx = Context() ctx = Context()
symbol_tbl = [(None, 0) for i in range(257)] 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( m = re.match(
r'.*\(\s*(\d+)\)\s+([|01]+)\s+(\S+)\s+\[\s*(\d+)\].*', line) r'.*\(\s*(\d+)\)\s+([|01]+)\s+(\S+)\s+\[\s*(\d+)\].*', line)
if m: if m:
@ -430,40 +429,40 @@ if __name__ == '__main__':
huffman_tree_set_node_id(ctx) huffman_tree_set_node_id(ctx)
huffman_tree_build_transition_table(ctx) huffman_tree_build_transition_table(ctx)
print '''\ print('''\
typedef struct { typedef struct {
uint32_t nbits; uint32_t nbits;
uint32_t code; uint32_t code;
} nghttp2_huff_sym; } nghttp2_huff_sym;
''' ''')
print '''\ print('''\
const nghttp2_huff_sym huff_sym_table[] = {''' const nghttp2_huff_sym huff_sym_table[] = {''')
for i in range(257): for i in range(257):
nbits = symbol_tbl[i][0] nbits = symbol_tbl[i][0]
k = int(symbol_tbl[i][1], 16) k = int(symbol_tbl[i][1], 16)
k = k << (32 - nbits) k = k << (32 - nbits)
print '''\ print('''\
{{ {}, 0x{}u }}{}\ {{ {}, 0x{}u }}{}\
'''.format(symbol_tbl[i][0], hex(k)[2:], ',' if i < 256 else '') '''.format(symbol_tbl[i][0], hex(k)[2:], ',' if i < 256 else ''))
print '};' print('};')
print '' print()
print '''\ print('''\
enum {{ enum {{
NGHTTP2_HUFF_ACCEPTED = {}, NGHTTP2_HUFF_ACCEPTED = {},
NGHTTP2_HUFF_SYM = {}, NGHTTP2_HUFF_SYM = {},
}} nghttp2_huff_decode_flag; }} nghttp2_huff_decode_flag;
'''.format(NGHTTP2_HUFF_ACCEPTED, NGHTTP2_HUFF_SYM) '''.format(NGHTTP2_HUFF_ACCEPTED, NGHTTP2_HUFF_SYM))
print '''\ print('''\
typedef struct { typedef struct {
uint16_t fstate; uint16_t fstate;
uint8_t sym; uint8_t sym;
} nghttp2_huff_decode; } nghttp2_huff_decode;
''' ''')
print '''\ print('''\
const nghttp2_huff_decode huff_decode_table[][16] = {''' const nghttp2_huff_decode huff_decode_table[][16] = {''')
huffman_tree_print_transition_table(ctx) huffman_tree_print_transition_table(ctx)
print '};' print('};')

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# This scripts reads static table entries [1] and generates # This scripts reads static table entries [1] and generates
@ -7,7 +7,6 @@
# #
# [1] http://http2.github.io/http2-spec/compression.html # [1] http://http2.github.io/http2-spec/compression.html
from __future__ import unicode_literals
import re, sys import re, sys
def hd_map_hash(name): def hd_map_hash(name):
@ -27,11 +26,11 @@ for line in sys.stdin:
val = m.group(3).strip() if m.group(3) else '' val = m.group(3).strip() if m.group(3) else ''
entries.append((int(m.group(1)), m.group(2), val)) 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 idx = 0
for i, ent in enumerate(entries): for i, ent in enumerate(entries):
if entries[idx][1] != ent[1]: if entries[idx][1] != ent[1]:
idx = i idx = i
print 'MAKE_STATIC_ENT("{}", "{}", {}, {}u),'\ print('MAKE_STATIC_ENT("{}", "{}", {}, {}u),'\
.format(ent[1], ent[2], entries[idx][0] - 1, hd_map_hash(ent[1])) .format(ent[1], ent[2], entries[idx][0] - 1, hd_map_hash(ent[1])))
print '};' print('};')