diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2012-06-22 19:12:59 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2012-06-22 19:12:59 (GMT) |
commit | f7338f65fb8bdb85c52dc54d06d003a82a06bbb3 (patch) | |
tree | 3c9664a228394688be7a8fc5c0c46305fc344b95 /Tools/ssl | |
parent | 3b36fb1f537a771829c9c7c9720dc040d3c87885 (diff) | |
download | cpython-f7338f65fb8bdb85c52dc54d06d003a82a06bbb3.zip cpython-f7338f65fb8bdb85c52dc54d06d003a82a06bbb3.tar.gz cpython-f7338f65fb8bdb85c52dc54d06d003a82a06bbb3.tar.bz2 |
Add forgotten files for #14837.
Diffstat (limited to 'Tools/ssl')
-rw-r--r-- | Tools/ssl/make_ssl_data.py | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/Tools/ssl/make_ssl_data.py b/Tools/ssl/make_ssl_data.py new file mode 100644 index 0000000..87b3ec2 --- /dev/null +++ b/Tools/ssl/make_ssl_data.py @@ -0,0 +1,57 @@ +#! /usr/bin/env python3 + +import datetime +import os +import re +import sys + + +def parse_error_codes(h_file, prefix): + pat = re.compile(r"#define\W+(%s([\w]+))\W+(\d+)\b" % re.escape(prefix)) + codes = [] + with open(h_file, "r", encoding="latin1") as f: + for line in f: + match = pat.search(line) + if match: + code, name, num = match.groups() + num = int(num) + codes.append((code, name, num)) + return codes + +if __name__ == "__main__": + openssl_inc = sys.argv[1] + outfile = sys.argv[2] + use_stdout = outfile == '-' + f = sys.stdout if use_stdout else open(outfile, "w") + error_libraries = ( + # (library code, mnemonic, error prefix, header file) + ('ERR_LIB_PEM', 'PEM', 'PEM_R_', 'pem.h'), + ('ERR_LIB_SSL', 'SSL', 'SSL_R_', 'ssl.h'), + ('ERR_LIB_X509', 'X509', 'X509_R_', 'x509.h'), + ) + def w(l): + f.write(l + "\n") + w("/* File generated by Tools/ssl/make_ssl_data.py */") + w("/* Generated on %s */" % datetime.datetime.now().isoformat()) + w("") + + w("static struct py_ssl_library_code library_codes[] = {") + for libcode, mnemo, _, _ in error_libraries: + w(' {"%s", %s},' % (mnemo, libcode)) + w(' { NULL }') + w('};') + w("") + + w("static struct py_ssl_error_code error_codes[] = {") + for libcode, _, prefix, h_file in error_libraries: + codes = parse_error_codes(os.path.join(openssl_inc, h_file), prefix) + for code, name, num in sorted(codes): + w(' #ifdef %s' % (code)) + w(' {"%s", %s, %s},' % (name, libcode, code)) + w(' #else') + w(' {"%s", %s, %d},' % (name, libcode, num)) + w(' #endif') + w(' { NULL }') + w('};') + if not use_stdout: + f.close() |