Unverified Commit 79a4f789 authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa Committed by GitHub

Merge pull request #1546 from nghttp2/py3-scripts

Python3 development scripts
parents 46536729 28ba0b37
#!/usr/bin/env python
#!/usr/bin/env python3
# script to extract commit author's name from standard input. The
# input should be <AUTHOR>:<EMAIL>, one per line.
......@@ -49,4 +49,4 @@ for name in names:
ndict[lowname] = name
for name in sorted(ndict.values()):
print name
print(name)
#!/usr/bin/env python
#!/usr/bin/env python3
import sys
def name(i):
......
#!/usr/bin/env python
#!/usr/bin/env python3
import sys
def name(i):
......
#!/usr/bin/env python
#!/usr/bin/env python3
from gentokenlookup import gentokenlookup
......
#!/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()
#!/usr/bin/env python
from __future__ import unicode_literals
#!/usr/bin/env python3
from io import StringIO
from gentokenlookup import gentokenlookup
......
#!/usr/bin/env python
#!/usr/bin/env python3
from gentokenlookup import gentokenlookup
......
#!/usr/bin/env python
#!/usr/bin/env python3
import sys
def name(i):
......
#!/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)
#!/usr/bin/env python
#!/usr/bin/env python3
import sys
def name(i):
......
#!/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
......
#!/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)))
#!/usr/bin/env python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# This script reads Huffman Code table [1] and generates symbol table
# 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
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('};')
#!/usr/bin/env python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# This scripts reads static table entries [1] and generates
# 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
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('};')
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