Uh oh!
There was an error while loading. Please reload this page.
This repository was archived by the owner on Jan 13, 2021. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 197
Expand file tree
/
Copy pathtasks.py
More file actions
Latest commit
59 lines (48 loc) · 1.89 KB
/
Copy pathtasks.py
File metadata and controls
59 lines (48 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
importjson
importos
frombinasciiimporthexlify
frominvokeimporttask
fromhyper.http20.hpackimportEncoder
@task
defhpack():
"""
This task generates HPACK test data suitable for use with
https://github.com/http2jp/hpack-test-case
The current format defines a JSON object with three keys: 'draft',
'description' and 'cases'.
The cases key has as its value a list of objects, with each object
representing a set of headers and the output from the encoder. The object
has the following keys:
- 'header_table_size': the size of the header table used.
- 'headers': A list of the headers as JSON objects.
- 'wire': The output from the encoder in hexadecimal.
"""
# A generator that contains the paths to all the raw data files and their
# names.
raw_story_files= (
(os.path.join('test_fixtures/raw-data', name), name)
fornameinos.listdir('test_fixtures/raw-data')
)
# For each file, build our output.
forsource, outnameinraw_story_files:
withopen(source, 'rb') asf:
indata=json.loads(f.read())
# Prepare the output and the encoder.
output= {
'description': 'Encoded by hyper. See github.com/Lukasa/hyper for more information.',
'cases': []
}
e=Encoder()
forcaseinindata['cases']:
outcase= {'header_table_size': e.header_table_size}
outcase['headers'] =case['headers']
headers= []
forheaderincase['headers']:
key=header.keys()[0]
header= (key, header[key])
headers.append(header)
outcase['wire'] =hexlify(e.encode(headers))
output['cases'].append(outcase)
withopen(outname, 'wb') asf:
f.write(json.dumps(output, sort_keys=True,
indent=2, separators=(',', ': ')))