Skip to content

Commit

Permalink
Merge pull request nghttp2#1546 from nghttp2/py3-scripts
Browse files Browse the repository at this point in the history
Python3 development scripts
  • Loading branch information
tatsuhiro-t authored Dec 29, 2020
2 parents 4653672 + 28ba0b3 commit 79a4f78
Show file tree
Hide file tree
Showing 14 changed files with 115 additions and 121 deletions.
4 changes: 2 additions & 2 deletions author.py
Original file line number Diff line number Diff line change
@@ -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 <AUTHOR>:<EMAIL>, one per line.
Expand Down Expand Up @@ -49,4 +49,4 @@
ndict[lowname] = name

for name in sorted(ndict.values()):
print name
print(name)
2 changes: 1 addition & 1 deletion genauthoritychartbl.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import sys

def name(i):
Expand Down
2 changes: 1 addition & 1 deletion gendowncasetbl.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import sys

def name(i):
Expand Down
2 changes: 1 addition & 1 deletion genheaderfunc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

from gentokenlookup import gentokenlookup

Expand Down
44 changes: 22 additions & 22 deletions genlibtokenlookup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

HEADERS = [
(':authority', 0),
Expand Down Expand Up @@ -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()
3 changes: 1 addition & 2 deletions genmethodfunc.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion gennghttpxfun.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

from gentokenlookup import gentokenlookup

Expand Down
2 changes: 1 addition & 1 deletion gennmchartbl.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import sys

def name(i):
Expand Down
48 changes: 24 additions & 24 deletions gentokenlookup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

def to_enum_hd(k, prefix):
res = prefix
Expand All @@ -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)
2 changes: 1 addition & 1 deletion genvchartbl.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import sys

def name(i):
Expand Down
4 changes: 1 addition & 3 deletions help2rst.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
23 changes: 11 additions & 12 deletions mkcipherlist.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -295,7 +294,7 @@

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

Expand All @@ -306,21 +305,21 @@
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)))
Loading

0 comments on commit 79a4f78

Please sign in to comment.