https://github.com/python/cpython/commit/0fb4c38c273213394b6c5e28432a3dcfc752d289
commit: 0fb4c38c273213394b6c5e28432a3dcfc752d289
branch: main
author: Serhiy Storchaka <storch...@gmail.com>
committer: serhiy-storchaka <storch...@gmail.com>
date: 2025-04-29T16:28:47+03:00
summary:

gh-132987: Support __index__() in the ssl.SSLContext.options setter (GH-133098)

files:
M Lib/test/test_ssl.py
M Modules/_ssl.c

diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py
index 1aff8e22683af0..395b2ef88ab622 100644
--- a/Lib/test/test_ssl.py
+++ b/Lib/test/test_ssl.py
@@ -986,7 +986,7 @@ def test_options(self):
         self.assertEqual(0, ctx.options & ~ssl.OP_NO_SSLv3)
 
         # invalid options
-        with self.assertRaises(OverflowError):
+        with self.assertRaises(ValueError):
             ctx.options = -1
         with self.assertRaises(OverflowError):
             ctx.options = 2 ** 100
diff --git a/Modules/_ssl.c b/Modules/_ssl.c
index 4c5367c3e5cc19..97a29f4d0e1830 100644
--- a/Modules/_ssl.c
+++ b/Modules/_ssl.c
@@ -27,6 +27,7 @@
 
 #include "Python.h"
 #include "pycore_fileutils.h"     // _PyIsSelectable_fd()
+#include "pycore_long.h"          // _PyLong_UnsignedLongLong_Converter()
 #include "pycore_pyerrors.h"      // _PyErr_ChainExceptions1()
 #include "pycore_time.h"          // _PyDeadline_Init()
 
@@ -3812,7 +3813,6 @@ static int
 _ssl__SSLContext_options_set_impl(PySSLContext *self, PyObject *value)
 /*[clinic end generated code: output=92ca34731ece5dbb input=2b94bf789e9ae5dd]*/
 {
-    PyObject *new_opts_obj;
     unsigned long long new_opts_arg;
     uint64_t new_opts, opts, clear, set;
     uint64_t opt_no = (
@@ -3820,11 +3820,7 @@ _ssl__SSLContext_options_set_impl(PySSLContext *self, 
PyObject *value)
         SSL_OP_NO_TLSv1_1 | SSL_OP_NO_TLSv1_2 | SSL_OP_NO_TLSv1_3
     );
 
-    if (!PyArg_Parse(value, "O!", &PyLong_Type, &new_opts_obj)) {
-        return -1;
-    }
-    new_opts_arg = PyLong_AsUnsignedLongLong(new_opts_obj);
-    if (new_opts_arg == (unsigned long long)-1 && PyErr_Occurred()) {
+    if (!PyArg_Parse(value, "O&", _PyLong_UnsignedLongLong_Converter, 
&new_opts_arg)) {
         return -1;
     }
     Py_BUILD_ASSERT(sizeof(new_opts) >= sizeof(new_opts_arg));

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: arch...@mail-archive.com

Reply via email to