mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
gh-132987: Support __index__() in the stat module (GH-133097)
Use it for the mode arguments in filemode(), S_IMODE(), S_ISDIR(), etc.
This commit is contained in:
parent
acb222ce8f
commit
c33efa8735
1 changed files with 14 additions and 2 deletions
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue