|
22 | 22 | #define OPENSSL_NO_DEPRECATED 1
|
23 | 23 |
|
24 | 24 | #define PY_SSIZE_T_CLEAN
|
25 |
| -#define NEEDS_PY_IDENTIFIER |
26 | 25 |
|
27 | 26 | #include "Python.h"
|
28 | 27 |
|
@@ -447,10 +446,6 @@ fill_and_set_sslerror(_sslmodulestate *state,
|
447 | 446 | PyObject *err_value = NULL, *reason_obj = NULL, *lib_obj = NULL;
|
448 | 447 | PyObject *verify_obj = NULL, *verify_code_obj = NULL;
|
449 | 448 | PyObject *init_value, *msg, *key;
|
450 |
| - _Py_IDENTIFIER(reason); |
451 |
| - _Py_IDENTIFIER(library); |
452 |
| - _Py_IDENTIFIER(verify_message); |
453 |
| - _Py_IDENTIFIER(verify_code); |
454 | 449 |
|
455 | 450 | if (errcode != 0) {
|
456 | 451 | int lib, reason;
|
@@ -544,20 +539,20 @@ fill_and_set_sslerror(_sslmodulestate *state,
|
544 | 539 |
|
545 | 540 | if (reason_obj == NULL)
|
546 | 541 | reason_obj = Py_None;
|
547 |
| - if (_PyObject_SetAttrId(err_value, &PyId_reason, reason_obj)) |
| 542 | + if (PyObject_SetAttr(err_value, state->str_reason, reason_obj)) |
548 | 543 | goto fail;
|
549 | 544 |
|
550 | 545 | if (lib_obj == NULL)
|
551 | 546 | lib_obj = Py_None;
|
552 |
| - if (_PyObject_SetAttrId(err_value, &PyId_library, lib_obj)) |
| 547 | + if (PyObject_SetAttr(err_value, state->str_library, lib_obj)) |
553 | 548 | goto fail;
|
554 | 549 |
|
555 | 550 | if ((sslsock != NULL) && (type == state->PySSLCertVerificationErrorObject)) {
|
556 | 551 | /* Only set verify code / message for SSLCertVerificationError */
|
557 |
| - if (_PyObject_SetAttrId(err_value, &PyId_verify_code, |
| 552 | + if (PyObject_SetAttr(err_value, state->str_verify_code, |
558 | 553 | verify_code_obj))
|
559 | 554 | goto fail;
|
560 |
| - if (_PyObject_SetAttrId(err_value, &PyId_verify_message, verify_obj)) |
| 555 | + if (PyObject_SetAttr(err_value, state->str_verify_message, verify_obj)) |
561 | 556 | goto fail;
|
562 | 557 | }
|
563 | 558 |
|
@@ -6158,13 +6153,37 @@ sslmodule_init_types(PyObject *module)
|
6158 | 6153 | return 0;
|
6159 | 6154 | }
|
6160 | 6155 |
|
| 6156 | +static int |
| 6157 | +sslmodule_init_strings(PyObject *module) |
| 6158 | +{ |
| 6159 | + _sslmodulestate *state = get_ssl_state(module); |
| 6160 | + state->str_library = PyUnicode_InternFromString("library"); |
| 6161 | + if (state->str_library == NULL) { |
| 6162 | + return -1; |
| 6163 | + } |
| 6164 | + state->str_reason = PyUnicode_InternFromString("reason"); |
| 6165 | + if (state->str_reason == NULL) { |
| 6166 | + return -1; |
| 6167 | + } |
| 6168 | + state->str_verify_message = PyUnicode_InternFromString("verify_message"); |
| 6169 | + if (state->str_verify_message == NULL) { |
| 6170 | + return -1; |
| 6171 | + } |
| 6172 | + state->str_verify_code = PyUnicode_InternFromString("verify_code"); |
| 6173 | + if (state->str_verify_code == NULL) { |
| 6174 | + return -1; |
| 6175 | + } |
| 6176 | + return 0; |
| 6177 | +} |
| 6178 | + |
6161 | 6179 | static PyModuleDef_Slot sslmodule_slots[] = {
|
6162 | 6180 | {Py_mod_exec, sslmodule_init_types},
|
6163 | 6181 | {Py_mod_exec, sslmodule_init_exceptions},
|
6164 | 6182 | {Py_mod_exec, sslmodule_init_socketapi},
|
6165 | 6183 | {Py_mod_exec, sslmodule_init_errorcodes},
|
6166 | 6184 | {Py_mod_exec, sslmodule_init_constants},
|
6167 | 6185 | {Py_mod_exec, sslmodule_init_versioninfo},
|
| 6186 | + {Py_mod_exec, sslmodule_init_strings}, |
6168 | 6187 | {0, NULL}
|
6169 | 6188 | };
|
6170 | 6189 |
|
@@ -6214,7 +6233,10 @@ sslmodule_clear(PyObject *m)
|
6214 | 6233 | Py_CLEAR(state->err_names_to_codes);
|
6215 | 6234 | Py_CLEAR(state->lib_codes_to_names);
|
6216 | 6235 | Py_CLEAR(state->Sock_Type);
|
6217 |
| - |
| 6236 | + Py_CLEAR(state->str_library); |
| 6237 | + Py_CLEAR(state->str_reason); |
| 6238 | + Py_CLEAR(state->str_verify_code); |
| 6239 | + Py_CLEAR(state->str_verify_message); |
6218 | 6240 | return 0;
|
6219 | 6241 | }
|
6220 | 6242 |
|
|
0 commit comments