Skip to content

Commit c8c35bd

Browse files
authored
Apply suggestions from code review
1 parent 5bbc702 commit c8c35bd

File tree

1 file changed

+4
-43
lines changed

1 file changed

+4
-43
lines changed

Tools/ssl/make_ssl_data.py

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,11 @@ def gen_error_codes(args):
178178
yield "/* generated from args.reasons */"
179179
yield "static struct py_ssl_error_code error_codes[] = {"
180180
for reason, libname, errname, num in args.reasons:
181-
yield f"#ifdef {reason}"
181+
yield f" #ifdef {reason}"
182182
yield f' {{"{errname}", ERR_LIB_{libname}, {reason}}},'
183-
yield "#else"
183+
yield " #else"
184184
yield f' {{"{errname}", {args.lib2errnum[libname]}, {num}}},'
185-
yield "#endif"
185+
yield " #endif"
186186
yield " {NULL, 0, 0} /* sentinel */"
187187
yield "};"
188188

@@ -204,42 +204,6 @@ def get_openssl_git_commit(args):
204204
return git_describe.stdout.strip()
205205

206206

207-
def get_header_name(args, commit):
208-
if args.openssl_version is not None:
209-
return f"Py_SSL_DATA_{args.openssl_version}_H"
210-
if args.output is not None:
211-
# deduce the header from the filename
212-
basename = os.path.basename(args.output)
213-
filestem, _ = os.path.splitext(basename)
214-
suffix = filestem.strip('_').upper()
215-
return f"Py_SSL_DATA_{suffix.removeprefix('SSL_DATA_')}_H"
216-
# deduce the header from the Git commit
217-
match = re.match(r"openssl[^\d](\d+)[^\d](\d+)[^\d]([a-z0-9]+)",
218-
commit, re.ASCII | re.IGNORECASE)
219-
if match is None:
220-
error("cannot extract OpenSSL version from Git commit %r; "
221-
"specify it via -H/--openssl-version instead", commit)
222-
major, minor, patch = match.groups()
223-
return f"Py_SSL_DATA_{major}{minor}{patch}_H"
224-
225-
226-
def gen_header_prolog_and_epilog(header_name):
227-
prolog = f"""\
228-
#ifndef {header_name}
229-
#define {header_name}
230-
231-
#include <stddef.h>
232-
233-
#ifdef __cplusplus
234-
extern "C" {{
235-
#endif"""
236-
epilog = f"""\
237-
#ifdef __cplusplus
238-
}}
239-
#endif
240-
241-
#endif /* !{header_name} */"""
242-
return prolog, epilog
243207

244208

245209
def main(args=None):
@@ -268,19 +232,16 @@ def main(args=None):
268232
args.reasons = sorted(reasons, key=operator.itemgetter(0, 3))
269233

270234
commit = get_openssl_git_commit(args)
271-
header_name = get_header_name(args, commit)
272-
prolog, epilog = gen_header_prolog_and_epilog(header_name)
273235

274236
lines = [
275237
"/* File generated by Tools/ssl/make_ssl_data.py */",
276238
f"/* Generated on {datetime.datetime.now(datetime.UTC).isoformat()} */",
277239
f"/* Generated from Git commit {commit} */",
240+
"",
278241
]
279-
lines.extend(["", prolog, ""])
280242
lines.extend(gen_library_codes(args))
281243
lines.append("")
282244
lines.extend(gen_error_codes(args))
283-
lines.extend(["", epilog])
284245

285246
if args.output is None:
286247
for line in lines:

0 commit comments

Comments
 (0)