mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
gh-118263: Add additional arguments to path_t (Argument Clinic type) in posixmodule (GH-119608)
This commit is contained in:
parent
ab9b605efa
commit
09a85eaa4c
7 changed files with 317 additions and 270 deletions
|
@ -521,7 +521,7 @@ def expandvars(path):
|
||||||
# Previously, this function also truncated pathnames to 8+3 format,
|
# Previously, this function also truncated pathnames to 8+3 format,
|
||||||
# but as this module is called "ntpath", that's obviously wrong!
|
# but as this module is called "ntpath", that's obviously wrong!
|
||||||
try:
|
try:
|
||||||
from nt import _path_normpath
|
from nt import _path_normpath as normpath
|
||||||
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
def normpath(path):
|
def normpath(path):
|
||||||
|
@ -560,14 +560,6 @@ except ImportError:
|
||||||
comps.append(curdir)
|
comps.append(curdir)
|
||||||
return prefix + sep.join(comps)
|
return prefix + sep.join(comps)
|
||||||
|
|
||||||
else:
|
|
||||||
def normpath(path):
|
|
||||||
"""Normalize path, eliminating double slashes, etc."""
|
|
||||||
path = os.fspath(path)
|
|
||||||
if isinstance(path, bytes):
|
|
||||||
return os.fsencode(_path_normpath(os.fsdecode(path))) or b"."
|
|
||||||
return _path_normpath(path) or "."
|
|
||||||
|
|
||||||
|
|
||||||
def _abspath_fallback(path):
|
def _abspath_fallback(path):
|
||||||
"""Return the absolute version of a path as a fallback function in case
|
"""Return the absolute version of a path as a fallback function in case
|
||||||
|
|
|
@ -371,7 +371,7 @@ def expandvars(path):
|
||||||
# if it contains symbolic links!
|
# if it contains symbolic links!
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from posix import _path_normpath
|
from posix import _path_normpath as normpath
|
||||||
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
def normpath(path):
|
def normpath(path):
|
||||||
|
@ -404,14 +404,6 @@ except ImportError:
|
||||||
path = initial_slashes + sep.join(comps)
|
path = initial_slashes + sep.join(comps)
|
||||||
return path or dot
|
return path or dot
|
||||||
|
|
||||||
else:
|
|
||||||
def normpath(path):
|
|
||||||
"""Normalize path, eliminating double slashes, etc."""
|
|
||||||
path = os.fspath(path)
|
|
||||||
if isinstance(path, bytes):
|
|
||||||
return os.fsencode(_path_normpath(os.fsdecode(path))) or b"."
|
|
||||||
return _path_normpath(path) or "."
|
|
||||||
|
|
||||||
|
|
||||||
def abspath(path):
|
def abspath(path):
|
||||||
"""Return an absolute path."""
|
"""Return an absolute path."""
|
||||||
|
|
|
@ -1010,6 +1010,8 @@ class TestNtpath(NtpathTestCase):
|
||||||
# There are fast paths of these functions implemented in posixmodule.c.
|
# There are fast paths of these functions implemented in posixmodule.c.
|
||||||
# Confirm that they are being used, and not the Python fallbacks in
|
# Confirm that they are being used, and not the Python fallbacks in
|
||||||
# genericpath.py.
|
# genericpath.py.
|
||||||
|
self.assertTrue(os.path.normpath is nt._path_normpath)
|
||||||
|
self.assertFalse(inspect.isfunction(os.path.normpath))
|
||||||
self.assertTrue(os.path.isdir is nt._path_isdir)
|
self.assertTrue(os.path.isdir is nt._path_isdir)
|
||||||
self.assertFalse(inspect.isfunction(os.path.isdir))
|
self.assertFalse(inspect.isfunction(os.path.isdir))
|
||||||
self.assertTrue(os.path.isfile is nt._path_isfile)
|
self.assertTrue(os.path.isfile is nt._path_isfile)
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import inspect
|
||||||
import os
|
import os
|
||||||
import posixpath
|
import posixpath
|
||||||
import sys
|
import sys
|
||||||
|
@ -5,7 +6,7 @@ import unittest
|
||||||
from posixpath import realpath, abspath, dirname, basename
|
from posixpath import realpath, abspath, dirname, basename
|
||||||
from test import test_genericpath
|
from test import test_genericpath
|
||||||
from test.support import import_helper
|
from test.support import import_helper
|
||||||
from test.support import os_helper
|
from test.support import cpython_only, os_helper
|
||||||
from test.support.os_helper import FakePath
|
from test.support.os_helper import FakePath
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
|
@ -273,6 +274,14 @@ class PosixPathTest(unittest.TestCase):
|
||||||
def test_isjunction(self):
|
def test_isjunction(self):
|
||||||
self.assertFalse(posixpath.isjunction(ABSTFN))
|
self.assertFalse(posixpath.isjunction(ABSTFN))
|
||||||
|
|
||||||
|
@unittest.skipIf(sys.platform == 'win32', "Fast paths are not for win32")
|
||||||
|
@cpython_only
|
||||||
|
def test_fast_paths_in_use(self):
|
||||||
|
# There are fast paths of these functions implemented in posixmodule.c.
|
||||||
|
# Confirm that they are being used, and not the Python fallbacks
|
||||||
|
self.assertTrue(os.path.normpath is posix._path_normpath)
|
||||||
|
self.assertFalse(inspect.isfunction(os.path.normpath))
|
||||||
|
|
||||||
def test_expanduser(self):
|
def test_expanduser(self):
|
||||||
self.assertEqual(posixpath.expanduser("foo"), "foo")
|
self.assertEqual(posixpath.expanduser("foo"), "foo")
|
||||||
self.assertEqual(posixpath.expanduser(b"foo"), b"foo")
|
self.assertEqual(posixpath.expanduser(b"foo"), b"foo")
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Speed up :func:`os.path.normpath` with a direct C call.
|
181
Modules/clinic/posixmodule.c.h
generated
181
Modules/clinic/posixmodule.c.h
generated
|
@ -70,7 +70,7 @@ os_stat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwn
|
||||||
#undef KWTUPLE
|
#undef KWTUPLE
|
||||||
PyObject *argsbuf[3];
|
PyObject *argsbuf[3];
|
||||||
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
|
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
|
||||||
path_t path = PATH_T_INITIALIZE("stat", "path", 0, 1);
|
path_t path = PATH_T_INITIALIZE_P("stat", "path", 0, 0, 0, 1);
|
||||||
int dir_fd = DEFAULT_DIR_FD;
|
int dir_fd = DEFAULT_DIR_FD;
|
||||||
int follow_symlinks = 1;
|
int follow_symlinks = 1;
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ os_lstat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kw
|
||||||
#undef KWTUPLE
|
#undef KWTUPLE
|
||||||
PyObject *argsbuf[2];
|
PyObject *argsbuf[2];
|
||||||
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
|
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
|
||||||
path_t path = PATH_T_INITIALIZE("lstat", "path", 0, 0);
|
path_t path = PATH_T_INITIALIZE_P("lstat", "path", 0, 0, 0, 0);
|
||||||
int dir_fd = DEFAULT_DIR_FD;
|
int dir_fd = DEFAULT_DIR_FD;
|
||||||
|
|
||||||
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
|
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
|
||||||
|
@ -248,7 +248,7 @@ os_access(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *k
|
||||||
#undef KWTUPLE
|
#undef KWTUPLE
|
||||||
PyObject *argsbuf[5];
|
PyObject *argsbuf[5];
|
||||||
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
|
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
|
||||||
path_t path = PATH_T_INITIALIZE("access", "path", 0, 0);
|
path_t path = PATH_T_INITIALIZE_P("access", "path", 0, 0, 0, 0);
|
||||||
int mode;
|
int mode;
|
||||||
int dir_fd = DEFAULT_DIR_FD;
|
int dir_fd = DEFAULT_DIR_FD;
|
||||||
int effective_ids = 0;
|
int effective_ids = 0;
|
||||||
|
@ -407,7 +407,7 @@ os_chdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kw
|
||||||
};
|
};
|
||||||
#undef KWTUPLE
|
#undef KWTUPLE
|
||||||
PyObject *argsbuf[1];
|
PyObject *argsbuf[1];
|
||||||
path_t path = PATH_T_INITIALIZE("chdir", "path", 0, PATH_HAVE_FCHDIR);
|
path_t path = PATH_T_INITIALIZE_P("chdir", "path", 0, 0, 0, PATH_HAVE_FCHDIR);
|
||||||
|
|
||||||
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
|
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
|
||||||
if (!args) {
|
if (!args) {
|
||||||
|
@ -556,7 +556,7 @@ os_chmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kw
|
||||||
#undef KWTUPLE
|
#undef KWTUPLE
|
||||||
PyObject *argsbuf[4];
|
PyObject *argsbuf[4];
|
||||||
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
|
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
|
||||||
path_t path = PATH_T_INITIALIZE("chmod", "path", 0, PATH_HAVE_FCHMOD);
|
path_t path = PATH_T_INITIALIZE_P("chmod", "path", 0, 0, 0, PATH_HAVE_FCHMOD);
|
||||||
int mode;
|
int mode;
|
||||||
int dir_fd = DEFAULT_DIR_FD;
|
int dir_fd = DEFAULT_DIR_FD;
|
||||||
int follow_symlinks = 1;
|
int follow_symlinks = 1;
|
||||||
|
@ -721,7 +721,7 @@ os_lchmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *k
|
||||||
};
|
};
|
||||||
#undef KWTUPLE
|
#undef KWTUPLE
|
||||||
PyObject *argsbuf[2];
|
PyObject *argsbuf[2];
|
||||||
path_t path = PATH_T_INITIALIZE("lchmod", "path", 0, 0);
|
path_t path = PATH_T_INITIALIZE_P("lchmod", "path", 0, 0, 0, 0);
|
||||||
int mode;
|
int mode;
|
||||||
|
|
||||||
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
|
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
|
||||||
|
@ -798,7 +798,7 @@ os_chflags(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *
|
||||||
#undef KWTUPLE
|
#undef KWTUPLE
|
||||||
PyObject *argsbuf[3];
|
PyObject *argsbuf[3];
|
||||||
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
|
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
|
||||||
path_t path = PATH_T_INITIALIZE("chflags", "path", 0, 0);
|
path_t path = PATH_T_INITIALIZE_P("chflags", "path", 0, 0, 0, 0);
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
int follow_symlinks = 1;
|
int follow_symlinks = 1;
|
||||||
|
|
||||||
|
@ -880,7 +880,7 @@ os_lchflags(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject
|
||||||
};
|
};
|
||||||
#undef KWTUPLE
|
#undef KWTUPLE
|
||||||
PyObject *argsbuf[2];
|
PyObject *argsbuf[2];
|
||||||
path_t path = PATH_T_INITIALIZE("lchflags", "path", 0, 0);
|
path_t path = PATH_T_INITIALIZE_P("lchflags", "path", 0, 0, 0, 0);
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
|
|
||||||
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
|
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
|
||||||
|
@ -950,7 +950,7 @@ os_chroot(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *k
|
||||||
};
|
};
|
||||||
#undef KWTUPLE
|
#undef KWTUPLE
|
||||||
PyObject *argsbuf[1];
|
PyObject *argsbuf[1];
|
||||||
path_t path = PATH_T_INITIALIZE("chroot", "path", 0, 0);
|
path_t path = PATH_T_INITIALIZE_P("chroot", "path", 0, 0, 0, 0);
|
||||||
|
|
||||||
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
|
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
|
||||||
if (!args) {
|
if (!args) {
|
||||||
|
@ -1184,7 +1184,7 @@ os_chown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kw
|
||||||
#undef KWTUPLE
|
#undef KWTUPLE
|
||||||
PyObject *argsbuf[5];
|
PyObject *argsbuf[5];
|
||||||
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
|
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
|
||||||
path_t path = PATH_T_INITIALIZE("chown", "path", 0, PATH_HAVE_FCHOWN);
|
path_t path = PATH_T_INITIALIZE_P("chown", "path", 0, 0, 0, PATH_HAVE_FCHOWN);
|
||||||
uid_t uid;
|
uid_t uid;
|
||||||
gid_t gid;
|
gid_t gid;
|
||||||
int dir_fd = DEFAULT_DIR_FD;
|
int dir_fd = DEFAULT_DIR_FD;
|
||||||
|
@ -1349,7 +1349,7 @@ os_lchown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *k
|
||||||
};
|
};
|
||||||
#undef KWTUPLE
|
#undef KWTUPLE
|
||||||
PyObject *argsbuf[3];
|
PyObject *argsbuf[3];
|
||||||
path_t path = PATH_T_INITIALIZE("lchown", "path", 0, 0);
|
path_t path = PATH_T_INITIALIZE_P("lchown", "path", 0, 0, 0, 0);
|
||||||
uid_t uid;
|
uid_t uid;
|
||||||
gid_t gid;
|
gid_t gid;
|
||||||
|
|
||||||
|
@ -1470,8 +1470,8 @@ os_link(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwn
|
||||||
#undef KWTUPLE
|
#undef KWTUPLE
|
||||||
PyObject *argsbuf[5];
|
PyObject *argsbuf[5];
|
||||||
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
|
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
|
||||||
path_t src = PATH_T_INITIALIZE("link", "src", 0, 0);
|
path_t src = PATH_T_INITIALIZE_P("link", "src", 0, 0, 0, 0);
|
||||||
path_t dst = PATH_T_INITIALIZE("link", "dst", 0, 0);
|
path_t dst = PATH_T_INITIALIZE_P("link", "dst", 0, 0, 0, 0);
|
||||||
int src_dir_fd = DEFAULT_DIR_FD;
|
int src_dir_fd = DEFAULT_DIR_FD;
|
||||||
int dst_dir_fd = DEFAULT_DIR_FD;
|
int dst_dir_fd = DEFAULT_DIR_FD;
|
||||||
int follow_symlinks = 1;
|
int follow_symlinks = 1;
|
||||||
|
@ -1577,7 +1577,7 @@ os_listdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *
|
||||||
#undef KWTUPLE
|
#undef KWTUPLE
|
||||||
PyObject *argsbuf[1];
|
PyObject *argsbuf[1];
|
||||||
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
|
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
|
||||||
path_t path = PATH_T_INITIALIZE("listdir", "path", 1, PATH_HAVE_FDOPENDIR);
|
path_t path = PATH_T_INITIALIZE_P("listdir", "path", 1, 0, 0, PATH_HAVE_FDOPENDIR);
|
||||||
|
|
||||||
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
|
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
|
||||||
if (!args) {
|
if (!args) {
|
||||||
|
@ -1693,7 +1693,7 @@ os_listmounts(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObjec
|
||||||
};
|
};
|
||||||
#undef KWTUPLE
|
#undef KWTUPLE
|
||||||
PyObject *argsbuf[1];
|
PyObject *argsbuf[1];
|
||||||
path_t volume = PATH_T_INITIALIZE("listmounts", "volume", 0, 0);
|
path_t volume = PATH_T_INITIALIZE_P("listmounts", "volume", 0, 0, 0, 0);
|
||||||
|
|
||||||
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
|
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
|
||||||
if (!args) {
|
if (!args) {
|
||||||
|
@ -1757,7 +1757,7 @@ os__path_isdevdrive(PyObject *module, PyObject *const *args, Py_ssize_t nargs, P
|
||||||
};
|
};
|
||||||
#undef KWTUPLE
|
#undef KWTUPLE
|
||||||
PyObject *argsbuf[1];
|
PyObject *argsbuf[1];
|
||||||
path_t path = PATH_T_INITIALIZE("_path_isdevdrive", "path", 0, 0);
|
path_t path = PATH_T_INITIALIZE_P("_path_isdevdrive", "path", 0, 0, 0, 0);
|
||||||
|
|
||||||
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
|
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
|
||||||
if (!args) {
|
if (!args) {
|
||||||
|
@ -1794,7 +1794,7 @@ static PyObject *
|
||||||
os__getfullpathname(PyObject *module, PyObject *arg)
|
os__getfullpathname(PyObject *module, PyObject *arg)
|
||||||
{
|
{
|
||||||
PyObject *return_value = NULL;
|
PyObject *return_value = NULL;
|
||||||
path_t path = PATH_T_INITIALIZE("_getfullpathname", "path", 0, 0);
|
path_t path = PATH_T_INITIALIZE_P("_getfullpathname", "path", 0, 0, 0, 0);
|
||||||
|
|
||||||
if (!path_converter(arg, &path)) {
|
if (!path_converter(arg, &path)) {
|
||||||
goto exit;
|
goto exit;
|
||||||
|
@ -1828,7 +1828,7 @@ static PyObject *
|
||||||
os__getfinalpathname(PyObject *module, PyObject *arg)
|
os__getfinalpathname(PyObject *module, PyObject *arg)
|
||||||
{
|
{
|
||||||
PyObject *return_value = NULL;
|
PyObject *return_value = NULL;
|
||||||
path_t path = PATH_T_INITIALIZE("_getfinalpathname", "path", 0, 0);
|
path_t path = PATH_T_INITIALIZE_P("_getfinalpathname", "path", 0, 0, 0, 0);
|
||||||
|
|
||||||
if (!path_converter(arg, &path)) {
|
if (!path_converter(arg, &path)) {
|
||||||
goto exit;
|
goto exit;
|
||||||
|
@ -1888,7 +1888,7 @@ os__getvolumepathname(PyObject *module, PyObject *const *args, Py_ssize_t nargs,
|
||||||
};
|
};
|
||||||
#undef KWTUPLE
|
#undef KWTUPLE
|
||||||
PyObject *argsbuf[1];
|
PyObject *argsbuf[1];
|
||||||
path_t path = PATH_T_INITIALIZE("_getvolumepathname", "path", 0, 0);
|
path_t path = PATH_T_INITIALIZE_P("_getvolumepathname", "path", 0, 0, 0, 0);
|
||||||
|
|
||||||
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
|
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
|
||||||
if (!args) {
|
if (!args) {
|
||||||
|
@ -1952,7 +1952,7 @@ os__path_splitroot(PyObject *module, PyObject *const *args, Py_ssize_t nargs, Py
|
||||||
};
|
};
|
||||||
#undef KWTUPLE
|
#undef KWTUPLE
|
||||||
PyObject *argsbuf[1];
|
PyObject *argsbuf[1];
|
||||||
path_t path = PATH_T_INITIALIZE("_path_splitroot", "path", 0, 0);
|
path_t path = PATH_T_INITIALIZE_P("_path_splitroot", "path", 0, 0, 0, 0);
|
||||||
|
|
||||||
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
|
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
|
||||||
if (!args) {
|
if (!args) {
|
||||||
|
@ -1984,21 +1984,28 @@ PyDoc_STRVAR(os__path_exists__doc__,
|
||||||
{"_path_exists", (PyCFunction)os__path_exists, METH_O, os__path_exists__doc__},
|
{"_path_exists", (PyCFunction)os__path_exists, METH_O, os__path_exists__doc__},
|
||||||
|
|
||||||
static int
|
static int
|
||||||
os__path_exists_impl(PyObject *module, PyObject *path);
|
os__path_exists_impl(PyObject *module, path_t *path);
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
os__path_exists(PyObject *module, PyObject *path)
|
os__path_exists(PyObject *module, PyObject *arg)
|
||||||
{
|
{
|
||||||
PyObject *return_value = NULL;
|
PyObject *return_value = NULL;
|
||||||
|
path_t path = PATH_T_INITIALIZE_P("_path_exists", "path", 0, 0, 1, 1);
|
||||||
int _return_value;
|
int _return_value;
|
||||||
|
|
||||||
_return_value = os__path_exists_impl(module, path);
|
if (!path_converter(arg, &path)) {
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
_return_value = os__path_exists_impl(module, &path);
|
||||||
if ((_return_value == -1) && PyErr_Occurred()) {
|
if ((_return_value == -1) && PyErr_Occurred()) {
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
return_value = PyBool_FromLong((long)_return_value);
|
return_value = PyBool_FromLong((long)_return_value);
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
/* Cleanup for path */
|
||||||
|
path_cleanup(&path);
|
||||||
|
|
||||||
return return_value;
|
return return_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2016,7 +2023,7 @@ PyDoc_STRVAR(os__path_isdir__doc__,
|
||||||
{"_path_isdir", _PyCFunction_CAST(os__path_isdir), METH_FASTCALL|METH_KEYWORDS, os__path_isdir__doc__},
|
{"_path_isdir", _PyCFunction_CAST(os__path_isdir), METH_FASTCALL|METH_KEYWORDS, os__path_isdir__doc__},
|
||||||
|
|
||||||
static int
|
static int
|
||||||
os__path_isdir_impl(PyObject *module, PyObject *path);
|
os__path_isdir_impl(PyObject *module, path_t *path);
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
os__path_isdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
os__path_isdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
||||||
|
@ -2048,21 +2055,26 @@ os__path_isdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObje
|
||||||
};
|
};
|
||||||
#undef KWTUPLE
|
#undef KWTUPLE
|
||||||
PyObject *argsbuf[1];
|
PyObject *argsbuf[1];
|
||||||
PyObject *path;
|
path_t path = PATH_T_INITIALIZE_P("_path_isdir", "path", 0, 0, 1, 1);
|
||||||
int _return_value;
|
int _return_value;
|
||||||
|
|
||||||
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
|
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
|
||||||
if (!args) {
|
if (!args) {
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
path = args[0];
|
if (!path_converter(args[0], &path)) {
|
||||||
_return_value = os__path_isdir_impl(module, path);
|
goto exit;
|
||||||
|
}
|
||||||
|
_return_value = os__path_isdir_impl(module, &path);
|
||||||
if ((_return_value == -1) && PyErr_Occurred()) {
|
if ((_return_value == -1) && PyErr_Occurred()) {
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
return_value = PyBool_FromLong((long)_return_value);
|
return_value = PyBool_FromLong((long)_return_value);
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
/* Cleanup for path */
|
||||||
|
path_cleanup(&path);
|
||||||
|
|
||||||
return return_value;
|
return return_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2080,7 +2092,7 @@ PyDoc_STRVAR(os__path_isfile__doc__,
|
||||||
{"_path_isfile", _PyCFunction_CAST(os__path_isfile), METH_FASTCALL|METH_KEYWORDS, os__path_isfile__doc__},
|
{"_path_isfile", _PyCFunction_CAST(os__path_isfile), METH_FASTCALL|METH_KEYWORDS, os__path_isfile__doc__},
|
||||||
|
|
||||||
static int
|
static int
|
||||||
os__path_isfile_impl(PyObject *module, PyObject *path);
|
os__path_isfile_impl(PyObject *module, path_t *path);
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
os__path_isfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
os__path_isfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
||||||
|
@ -2112,21 +2124,26 @@ os__path_isfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObj
|
||||||
};
|
};
|
||||||
#undef KWTUPLE
|
#undef KWTUPLE
|
||||||
PyObject *argsbuf[1];
|
PyObject *argsbuf[1];
|
||||||
PyObject *path;
|
path_t path = PATH_T_INITIALIZE_P("_path_isfile", "path", 0, 0, 1, 1);
|
||||||
int _return_value;
|
int _return_value;
|
||||||
|
|
||||||
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
|
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
|
||||||
if (!args) {
|
if (!args) {
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
path = args[0];
|
if (!path_converter(args[0], &path)) {
|
||||||
_return_value = os__path_isfile_impl(module, path);
|
goto exit;
|
||||||
|
}
|
||||||
|
_return_value = os__path_isfile_impl(module, &path);
|
||||||
if ((_return_value == -1) && PyErr_Occurred()) {
|
if ((_return_value == -1) && PyErr_Occurred()) {
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
return_value = PyBool_FromLong((long)_return_value);
|
return_value = PyBool_FromLong((long)_return_value);
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
/* Cleanup for path */
|
||||||
|
path_cleanup(&path);
|
||||||
|
|
||||||
return return_value;
|
return return_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2144,7 +2161,7 @@ PyDoc_STRVAR(os__path_islink__doc__,
|
||||||
{"_path_islink", _PyCFunction_CAST(os__path_islink), METH_FASTCALL|METH_KEYWORDS, os__path_islink__doc__},
|
{"_path_islink", _PyCFunction_CAST(os__path_islink), METH_FASTCALL|METH_KEYWORDS, os__path_islink__doc__},
|
||||||
|
|
||||||
static int
|
static int
|
||||||
os__path_islink_impl(PyObject *module, PyObject *path);
|
os__path_islink_impl(PyObject *module, path_t *path);
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
os__path_islink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
os__path_islink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
||||||
|
@ -2176,21 +2193,26 @@ os__path_islink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObj
|
||||||
};
|
};
|
||||||
#undef KWTUPLE
|
#undef KWTUPLE
|
||||||
PyObject *argsbuf[1];
|
PyObject *argsbuf[1];
|
||||||
PyObject *path;
|
path_t path = PATH_T_INITIALIZE_P("_path_islink", "path", 0, 0, 1, 1);
|
||||||
int _return_value;
|
int _return_value;
|
||||||
|
|
||||||
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
|
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
|
||||||
if (!args) {
|
if (!args) {
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
path = args[0];
|
if (!path_converter(args[0], &path)) {
|
||||||
_return_value = os__path_islink_impl(module, path);
|
goto exit;
|
||||||
|
}
|
||||||
|
_return_value = os__path_islink_impl(module, &path);
|
||||||
if ((_return_value == -1) && PyErr_Occurred()) {
|
if ((_return_value == -1) && PyErr_Occurred()) {
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
return_value = PyBool_FromLong((long)_return_value);
|
return_value = PyBool_FromLong((long)_return_value);
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
/* Cleanup for path */
|
||||||
|
path_cleanup(&path);
|
||||||
|
|
||||||
return return_value;
|
return return_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2200,13 +2222,13 @@ PyDoc_STRVAR(os__path_normpath__doc__,
|
||||||
"_path_normpath($module, /, path)\n"
|
"_path_normpath($module, /, path)\n"
|
||||||
"--\n"
|
"--\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Basic path normalization.");
|
"Normalize path, eliminating double slashes, etc.");
|
||||||
|
|
||||||
#define OS__PATH_NORMPATH_METHODDEF \
|
#define OS__PATH_NORMPATH_METHODDEF \
|
||||||
{"_path_normpath", _PyCFunction_CAST(os__path_normpath), METH_FASTCALL|METH_KEYWORDS, os__path_normpath__doc__},
|
{"_path_normpath", _PyCFunction_CAST(os__path_normpath), METH_FASTCALL|METH_KEYWORDS, os__path_normpath__doc__},
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
os__path_normpath_impl(PyObject *module, PyObject *path);
|
os__path_normpath_impl(PyObject *module, path_t *path);
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
os__path_normpath(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
os__path_normpath(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
||||||
|
@ -2238,16 +2260,21 @@ os__path_normpath(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyO
|
||||||
};
|
};
|
||||||
#undef KWTUPLE
|
#undef KWTUPLE
|
||||||
PyObject *argsbuf[1];
|
PyObject *argsbuf[1];
|
||||||
PyObject *path;
|
path_t path = PATH_T_INITIALIZE("_path_normpath", "path", 0, 1, 1, 0, 0);
|
||||||
|
|
||||||
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
|
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
|
||||||
if (!args) {
|
if (!args) {
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
path = args[0];
|
if (!path_converter(args[0], &path)) {
|
||||||
return_value = os__path_normpath_impl(module, path);
|
goto exit;
|
||||||
|
}
|
||||||
|
return_value = os__path_normpath_impl(module, &path);
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
/* Cleanup for path */
|
||||||
|
path_cleanup(&path);
|
||||||
|
|
||||||
return return_value;
|
return return_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2302,7 +2329,7 @@ os_mkdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kw
|
||||||
#undef KWTUPLE
|
#undef KWTUPLE
|
||||||
PyObject *argsbuf[3];
|
PyObject *argsbuf[3];
|
||||||
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
|
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
|
||||||
path_t path = PATH_T_INITIALIZE("mkdir", "path", 0, 0);
|
path_t path = PATH_T_INITIALIZE_P("mkdir", "path", 0, 0, 0, 0);
|
||||||
int mode = 511;
|
int mode = 511;
|
||||||
int dir_fd = DEFAULT_DIR_FD;
|
int dir_fd = DEFAULT_DIR_FD;
|
||||||
|
|
||||||
|
@ -2563,8 +2590,8 @@ os_rename(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *k
|
||||||
#undef KWTUPLE
|
#undef KWTUPLE
|
||||||
PyObject *argsbuf[4];
|
PyObject *argsbuf[4];
|
||||||
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
|
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
|
||||||
path_t src = PATH_T_INITIALIZE("rename", "src", 0, 0);
|
path_t src = PATH_T_INITIALIZE_P("rename", "src", 0, 0, 0, 0);
|
||||||
path_t dst = PATH_T_INITIALIZE("rename", "dst", 0, 0);
|
path_t dst = PATH_T_INITIALIZE_P("rename", "dst", 0, 0, 0, 0);
|
||||||
int src_dir_fd = DEFAULT_DIR_FD;
|
int src_dir_fd = DEFAULT_DIR_FD;
|
||||||
int dst_dir_fd = DEFAULT_DIR_FD;
|
int dst_dir_fd = DEFAULT_DIR_FD;
|
||||||
|
|
||||||
|
@ -2654,8 +2681,8 @@ os_replace(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *
|
||||||
#undef KWTUPLE
|
#undef KWTUPLE
|
||||||
PyObject *argsbuf[4];
|
PyObject *argsbuf[4];
|
||||||
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
|
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
|
||||||
path_t src = PATH_T_INITIALIZE("replace", "src", 0, 0);
|
path_t src = PATH_T_INITIALIZE_P("replace", "src", 0, 0, 0, 0);
|
||||||
path_t dst = PATH_T_INITIALIZE("replace", "dst", 0, 0);
|
path_t dst = PATH_T_INITIALIZE_P("replace", "dst", 0, 0, 0, 0);
|
||||||
int src_dir_fd = DEFAULT_DIR_FD;
|
int src_dir_fd = DEFAULT_DIR_FD;
|
||||||
int dst_dir_fd = DEFAULT_DIR_FD;
|
int dst_dir_fd = DEFAULT_DIR_FD;
|
||||||
|
|
||||||
|
@ -2743,7 +2770,7 @@ os_rmdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kw
|
||||||
#undef KWTUPLE
|
#undef KWTUPLE
|
||||||
PyObject *argsbuf[2];
|
PyObject *argsbuf[2];
|
||||||
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
|
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
|
||||||
path_t path = PATH_T_INITIALIZE("rmdir", "path", 0, 0);
|
path_t path = PATH_T_INITIALIZE_P("rmdir", "path", 0, 0, 0, 0);
|
||||||
int dir_fd = DEFAULT_DIR_FD;
|
int dir_fd = DEFAULT_DIR_FD;
|
||||||
|
|
||||||
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
|
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
|
||||||
|
@ -2992,7 +3019,7 @@ os_unlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *k
|
||||||
#undef KWTUPLE
|
#undef KWTUPLE
|
||||||
PyObject *argsbuf[2];
|
PyObject *argsbuf[2];
|
||||||
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
|
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
|
||||||
path_t path = PATH_T_INITIALIZE("unlink", "path", 0, 0);
|
path_t path = PATH_T_INITIALIZE_P("unlink", "path", 0, 0, 0, 0);
|
||||||
int dir_fd = DEFAULT_DIR_FD;
|
int dir_fd = DEFAULT_DIR_FD;
|
||||||
|
|
||||||
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
|
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
|
||||||
|
@ -3066,7 +3093,7 @@ os_remove(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *k
|
||||||
#undef KWTUPLE
|
#undef KWTUPLE
|
||||||
PyObject *argsbuf[2];
|
PyObject *argsbuf[2];
|
||||||
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
|
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
|
||||||
path_t path = PATH_T_INITIALIZE("remove", "path", 0, 0);
|
path_t path = PATH_T_INITIALIZE_P("remove", "path", 0, 0, 0, 0);
|
||||||
int dir_fd = DEFAULT_DIR_FD;
|
int dir_fd = DEFAULT_DIR_FD;
|
||||||
|
|
||||||
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
|
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
|
||||||
|
@ -3184,7 +3211,7 @@ os_utime(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kw
|
||||||
#undef KWTUPLE
|
#undef KWTUPLE
|
||||||
PyObject *argsbuf[5];
|
PyObject *argsbuf[5];
|
||||||
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
|
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
|
||||||
path_t path = PATH_T_INITIALIZE("utime", "path", 0, PATH_UTIME_HAVE_FD);
|
path_t path = PATH_T_INITIALIZE_P("utime", "path", 0, 0, 0, PATH_UTIME_HAVE_FD);
|
||||||
PyObject *times = Py_None;
|
PyObject *times = Py_None;
|
||||||
PyObject *ns = NULL;
|
PyObject *ns = NULL;
|
||||||
int dir_fd = DEFAULT_DIR_FD;
|
int dir_fd = DEFAULT_DIR_FD;
|
||||||
|
@ -3319,7 +3346,7 @@ static PyObject *
|
||||||
os_execv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
os_execv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
||||||
{
|
{
|
||||||
PyObject *return_value = NULL;
|
PyObject *return_value = NULL;
|
||||||
path_t path = PATH_T_INITIALIZE("execv", "path", 0, 0);
|
path_t path = PATH_T_INITIALIZE_P("execv", "path", 0, 0, 0, 0);
|
||||||
PyObject *argv;
|
PyObject *argv;
|
||||||
|
|
||||||
if (!_PyArg_CheckPositional("execv", nargs, 2, 2)) {
|
if (!_PyArg_CheckPositional("execv", nargs, 2, 2)) {
|
||||||
|
@ -3391,7 +3418,7 @@ os_execve(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *k
|
||||||
};
|
};
|
||||||
#undef KWTUPLE
|
#undef KWTUPLE
|
||||||
PyObject *argsbuf[3];
|
PyObject *argsbuf[3];
|
||||||
path_t path = PATH_T_INITIALIZE("execve", "path", 0, PATH_HAVE_FEXECVE);
|
path_t path = PATH_T_INITIALIZE_P("execve", "path", 0, 0, 0, PATH_HAVE_FEXECVE);
|
||||||
PyObject *argv;
|
PyObject *argv;
|
||||||
PyObject *env;
|
PyObject *env;
|
||||||
|
|
||||||
|
@ -3487,7 +3514,7 @@ os_posix_spawn(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObje
|
||||||
#undef KWTUPLE
|
#undef KWTUPLE
|
||||||
PyObject *argsbuf[10];
|
PyObject *argsbuf[10];
|
||||||
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
|
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
|
||||||
path_t path = PATH_T_INITIALIZE("posix_spawn", "path", 0, 0);
|
path_t path = PATH_T_INITIALIZE_P("posix_spawn", "path", 0, 0, 0, 0);
|
||||||
PyObject *argv;
|
PyObject *argv;
|
||||||
PyObject *env;
|
PyObject *env;
|
||||||
PyObject *file_actions = NULL;
|
PyObject *file_actions = NULL;
|
||||||
|
@ -3637,7 +3664,7 @@ os_posix_spawnp(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObj
|
||||||
#undef KWTUPLE
|
#undef KWTUPLE
|
||||||
PyObject *argsbuf[10];
|
PyObject *argsbuf[10];
|
||||||
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
|
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
|
||||||
path_t path = PATH_T_INITIALIZE("posix_spawnp", "path", 0, 0);
|
path_t path = PATH_T_INITIALIZE_P("posix_spawnp", "path", 0, 0, 0, 0);
|
||||||
PyObject *argv;
|
PyObject *argv;
|
||||||
PyObject *env;
|
PyObject *env;
|
||||||
PyObject *file_actions = NULL;
|
PyObject *file_actions = NULL;
|
||||||
|
@ -3741,7 +3768,7 @@ os_spawnv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
||||||
{
|
{
|
||||||
PyObject *return_value = NULL;
|
PyObject *return_value = NULL;
|
||||||
int mode;
|
int mode;
|
||||||
path_t path = PATH_T_INITIALIZE("spawnv", "path", 0, 0);
|
path_t path = PATH_T_INITIALIZE_P("spawnv", "path", 0, 0, 0, 0);
|
||||||
PyObject *argv;
|
PyObject *argv;
|
||||||
|
|
||||||
if (!_PyArg_CheckPositional("spawnv", nargs, 3, 3)) {
|
if (!_PyArg_CheckPositional("spawnv", nargs, 3, 3)) {
|
||||||
|
@ -3795,7 +3822,7 @@ os_spawnve(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
||||||
{
|
{
|
||||||
PyObject *return_value = NULL;
|
PyObject *return_value = NULL;
|
||||||
int mode;
|
int mode;
|
||||||
path_t path = PATH_T_INITIALIZE("spawnve", "path", 0, 0);
|
path_t path = PATH_T_INITIALIZE_P("spawnve", "path", 0, 0, 0, 0);
|
||||||
PyObject *argv;
|
PyObject *argv;
|
||||||
PyObject *env;
|
PyObject *env;
|
||||||
|
|
||||||
|
@ -5816,7 +5843,7 @@ os_readlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject
|
||||||
#undef KWTUPLE
|
#undef KWTUPLE
|
||||||
PyObject *argsbuf[2];
|
PyObject *argsbuf[2];
|
||||||
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
|
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
|
||||||
path_t path = PATH_T_INITIALIZE("readlink", "path", 0, 0);
|
path_t path = PATH_T_INITIALIZE_P("readlink", "path", 0, 0, 0, 0);
|
||||||
int dir_fd = DEFAULT_DIR_FD;
|
int dir_fd = DEFAULT_DIR_FD;
|
||||||
|
|
||||||
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
|
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
|
||||||
|
@ -5900,8 +5927,8 @@ os_symlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *
|
||||||
#undef KWTUPLE
|
#undef KWTUPLE
|
||||||
PyObject *argsbuf[4];
|
PyObject *argsbuf[4];
|
||||||
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
|
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
|
||||||
path_t src = PATH_T_INITIALIZE("symlink", "src", 0, 0);
|
path_t src = PATH_T_INITIALIZE_P("symlink", "src", 0, 0, 0, 0);
|
||||||
path_t dst = PATH_T_INITIALIZE("symlink", "dst", 0, 0);
|
path_t dst = PATH_T_INITIALIZE_P("symlink", "dst", 0, 0, 0, 0);
|
||||||
int target_is_directory = 0;
|
int target_is_directory = 0;
|
||||||
int dir_fd = DEFAULT_DIR_FD;
|
int dir_fd = DEFAULT_DIR_FD;
|
||||||
|
|
||||||
|
@ -6173,7 +6200,7 @@ os_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwn
|
||||||
#undef KWTUPLE
|
#undef KWTUPLE
|
||||||
PyObject *argsbuf[4];
|
PyObject *argsbuf[4];
|
||||||
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
|
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
|
||||||
path_t path = PATH_T_INITIALIZE("open", "path", 0, 0);
|
path_t path = PATH_T_INITIALIZE_P("open", "path", 0, 0, 0, 0);
|
||||||
int flags;
|
int flags;
|
||||||
int mode = 511;
|
int mode = 511;
|
||||||
int dir_fd = DEFAULT_DIR_FD;
|
int dir_fd = DEFAULT_DIR_FD;
|
||||||
|
@ -7769,7 +7796,7 @@ os_mkfifo(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *k
|
||||||
#undef KWTUPLE
|
#undef KWTUPLE
|
||||||
PyObject *argsbuf[3];
|
PyObject *argsbuf[3];
|
||||||
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
|
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
|
||||||
path_t path = PATH_T_INITIALIZE("mkfifo", "path", 0, 0);
|
path_t path = PATH_T_INITIALIZE_P("mkfifo", "path", 0, 0, 0, 0);
|
||||||
int mode = 438;
|
int mode = 438;
|
||||||
int dir_fd = DEFAULT_DIR_FD;
|
int dir_fd = DEFAULT_DIR_FD;
|
||||||
|
|
||||||
|
@ -7869,7 +7896,7 @@ os_mknod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kw
|
||||||
#undef KWTUPLE
|
#undef KWTUPLE
|
||||||
PyObject *argsbuf[4];
|
PyObject *argsbuf[4];
|
||||||
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
|
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
|
||||||
path_t path = PATH_T_INITIALIZE("mknod", "path", 0, 0);
|
path_t path = PATH_T_INITIALIZE_P("mknod", "path", 0, 0, 0, 0);
|
||||||
int mode = 384;
|
int mode = 384;
|
||||||
dev_t device = 0;
|
dev_t device = 0;
|
||||||
int dir_fd = DEFAULT_DIR_FD;
|
int dir_fd = DEFAULT_DIR_FD;
|
||||||
|
@ -8123,7 +8150,7 @@ os_truncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject
|
||||||
};
|
};
|
||||||
#undef KWTUPLE
|
#undef KWTUPLE
|
||||||
PyObject *argsbuf[2];
|
PyObject *argsbuf[2];
|
||||||
path_t path = PATH_T_INITIALIZE("truncate", "path", 0, PATH_HAVE_FTRUNCATE);
|
path_t path = PATH_T_INITIALIZE_P("truncate", "path", 0, 0, 0, PATH_HAVE_FTRUNCATE);
|
||||||
Py_off_t length;
|
Py_off_t length;
|
||||||
|
|
||||||
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
|
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
|
||||||
|
@ -9031,7 +9058,7 @@ os_statvfs(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *
|
||||||
};
|
};
|
||||||
#undef KWTUPLE
|
#undef KWTUPLE
|
||||||
PyObject *argsbuf[1];
|
PyObject *argsbuf[1];
|
||||||
path_t path = PATH_T_INITIALIZE("statvfs", "path", 0, PATH_HAVE_FSTATVFS);
|
path_t path = PATH_T_INITIALIZE_P("statvfs", "path", 0, 0, 0, PATH_HAVE_FSTATVFS);
|
||||||
|
|
||||||
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
|
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
|
||||||
if (!args) {
|
if (!args) {
|
||||||
|
@ -9095,7 +9122,7 @@ os__getdiskusage(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyOb
|
||||||
};
|
};
|
||||||
#undef KWTUPLE
|
#undef KWTUPLE
|
||||||
PyObject *argsbuf[1];
|
PyObject *argsbuf[1];
|
||||||
path_t path = PATH_T_INITIALIZE("_getdiskusage", "path", 0, 0);
|
path_t path = PATH_T_INITIALIZE_P("_getdiskusage", "path", 0, 0, 0, 0);
|
||||||
|
|
||||||
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
|
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
|
||||||
if (!args) {
|
if (!args) {
|
||||||
|
@ -9208,7 +9235,7 @@ os_pathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject
|
||||||
};
|
};
|
||||||
#undef KWTUPLE
|
#undef KWTUPLE
|
||||||
PyObject *argsbuf[2];
|
PyObject *argsbuf[2];
|
||||||
path_t path = PATH_T_INITIALIZE("pathconf", "path", 0, PATH_HAVE_FPATHCONF);
|
path_t path = PATH_T_INITIALIZE_P("pathconf", "path", 0, 0, 0, PATH_HAVE_FPATHCONF);
|
||||||
int name;
|
int name;
|
||||||
long _return_value;
|
long _return_value;
|
||||||
|
|
||||||
|
@ -9398,10 +9425,10 @@ os_startfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject
|
||||||
#undef KWTUPLE
|
#undef KWTUPLE
|
||||||
PyObject *argsbuf[5];
|
PyObject *argsbuf[5];
|
||||||
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
|
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
|
||||||
path_t filepath = PATH_T_INITIALIZE("startfile", "filepath", 0, 0);
|
path_t filepath = PATH_T_INITIALIZE_P("startfile", "filepath", 0, 0, 0, 0);
|
||||||
const Py_UNICODE *operation = NULL;
|
const Py_UNICODE *operation = NULL;
|
||||||
const Py_UNICODE *arguments = NULL;
|
const Py_UNICODE *arguments = NULL;
|
||||||
path_t cwd = PATH_T_INITIALIZE("startfile", "cwd", 1, 0);
|
path_t cwd = PATH_T_INITIALIZE_P("startfile", "cwd", 1, 0, 0, 0);
|
||||||
int show_cmd = 1;
|
int show_cmd = 1;
|
||||||
|
|
||||||
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 5, 0, argsbuf);
|
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 5, 0, argsbuf);
|
||||||
|
@ -9736,8 +9763,8 @@ os_getxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject
|
||||||
#undef KWTUPLE
|
#undef KWTUPLE
|
||||||
PyObject *argsbuf[3];
|
PyObject *argsbuf[3];
|
||||||
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
|
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
|
||||||
path_t path = PATH_T_INITIALIZE("getxattr", "path", 0, 1);
|
path_t path = PATH_T_INITIALIZE_P("getxattr", "path", 0, 0, 0, 1);
|
||||||
path_t attribute = PATH_T_INITIALIZE("getxattr", "attribute", 0, 0);
|
path_t attribute = PATH_T_INITIALIZE_P("getxattr", "attribute", 0, 0, 0, 0);
|
||||||
int follow_symlinks = 1;
|
int follow_symlinks = 1;
|
||||||
|
|
||||||
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
|
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
|
||||||
|
@ -9823,8 +9850,8 @@ os_setxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject
|
||||||
#undef KWTUPLE
|
#undef KWTUPLE
|
||||||
PyObject *argsbuf[5];
|
PyObject *argsbuf[5];
|
||||||
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
|
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
|
||||||
path_t path = PATH_T_INITIALIZE("setxattr", "path", 0, 1);
|
path_t path = PATH_T_INITIALIZE_P("setxattr", "path", 0, 0, 0, 1);
|
||||||
path_t attribute = PATH_T_INITIALIZE("setxattr", "attribute", 0, 0);
|
path_t attribute = PATH_T_INITIALIZE_P("setxattr", "attribute", 0, 0, 0, 0);
|
||||||
Py_buffer value = {NULL, NULL};
|
Py_buffer value = {NULL, NULL};
|
||||||
int flags = 0;
|
int flags = 0;
|
||||||
int follow_symlinks = 1;
|
int follow_symlinks = 1;
|
||||||
|
@ -9935,8 +9962,8 @@ os_removexattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObje
|
||||||
#undef KWTUPLE
|
#undef KWTUPLE
|
||||||
PyObject *argsbuf[3];
|
PyObject *argsbuf[3];
|
||||||
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
|
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
|
||||||
path_t path = PATH_T_INITIALIZE("removexattr", "path", 0, 1);
|
path_t path = PATH_T_INITIALIZE_P("removexattr", "path", 0, 0, 0, 1);
|
||||||
path_t attribute = PATH_T_INITIALIZE("removexattr", "attribute", 0, 0);
|
path_t attribute = PATH_T_INITIALIZE_P("removexattr", "attribute", 0, 0, 0, 0);
|
||||||
int follow_symlinks = 1;
|
int follow_symlinks = 1;
|
||||||
|
|
||||||
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
|
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
|
||||||
|
@ -10021,7 +10048,7 @@ os_listxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject
|
||||||
#undef KWTUPLE
|
#undef KWTUPLE
|
||||||
PyObject *argsbuf[2];
|
PyObject *argsbuf[2];
|
||||||
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
|
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
|
||||||
path_t path = PATH_T_INITIALIZE("listxattr", "path", 1, 1);
|
path_t path = PATH_T_INITIALIZE_P("listxattr", "path", 1, 0, 0, 1);
|
||||||
int follow_symlinks = 1;
|
int follow_symlinks = 1;
|
||||||
|
|
||||||
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
|
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
|
||||||
|
@ -11002,7 +11029,7 @@ os_scandir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *
|
||||||
#undef KWTUPLE
|
#undef KWTUPLE
|
||||||
PyObject *argsbuf[1];
|
PyObject *argsbuf[1];
|
||||||
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
|
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
|
||||||
path_t path = PATH_T_INITIALIZE("scandir", "path", 1, PATH_HAVE_FDOPENDIR);
|
path_t path = PATH_T_INITIALIZE_P("scandir", "path", 1, 0, 0, PATH_HAVE_FDOPENDIR);
|
||||||
|
|
||||||
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
|
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
|
||||||
if (!args) {
|
if (!args) {
|
||||||
|
@ -11214,7 +11241,7 @@ os__add_dll_directory(PyObject *module, PyObject *const *args, Py_ssize_t nargs,
|
||||||
};
|
};
|
||||||
#undef KWTUPLE
|
#undef KWTUPLE
|
||||||
PyObject *argsbuf[1];
|
PyObject *argsbuf[1];
|
||||||
path_t path = PATH_T_INITIALIZE("_add_dll_directory", "path", 0, 0);
|
path_t path = PATH_T_INITIALIZE_P("_add_dll_directory", "path", 0, 0, 0, 0);
|
||||||
|
|
||||||
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
|
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
|
||||||
if (!args) {
|
if (!args) {
|
||||||
|
@ -11987,4 +12014,4 @@ exit:
|
||||||
#ifndef OS_WAITSTATUS_TO_EXITCODE_METHODDEF
|
#ifndef OS_WAITSTATUS_TO_EXITCODE_METHODDEF
|
||||||
#define OS_WAITSTATUS_TO_EXITCODE_METHODDEF
|
#define OS_WAITSTATUS_TO_EXITCODE_METHODDEF
|
||||||
#endif /* !defined(OS_WAITSTATUS_TO_EXITCODE_METHODDEF) */
|
#endif /* !defined(OS_WAITSTATUS_TO_EXITCODE_METHODDEF) */
|
||||||
/*[clinic end generated code: output=46e87bace3cc07b6 input=a9049054013a1b77]*/
|
/*[clinic end generated code: output=485aa0aed01eb699 input=a9049054013a1b77]*/
|
||||||
|
|
|
@ -1034,16 +1034,15 @@ get_posix_state(PyObject *module)
|
||||||
*
|
*
|
||||||
* path_converter accepts (Unicode) strings and their
|
* path_converter accepts (Unicode) strings and their
|
||||||
* subclasses, and bytes and their subclasses. What
|
* subclasses, and bytes and their subclasses. What
|
||||||
* it does with the argument depends on the platform:
|
* it does with the argument depends on path.make_wide:
|
||||||
*
|
*
|
||||||
* * On Windows, if we get a (Unicode) string we
|
* * If path.make_wide is nonzero, if we get a (Unicode)
|
||||||
* extract the wchar_t * and return it; if we get
|
* string we extract the wchar_t * and return it; if we
|
||||||
* bytes we decode to wchar_t * and return that.
|
* get bytes we decode to wchar_t * and return that.
|
||||||
*
|
*
|
||||||
* * On all other platforms, strings are encoded
|
* * If path.make_wide is zero, if we get bytes we extract
|
||||||
* to bytes using PyUnicode_FSConverter, then we
|
* the char_t * and return it; if we get a (Unicode)
|
||||||
* extract the char * from the bytes object and
|
* string we encode to char_t * and return that.
|
||||||
* return that.
|
|
||||||
*
|
*
|
||||||
* path_converter also optionally accepts signed
|
* path_converter also optionally accepts signed
|
||||||
* integers (representing open file descriptors) instead
|
* integers (representing open file descriptors) instead
|
||||||
|
@ -1052,6 +1051,15 @@ get_posix_state(PyObject *module)
|
||||||
* Input fields:
|
* Input fields:
|
||||||
* path.nullable
|
* path.nullable
|
||||||
* If nonzero, the path is permitted to be None.
|
* If nonzero, the path is permitted to be None.
|
||||||
|
* path.nonstrict
|
||||||
|
* If nonzero, the path is permitted to contain
|
||||||
|
* embedded null characters and have any length.
|
||||||
|
* path.make_wide
|
||||||
|
* If nonzero, the converter always uses wide, decoding if necessary, else
|
||||||
|
* it always uses narrow, encoding if necessary. The default value is
|
||||||
|
* nonzero on Windows, else zero.
|
||||||
|
* path.suppress_value_error
|
||||||
|
* If nonzero, raising ValueError is suppressed.
|
||||||
* path.allow_fd
|
* path.allow_fd
|
||||||
* If nonzero, the path is permitted to be a file handle
|
* If nonzero, the path is permitted to be a file handle
|
||||||
* (a signed int) instead of a string.
|
* (a signed int) instead of a string.
|
||||||
|
@ -1067,12 +1075,10 @@ get_posix_state(PyObject *module)
|
||||||
* Output fields:
|
* Output fields:
|
||||||
* path.wide
|
* path.wide
|
||||||
* Points to the path if it was expressed as Unicode
|
* Points to the path if it was expressed as Unicode
|
||||||
* and was not encoded. (Only used on Windows.)
|
* or if it was bytes and decoded to Unicode.
|
||||||
* path.narrow
|
* path.narrow
|
||||||
* Points to the path if it was expressed as bytes,
|
* Points to the path if it was expressed as bytes,
|
||||||
* or it was Unicode and was encoded to bytes. (On Windows,
|
* or if it was Unicode and encoded to bytes.
|
||||||
* is a non-zero integer if the path was expressed as bytes.
|
|
||||||
* The type is deliberately incompatible to prevent misuse.)
|
|
||||||
* path.fd
|
* path.fd
|
||||||
* Contains a file descriptor if path.accept_fd was true
|
* Contains a file descriptor if path.accept_fd was true
|
||||||
* and the caller provided a signed integer instead of any
|
* and the caller provided a signed integer instead of any
|
||||||
|
@ -1082,6 +1088,9 @@ get_posix_state(PyObject *module)
|
||||||
* unspecified, path_converter will never get called.
|
* unspecified, path_converter will never get called.
|
||||||
* So if you set allow_fd, you *MUST* initialize path.fd = -1
|
* So if you set allow_fd, you *MUST* initialize path.fd = -1
|
||||||
* yourself!
|
* yourself!
|
||||||
|
* path.value_error
|
||||||
|
* If nonzero, then suppress_value_error was specified and a ValueError
|
||||||
|
* occurred.
|
||||||
* path.length
|
* path.length
|
||||||
* The length of the path in characters, if specified as
|
* The length of the path in characters, if specified as
|
||||||
* a string.
|
* a string.
|
||||||
|
@ -1114,28 +1123,38 @@ get_posix_state(PyObject *module)
|
||||||
* path_cleanup(). However it is safe to do so.)
|
* path_cleanup(). However it is safe to do so.)
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
// Input fields
|
||||||
const char *function_name;
|
const char *function_name;
|
||||||
const char *argument_name;
|
const char *argument_name;
|
||||||
int nullable;
|
int nullable;
|
||||||
|
int nonstrict;
|
||||||
|
int make_wide;
|
||||||
|
int suppress_value_error;
|
||||||
int allow_fd;
|
int allow_fd;
|
||||||
|
// Output fields
|
||||||
const wchar_t *wide;
|
const wchar_t *wide;
|
||||||
#ifdef MS_WINDOWS
|
|
||||||
BOOL narrow;
|
|
||||||
#else
|
|
||||||
const char *narrow;
|
const char *narrow;
|
||||||
#endif
|
|
||||||
int fd;
|
int fd;
|
||||||
|
int value_error;
|
||||||
Py_ssize_t length;
|
Py_ssize_t length;
|
||||||
PyObject *object;
|
PyObject *object;
|
||||||
PyObject *cleanup;
|
PyObject *cleanup;
|
||||||
} path_t;
|
} path_t;
|
||||||
|
|
||||||
|
#define PATH_T_INITIALIZE(function_name, argument_name, nullable, nonstrict, \
|
||||||
|
make_wide, suppress_value_error, allow_fd) \
|
||||||
|
{function_name, argument_name, nullable, nonstrict, make_wide, \
|
||||||
|
suppress_value_error, allow_fd, NULL, NULL, -1, 0, 0, NULL, NULL}
|
||||||
#ifdef MS_WINDOWS
|
#ifdef MS_WINDOWS
|
||||||
#define PATH_T_INITIALIZE(function_name, argument_name, nullable, allow_fd) \
|
#define PATH_T_INITIALIZE_P(function_name, argument_name, nullable, \
|
||||||
{function_name, argument_name, nullable, allow_fd, NULL, FALSE, -1, 0, NULL, NULL}
|
nonstrict, suppress_value_error, allow_fd) \
|
||||||
|
PATH_T_INITIALIZE(function_name, argument_name, nullable, nonstrict, 1, \
|
||||||
|
suppress_value_error, allow_fd)
|
||||||
#else
|
#else
|
||||||
#define PATH_T_INITIALIZE(function_name, argument_name, nullable, allow_fd) \
|
#define PATH_T_INITIALIZE_P(function_name, argument_name, nullable, \
|
||||||
{function_name, argument_name, nullable, allow_fd, NULL, NULL, -1, 0, NULL, NULL}
|
nonstrict, suppress_value_error, allow_fd) \
|
||||||
|
PATH_T_INITIALIZE(function_name, argument_name, nullable, nonstrict, 0, \
|
||||||
|
suppress_value_error, allow_fd)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -1156,10 +1175,8 @@ path_converter(PyObject *o, void *p)
|
||||||
Py_ssize_t length = 0;
|
Py_ssize_t length = 0;
|
||||||
int is_index, is_bytes, is_unicode;
|
int is_index, is_bytes, is_unicode;
|
||||||
const char *narrow;
|
const char *narrow;
|
||||||
#ifdef MS_WINDOWS
|
|
||||||
PyObject *wo = NULL;
|
PyObject *wo = NULL;
|
||||||
wchar_t *wide = NULL;
|
wchar_t *wide = NULL;
|
||||||
#endif
|
|
||||||
|
|
||||||
#define FORMAT_EXCEPTION(exc, fmt) \
|
#define FORMAT_EXCEPTION(exc, fmt) \
|
||||||
PyErr_Format(exc, "%s%s" fmt, \
|
PyErr_Format(exc, "%s%s" fmt, \
|
||||||
|
@ -1180,11 +1197,7 @@ path_converter(PyObject *o, void *p)
|
||||||
|
|
||||||
if ((o == Py_None) && path->nullable) {
|
if ((o == Py_None) && path->nullable) {
|
||||||
path->wide = NULL;
|
path->wide = NULL;
|
||||||
#ifdef MS_WINDOWS
|
|
||||||
path->narrow = FALSE;
|
|
||||||
#else
|
|
||||||
path->narrow = NULL;
|
path->narrow = NULL;
|
||||||
#endif
|
|
||||||
path->fd = -1;
|
path->fd = -1;
|
||||||
goto success_exit;
|
goto success_exit;
|
||||||
}
|
}
|
||||||
|
@ -1228,30 +1241,33 @@ path_converter(PyObject *o, void *p)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_unicode) {
|
if (is_unicode) {
|
||||||
#ifdef MS_WINDOWS
|
if (path->make_wide) {
|
||||||
wide = PyUnicode_AsWideCharString(o, &length);
|
wide = PyUnicode_AsWideCharString(o, &length);
|
||||||
if (!wide) {
|
if (!wide) {
|
||||||
goto error_exit;
|
goto error_exit;
|
||||||
}
|
}
|
||||||
if (length > 32767) {
|
#ifdef MS_WINDOWS
|
||||||
|
if (!path->nonstrict && length > 32767) {
|
||||||
FORMAT_EXCEPTION(PyExc_ValueError, "%s too long for Windows");
|
FORMAT_EXCEPTION(PyExc_ValueError, "%s too long for Windows");
|
||||||
goto error_exit;
|
goto error_exit;
|
||||||
}
|
}
|
||||||
if (wcslen(wide) != length) {
|
#endif
|
||||||
FORMAT_EXCEPTION(PyExc_ValueError, "embedded null character in %s");
|
if (!path->nonstrict && wcslen(wide) != (size_t)length) {
|
||||||
|
FORMAT_EXCEPTION(PyExc_ValueError,
|
||||||
|
"embedded null character in %s");
|
||||||
goto error_exit;
|
goto error_exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
path->wide = wide;
|
path->wide = wide;
|
||||||
path->narrow = FALSE;
|
path->narrow = NULL;
|
||||||
path->fd = -1;
|
path->fd = -1;
|
||||||
wide = NULL;
|
wide = NULL;
|
||||||
goto success_exit;
|
goto success_exit;
|
||||||
#else
|
}
|
||||||
if (!PyUnicode_FSConverter(o, &bytes)) {
|
bytes = PyUnicode_EncodeFSDefault(o);
|
||||||
|
if (!bytes) {
|
||||||
goto error_exit;
|
goto error_exit;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
else if (is_bytes) {
|
else if (is_bytes) {
|
||||||
bytes = Py_NewRef(o);
|
bytes = Py_NewRef(o);
|
||||||
|
@ -1261,11 +1277,7 @@ path_converter(PyObject *o, void *p)
|
||||||
goto error_exit;
|
goto error_exit;
|
||||||
}
|
}
|
||||||
path->wide = NULL;
|
path->wide = NULL;
|
||||||
#ifdef MS_WINDOWS
|
|
||||||
path->narrow = FALSE;
|
|
||||||
#else
|
|
||||||
path->narrow = NULL;
|
path->narrow = NULL;
|
||||||
#endif
|
|
||||||
goto success_exit;
|
goto success_exit;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -1285,16 +1297,13 @@ path_converter(PyObject *o, void *p)
|
||||||
|
|
||||||
length = PyBytes_GET_SIZE(bytes);
|
length = PyBytes_GET_SIZE(bytes);
|
||||||
narrow = PyBytes_AS_STRING(bytes);
|
narrow = PyBytes_AS_STRING(bytes);
|
||||||
if ((size_t)length != strlen(narrow)) {
|
if (!path->nonstrict && strlen(narrow) != (size_t)length) {
|
||||||
FORMAT_EXCEPTION(PyExc_ValueError, "embedded null character in %s");
|
FORMAT_EXCEPTION(PyExc_ValueError, "embedded null character in %s");
|
||||||
goto error_exit;
|
goto error_exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef MS_WINDOWS
|
if (path->make_wide) {
|
||||||
wo = PyUnicode_DecodeFSDefaultAndSize(
|
wo = PyUnicode_DecodeFSDefaultAndSize(narrow, length);
|
||||||
narrow,
|
|
||||||
length
|
|
||||||
);
|
|
||||||
if (!wo) {
|
if (!wo) {
|
||||||
goto error_exit;
|
goto error_exit;
|
||||||
}
|
}
|
||||||
|
@ -1304,19 +1313,23 @@ path_converter(PyObject *o, void *p)
|
||||||
if (!wide) {
|
if (!wide) {
|
||||||
goto error_exit;
|
goto error_exit;
|
||||||
}
|
}
|
||||||
if (length > 32767) {
|
#ifdef MS_WINDOWS
|
||||||
|
if (!path->nonstrict && length > 32767) {
|
||||||
FORMAT_EXCEPTION(PyExc_ValueError, "%s too long for Windows");
|
FORMAT_EXCEPTION(PyExc_ValueError, "%s too long for Windows");
|
||||||
goto error_exit;
|
goto error_exit;
|
||||||
}
|
}
|
||||||
if (wcslen(wide) != length) {
|
#endif
|
||||||
FORMAT_EXCEPTION(PyExc_ValueError, "embedded null character in %s");
|
if (!path->nonstrict && wcslen(wide) != (size_t)length) {
|
||||||
|
FORMAT_EXCEPTION(PyExc_ValueError,
|
||||||
|
"embedded null character in %s");
|
||||||
goto error_exit;
|
goto error_exit;
|
||||||
}
|
}
|
||||||
path->wide = wide;
|
path->wide = wide;
|
||||||
path->narrow = TRUE;
|
path->narrow = NULL;
|
||||||
Py_DECREF(bytes);
|
Py_DECREF(bytes);
|
||||||
wide = NULL;
|
wide = NULL;
|
||||||
#else
|
}
|
||||||
|
else {
|
||||||
path->wide = NULL;
|
path->wide = NULL;
|
||||||
path->narrow = narrow;
|
path->narrow = narrow;
|
||||||
if (bytes == o) {
|
if (bytes == o) {
|
||||||
|
@ -1327,10 +1340,11 @@ path_converter(PyObject *o, void *p)
|
||||||
else {
|
else {
|
||||||
path->cleanup = bytes;
|
path->cleanup = bytes;
|
||||||
}
|
}
|
||||||
#endif
|
}
|
||||||
path->fd = -1;
|
path->fd = -1;
|
||||||
|
|
||||||
success_exit:
|
success_exit:
|
||||||
|
path->value_error = 0;
|
||||||
path->length = length;
|
path->length = length;
|
||||||
path->object = o;
|
path->object = o;
|
||||||
return Py_CLEANUP_SUPPORTED;
|
return Py_CLEANUP_SUPPORTED;
|
||||||
|
@ -1338,10 +1352,20 @@ path_converter(PyObject *o, void *p)
|
||||||
error_exit:
|
error_exit:
|
||||||
Py_XDECREF(o);
|
Py_XDECREF(o);
|
||||||
Py_XDECREF(bytes);
|
Py_XDECREF(bytes);
|
||||||
#ifdef MS_WINDOWS
|
|
||||||
PyMem_Free(wide);
|
PyMem_Free(wide);
|
||||||
#endif
|
if (!path->suppress_value_error ||
|
||||||
|
!PyErr_ExceptionMatches(PyExc_ValueError))
|
||||||
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
PyErr_Clear();
|
||||||
|
path->wide = NULL;
|
||||||
|
path->narrow = NULL;
|
||||||
|
path->fd = -1;
|
||||||
|
path->value_error = 1;
|
||||||
|
path->length = 0;
|
||||||
|
path->object = NULL;
|
||||||
|
return Py_CLEANUP_SUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -1391,11 +1415,7 @@ follow_symlinks_specified(const char *function_name, int follow_symlinks)
|
||||||
static int
|
static int
|
||||||
path_and_dir_fd_invalid(const char *function_name, path_t *path, int dir_fd)
|
path_and_dir_fd_invalid(const char *function_name, path_t *path, int dir_fd)
|
||||||
{
|
{
|
||||||
if (!path->wide && (dir_fd != DEFAULT_DIR_FD)
|
if (!path->wide && (dir_fd != DEFAULT_DIR_FD) && !path->narrow) {
|
||||||
#ifndef MS_WINDOWS
|
|
||||||
&& !path->narrow
|
|
||||||
#endif
|
|
||||||
) {
|
|
||||||
PyErr_Format(PyExc_ValueError,
|
PyErr_Format(PyExc_ValueError,
|
||||||
"%s: can't specify dir_fd without matching path",
|
"%s: can't specify dir_fd without matching path",
|
||||||
function_name);
|
function_name);
|
||||||
|
@ -2852,7 +2872,9 @@ class path_t_converter(CConverter):
|
||||||
|
|
||||||
converter = 'path_converter'
|
converter = 'path_converter'
|
||||||
|
|
||||||
def converter_init(self, *, allow_fd=False, nullable=False):
|
def converter_init(self, *, allow_fd=False, make_wide=None,
|
||||||
|
nonstrict=False, nullable=False,
|
||||||
|
suppress_value_error=False):
|
||||||
# right now path_t doesn't support default values.
|
# right now path_t doesn't support default values.
|
||||||
# to support a default value, you'll need to override initialize().
|
# to support a default value, you'll need to override initialize().
|
||||||
if self.default not in (unspecified, None):
|
if self.default not in (unspecified, None):
|
||||||
|
@ -2862,6 +2884,9 @@ class path_t_converter(CConverter):
|
||||||
raise RuntimeError("Can't specify a c_default to the path_t converter!")
|
raise RuntimeError("Can't specify a c_default to the path_t converter!")
|
||||||
|
|
||||||
self.nullable = nullable
|
self.nullable = nullable
|
||||||
|
self.nonstrict = nonstrict
|
||||||
|
self.make_wide = make_wide
|
||||||
|
self.suppress_value_error = suppress_value_error
|
||||||
self.allow_fd = allow_fd
|
self.allow_fd = allow_fd
|
||||||
|
|
||||||
def pre_render(self):
|
def pre_render(self):
|
||||||
|
@ -2871,10 +2896,23 @@ class path_t_converter(CConverter):
|
||||||
return str(int(bool(value)))
|
return str(int(bool(value)))
|
||||||
|
|
||||||
# add self.py_name here when merging with posixmodule conversion
|
# add self.py_name here when merging with posixmodule conversion
|
||||||
self.c_default = 'PATH_T_INITIALIZE("{}", "{}", {}, {})'.format(
|
if self.make_wide is None:
|
||||||
|
self.c_default = 'PATH_T_INITIALIZE_P("{}", "{}", {}, {}, {}, {})'.format(
|
||||||
self.function.name,
|
self.function.name,
|
||||||
self.name,
|
self.name,
|
||||||
strify(self.nullable),
|
strify(self.nullable),
|
||||||
|
strify(self.nonstrict),
|
||||||
|
strify(self.suppress_value_error),
|
||||||
|
strify(self.allow_fd),
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
self.c_default = 'PATH_T_INITIALIZE("{}", "{}", {}, {}, {}, {}, {})'.format(
|
||||||
|
self.function.name,
|
||||||
|
self.name,
|
||||||
|
strify(self.nullable),
|
||||||
|
strify(self.nonstrict),
|
||||||
|
strify(self.make_wide),
|
||||||
|
strify(self.suppress_value_error),
|
||||||
strify(self.allow_fd),
|
strify(self.allow_fd),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -2955,7 +2993,7 @@ class sysconf_confname_converter(path_confname_converter):
|
||||||
converter="conv_sysconf_confname"
|
converter="conv_sysconf_confname"
|
||||||
|
|
||||||
[python start generated code]*/
|
[python start generated code]*/
|
||||||
/*[python end generated code: output=da39a3ee5e6b4b0d input=3338733161aa7879]*/
|
/*[python end generated code: output=da39a3ee5e6b4b0d input=577cb476e5d64960]*/
|
||||||
|
|
||||||
/*[clinic input]
|
/*[clinic input]
|
||||||
|
|
||||||
|
@ -4133,7 +4171,7 @@ _listdir_windows_no_opendir(path_t *path, PyObject *list)
|
||||||
{
|
{
|
||||||
PyObject *v;
|
PyObject *v;
|
||||||
HANDLE hFindFile = INVALID_HANDLE_VALUE;
|
HANDLE hFindFile = INVALID_HANDLE_VALUE;
|
||||||
BOOL result;
|
BOOL result, return_bytes;
|
||||||
wchar_t namebuf[MAX_PATH+4]; /* Overallocate for "\*.*" */
|
wchar_t namebuf[MAX_PATH+4]; /* Overallocate for "\*.*" */
|
||||||
/* only claim to have space for MAX_PATH */
|
/* only claim to have space for MAX_PATH */
|
||||||
Py_ssize_t len = Py_ARRAY_LENGTH(namebuf)-4;
|
Py_ssize_t len = Py_ARRAY_LENGTH(namebuf)-4;
|
||||||
|
@ -4145,9 +4183,11 @@ _listdir_windows_no_opendir(path_t *path, PyObject *list)
|
||||||
if (!path->wide) { /* Default arg: "." */
|
if (!path->wide) { /* Default arg: "." */
|
||||||
po_wchars = L".";
|
po_wchars = L".";
|
||||||
len = 1;
|
len = 1;
|
||||||
|
return_bytes = 0;
|
||||||
} else {
|
} else {
|
||||||
po_wchars = path->wide;
|
po_wchars = path->wide;
|
||||||
len = wcslen(path->wide);
|
len = wcslen(path->wide);
|
||||||
|
return_bytes = PyBytes_Check(path->object);
|
||||||
}
|
}
|
||||||
/* The +5 is so we can append "\\*.*\0" */
|
/* The +5 is so we can append "\\*.*\0" */
|
||||||
wnamebuf = PyMem_New(wchar_t, len + 5);
|
wnamebuf = PyMem_New(wchar_t, len + 5);
|
||||||
|
@ -4182,7 +4222,7 @@ _listdir_windows_no_opendir(path_t *path, PyObject *list)
|
||||||
wcscmp(wFileData.cFileName, L"..") != 0) {
|
wcscmp(wFileData.cFileName, L"..") != 0) {
|
||||||
v = PyUnicode_FromWideChar(wFileData.cFileName,
|
v = PyUnicode_FromWideChar(wFileData.cFileName,
|
||||||
wcslen(wFileData.cFileName));
|
wcslen(wFileData.cFileName));
|
||||||
if (path->narrow && v) {
|
if (return_bytes && v) {
|
||||||
Py_SETREF(v, PyUnicode_EncodeFSDefault(v));
|
Py_SETREF(v, PyUnicode_EncodeFSDefault(v));
|
||||||
}
|
}
|
||||||
if (v == NULL) {
|
if (v == NULL) {
|
||||||
|
@ -4725,7 +4765,7 @@ os__getfullpathname_impl(PyObject *module, path_t *path)
|
||||||
if (str == NULL) {
|
if (str == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (path->narrow) {
|
if (PyBytes_Check(path->object)) {
|
||||||
Py_SETREF(str, PyUnicode_EncodeFSDefault(str));
|
Py_SETREF(str, PyUnicode_EncodeFSDefault(str));
|
||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
|
@ -4798,7 +4838,7 @@ os__getfinalpathname_impl(PyObject *module, path_t *path)
|
||||||
}
|
}
|
||||||
|
|
||||||
result = PyUnicode_FromWideChar(target_path, result_length);
|
result = PyUnicode_FromWideChar(target_path, result_length);
|
||||||
if (result && path->narrow) {
|
if (result && PyBytes_Check(path->object)) {
|
||||||
Py_SETREF(result, PyUnicode_EncodeFSDefault(result));
|
Py_SETREF(result, PyUnicode_EncodeFSDefault(result));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4850,7 +4890,7 @@ os__getvolumepathname_impl(PyObject *module, path_t *path)
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
result = PyUnicode_FromWideChar(mountpath, wcslen(mountpath));
|
result = PyUnicode_FromWideChar(mountpath, wcslen(mountpath));
|
||||||
if (path->narrow)
|
if (PyBytes_Check(path->object))
|
||||||
Py_SETREF(result, PyUnicode_EncodeFSDefault(result));
|
Py_SETREF(result, PyUnicode_EncodeFSDefault(result));
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
@ -5084,64 +5124,52 @@ _testFileExistsByName(LPCWSTR path, BOOL followLinks)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static BOOL
|
||||||
_testFileExists(path_t *_path, PyObject *path, BOOL followLinks)
|
_testFileExists(path_t *path, BOOL followLinks)
|
||||||
{
|
{
|
||||||
BOOL result = FALSE;
|
BOOL result = FALSE;
|
||||||
if (!path_converter(path, _path)) {
|
if (path->value_error) {
|
||||||
path_cleanup(_path);
|
|
||||||
if (PyErr_ExceptionMatches(PyExc_ValueError)) {
|
|
||||||
PyErr_Clear();
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS
|
||||||
if (_path->fd != -1) {
|
if (path->fd != -1) {
|
||||||
HANDLE hfile = _Py_get_osfhandle_noraise(_path->fd);
|
HANDLE hfile = _Py_get_osfhandle_noraise(path->fd);
|
||||||
if (hfile != INVALID_HANDLE_VALUE) {
|
if (hfile != INVALID_HANDLE_VALUE) {
|
||||||
if (GetFileType(hfile) != FILE_TYPE_UNKNOWN || !GetLastError()) {
|
if (GetFileType(hfile) != FILE_TYPE_UNKNOWN || !GetLastError()) {
|
||||||
result = TRUE;
|
result = TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (_path->wide) {
|
else if (path->wide) {
|
||||||
result = _testFileExistsByName(_path->wide, followLinks);
|
result = _testFileExistsByName(path->wide, followLinks);
|
||||||
}
|
}
|
||||||
Py_END_ALLOW_THREADS
|
Py_END_ALLOW_THREADS
|
||||||
|
|
||||||
path_cleanup(_path);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static BOOL
|
||||||
_testFileType(path_t *_path, PyObject *path, int testedType)
|
_testFileType(path_t *path, int testedType)
|
||||||
{
|
{
|
||||||
BOOL result = FALSE;
|
BOOL result = FALSE;
|
||||||
if (!path_converter(path, _path)) {
|
if (path->value_error) {
|
||||||
path_cleanup(_path);
|
|
||||||
if (PyErr_ExceptionMatches(PyExc_ValueError)) {
|
|
||||||
PyErr_Clear();
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS
|
||||||
if (_path->fd != -1) {
|
if (path->fd != -1) {
|
||||||
HANDLE hfile = _Py_get_osfhandle_noraise(_path->fd);
|
HANDLE hfile = _Py_get_osfhandle_noraise(path->fd);
|
||||||
if (hfile != INVALID_HANDLE_VALUE) {
|
if (hfile != INVALID_HANDLE_VALUE) {
|
||||||
result = _testFileTypeByHandle(hfile, testedType, TRUE);
|
result = _testFileTypeByHandle(hfile, testedType, TRUE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (_path->wide) {
|
else if (path->wide) {
|
||||||
result = _testFileTypeByName(_path->wide, testedType);
|
result = _testFileTypeByName(path->wide, testedType);
|
||||||
}
|
}
|
||||||
Py_END_ALLOW_THREADS
|
Py_END_ALLOW_THREADS
|
||||||
|
|
||||||
path_cleanup(_path);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5149,7 +5177,7 @@ _testFileType(path_t *_path, PyObject *path, int testedType)
|
||||||
/*[clinic input]
|
/*[clinic input]
|
||||||
os._path_exists -> bool
|
os._path_exists -> bool
|
||||||
|
|
||||||
path: object
|
path: path_t(allow_fd=True, suppress_value_error=True)
|
||||||
/
|
/
|
||||||
|
|
||||||
Test whether a path exists. Returns False for broken symbolic links.
|
Test whether a path exists. Returns False for broken symbolic links.
|
||||||
|
@ -5157,65 +5185,61 @@ Test whether a path exists. Returns False for broken symbolic links.
|
||||||
[clinic start generated code]*/
|
[clinic start generated code]*/
|
||||||
|
|
||||||
static int
|
static int
|
||||||
os__path_exists_impl(PyObject *module, PyObject *path)
|
os__path_exists_impl(PyObject *module, path_t *path)
|
||||||
/*[clinic end generated code: output=8f784b3abf9f8588 input=2777da15bc4ba5a3]*/
|
/*[clinic end generated code: output=8da13acf666e16ba input=29198507a6082a57]*/
|
||||||
{
|
{
|
||||||
path_t _path = PATH_T_INITIALIZE("_path_exists", "path", 0, 1);
|
return _testFileExists(path, TRUE);
|
||||||
return _testFileExists(&_path, path, TRUE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*[clinic input]
|
/*[clinic input]
|
||||||
os._path_isdir -> bool
|
os._path_isdir -> bool
|
||||||
|
|
||||||
s as path: object
|
s as path: path_t(allow_fd=True, suppress_value_error=True)
|
||||||
|
|
||||||
Return true if the pathname refers to an existing directory.
|
Return true if the pathname refers to an existing directory.
|
||||||
|
|
||||||
[clinic start generated code]*/
|
[clinic start generated code]*/
|
||||||
|
|
||||||
static int
|
static int
|
||||||
os__path_isdir_impl(PyObject *module, PyObject *path)
|
os__path_isdir_impl(PyObject *module, path_t *path)
|
||||||
/*[clinic end generated code: output=0504fd403f369701 input=2cb54dd97eb970f7]*/
|
/*[clinic end generated code: output=d5786196f9e2fa7a input=132a3b5301aecf79]*/
|
||||||
{
|
{
|
||||||
path_t _path = PATH_T_INITIALIZE("_path_isdir", "s", 0, 1);
|
return _testFileType(path, PY_IFDIR);
|
||||||
return _testFileType(&_path, path, PY_IFDIR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*[clinic input]
|
/*[clinic input]
|
||||||
os._path_isfile -> bool
|
os._path_isfile -> bool
|
||||||
|
|
||||||
path: object
|
path: path_t(allow_fd=True, suppress_value_error=True)
|
||||||
|
|
||||||
Test whether a path is a regular file
|
Test whether a path is a regular file
|
||||||
|
|
||||||
[clinic start generated code]*/
|
[clinic start generated code]*/
|
||||||
|
|
||||||
static int
|
static int
|
||||||
os__path_isfile_impl(PyObject *module, PyObject *path)
|
os__path_isfile_impl(PyObject *module, path_t *path)
|
||||||
/*[clinic end generated code: output=b40d620efe5a896f input=54b428a310debaea]*/
|
/*[clinic end generated code: output=5c3073bc212b9863 input=4ac1fd350b30a39e]*/
|
||||||
{
|
{
|
||||||
path_t _path = PATH_T_INITIALIZE("_path_isfile", "path", 0, 1);
|
return _testFileType(path, PY_IFREG);
|
||||||
return _testFileType(&_path, path, PY_IFREG);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*[clinic input]
|
/*[clinic input]
|
||||||
os._path_islink -> bool
|
os._path_islink -> bool
|
||||||
|
|
||||||
path: object
|
path: path_t(allow_fd=True, suppress_value_error=True)
|
||||||
|
|
||||||
Test whether a path is a symbolic link
|
Test whether a path is a symbolic link
|
||||||
|
|
||||||
[clinic start generated code]*/
|
[clinic start generated code]*/
|
||||||
|
|
||||||
static int
|
static int
|
||||||
os__path_islink_impl(PyObject *module, PyObject *path)
|
os__path_islink_impl(PyObject *module, path_t *path)
|
||||||
/*[clinic end generated code: output=9d0cf8e4c640dfe6 input=b71fed60b9b2cd73]*/
|
/*[clinic end generated code: output=30da7bda8296adcc input=7510ce05b547debb]*/
|
||||||
{
|
{
|
||||||
path_t _path = PATH_T_INITIALIZE("_path_islink", "path", 0, 1);
|
return _testFileType(path, PY_IFLNK);
|
||||||
return _testFileType(&_path, path, PY_IFLNK);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef PY_IFREG
|
#undef PY_IFREG
|
||||||
|
@ -5231,29 +5255,28 @@ os__path_islink_impl(PyObject *module, PyObject *path)
|
||||||
/*[clinic input]
|
/*[clinic input]
|
||||||
os._path_normpath
|
os._path_normpath
|
||||||
|
|
||||||
path: object
|
path: path_t(make_wide=True, nonstrict=True)
|
||||||
|
|
||||||
Basic path normalization.
|
Normalize path, eliminating double slashes, etc.
|
||||||
[clinic start generated code]*/
|
[clinic start generated code]*/
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
os__path_normpath_impl(PyObject *module, PyObject *path)
|
os__path_normpath_impl(PyObject *module, path_t *path)
|
||||||
/*[clinic end generated code: output=b94d696d828019da input=5e90c39e12549dc0]*/
|
/*[clinic end generated code: output=d353e7ed9410c044 input=3d4ac23b06332dcb]*/
|
||||||
{
|
{
|
||||||
if (!PyUnicode_Check(path)) {
|
PyObject *result;
|
||||||
PyErr_Format(PyExc_TypeError, "expected 'str', not '%.200s'",
|
|
||||||
Py_TYPE(path)->tp_name);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
Py_ssize_t len;
|
|
||||||
wchar_t *buffer = PyUnicode_AsWideCharString(path, &len);
|
|
||||||
if (!buffer) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
Py_ssize_t norm_len;
|
Py_ssize_t norm_len;
|
||||||
wchar_t *norm_path = _Py_normpath_and_size(buffer, len, &norm_len);
|
wchar_t *norm_path = _Py_normpath_and_size((wchar_t *)path->wide,
|
||||||
PyObject *result = PyUnicode_FromWideChar(norm_path, norm_len);
|
path->length, &norm_len);
|
||||||
PyMem_Free(buffer);
|
if (!norm_len) {
|
||||||
|
result = PyUnicode_FromOrdinal('.');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
result = PyUnicode_FromWideChar(norm_path, norm_len);
|
||||||
|
}
|
||||||
|
if (PyBytes_Check(path->object)) {
|
||||||
|
Py_SETREF(result, PyUnicode_EncodeFSDefault(result));
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9709,7 +9732,7 @@ os_readlink_impl(PyObject *module, path_t *path, int dir_fd)
|
||||||
name[1] = L'\\';
|
name[1] = L'\\';
|
||||||
}
|
}
|
||||||
result = PyUnicode_FromWideChar(name, nameLen);
|
result = PyUnicode_FromWideChar(name, nameLen);
|
||||||
if (result && path->narrow) {
|
if (result && PyBytes_Check(path->object)) {
|
||||||
Py_SETREF(result, PyUnicode_EncodeFSDefault(result));
|
Py_SETREF(result, PyUnicode_EncodeFSDefault(result));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15004,7 +15027,8 @@ DirEntry_from_find_data(PyObject *module, path_t *path, WIN32_FIND_DATAW *dataW)
|
||||||
entry->name = PyUnicode_FromWideChar(dataW->cFileName, -1);
|
entry->name = PyUnicode_FromWideChar(dataW->cFileName, -1);
|
||||||
if (!entry->name)
|
if (!entry->name)
|
||||||
goto error;
|
goto error;
|
||||||
if (path->narrow) {
|
int return_bytes = path->wide && PyBytes_Check(path->object);
|
||||||
|
if (return_bytes) {
|
||||||
Py_SETREF(entry->name, PyUnicode_EncodeFSDefault(entry->name));
|
Py_SETREF(entry->name, PyUnicode_EncodeFSDefault(entry->name));
|
||||||
if (!entry->name)
|
if (!entry->name)
|
||||||
goto error;
|
goto error;
|
||||||
|
@ -15018,7 +15042,7 @@ DirEntry_from_find_data(PyObject *module, path_t *path, WIN32_FIND_DATAW *dataW)
|
||||||
PyMem_Free(joined_path);
|
PyMem_Free(joined_path);
|
||||||
if (!entry->path)
|
if (!entry->path)
|
||||||
goto error;
|
goto error;
|
||||||
if (path->narrow) {
|
if (return_bytes) {
|
||||||
Py_SETREF(entry->path, PyUnicode_EncodeFSDefault(entry->path));
|
Py_SETREF(entry->path, PyUnicode_EncodeFSDefault(entry->path));
|
||||||
if (!entry->path)
|
if (!entry->path)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue