From a5cd1a56bfc3c4566de2b4c23d355ab6d8f831c4 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Mon, 28 Apr 2025 20:34:20 +0300 Subject: [PATCH] gh-132987: Support __index__() in the stat module Use it for the mode arguments in filemode(), S_IMODE(), S_ISDIR(), etc. --- Modules/_stat.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Modules/_stat.c b/Modules/_stat.c index 13a2bec252f448..f11ca7d23b440d 100644 --- a/Modules/_stat.c +++ b/Modules/_stat.c @@ -295,9 +295,21 @@ _PyLong_AsMode_t(PyObject *op) unsigned long value; mode_t mode; - value = PyLong_AsUnsignedLong(op); - if ((value == (unsigned long)-1) && PyErr_Occurred()) + if (PyLong_Check(op)) { + value = PyLong_AsUnsignedLong(op); + } + else { + op = PyNumber_Index(op); + if (op == NULL) { + return (mode_t)-1; + } + value = PyLong_AsUnsignedLong(op); + Py_DECREF(op); + } + + if ((value == (unsigned long)-1) && PyErr_Occurred()) { return (mode_t)-1; + } mode = (mode_t)value; if ((unsigned long)mode != value) { pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy