-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
Expand file tree
/
Copy pathconstants_helper.py
More file actions
23 lines (19 loc) · 801 Bytes
/
constants_helper.py
File metadata and controls
23 lines (19 loc) · 801 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import re
from pathlib import Path
from typing import Iterable
from test.support.project_files_helper import iter_all_c_files
# copypaste from 'Tools/build/generate_global_objects.py'
def iter_global_strings() -> Iterable[str]:
id_regex = re.compile(r"\b_Py_ID\((\w+)\)")
str_regex = re.compile(r'\b_Py_DECLARE_STR\((?:\w+), "(.*?)"\)')
for filename in iter_all_c_files():
infile = Path(filename)
if not infile.exists():
# The file must have been a temporary file.
continue
with infile.open(encoding="utf-8") as infile_open:
for line in infile_open:
for m in id_regex.finditer(line):
yield m.group(1)
for m in str_regex.finditer(line):
yield m.group(1)