Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions tools/gen.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python

import ast
import io
import pathlib
from collections import defaultdict
Expand All @@ -13,10 +14,20 @@

def calc_headers(root):
hdrs_file = root / "aiohttp/hdrs.py"
code = compile(hdrs_file.read_text(), str(hdrs_file), "exec")
globs = {}
exec(code, globs)
headers = [val for val in globs.values() if isinstance(val, multidict.istr)]
tree = ast.parse(hdrs_file.read_text(), str(hdrs_file))
headers = []
for node in ast.walk(tree):
if isinstance(node, ast.Assign):
value = node.value
if (
isinstance(value, ast.Call)
and isinstance(value.func, ast.Name)
and value.func.id == "istr"
and len(value.args) == 1
and isinstance(value.args[0], ast.Constant)
and isinstance(value.args[0].value, str)
):
headers.append(multidict.istr(value.args[0].value))
return sorted(headers)


Expand Down
Loading