Converted os._getfullpathname() and os._isdir() to Argument Clinic.
This commit is contained in:
parent
cd4a5cc339
commit
f0b5015edb
|
@ -890,6 +890,38 @@ exit:
|
||||||
|
|
||||||
#if defined(MS_WINDOWS)
|
#if defined(MS_WINDOWS)
|
||||||
|
|
||||||
|
PyDoc_STRVAR(os__getfullpathname__doc__,
|
||||||
|
"_getfullpathname($module, path, /)\n"
|
||||||
|
"--\n"
|
||||||
|
"\n");
|
||||||
|
|
||||||
|
#define OS__GETFULLPATHNAME_METHODDEF \
|
||||||
|
{"_getfullpathname", (PyCFunction)os__getfullpathname, METH_O, os__getfullpathname__doc__},
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
os__getfullpathname_impl(PyModuleDef *module, path_t *path);
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
os__getfullpathname(PyModuleDef *module, PyObject *arg)
|
||||||
|
{
|
||||||
|
PyObject *return_value = NULL;
|
||||||
|
path_t path = PATH_T_INITIALIZE("_getfullpathname", "path", 0, 0);
|
||||||
|
|
||||||
|
if (!PyArg_Parse(arg, "O&:_getfullpathname", path_converter, &path))
|
||||||
|
goto exit;
|
||||||
|
return_value = os__getfullpathname_impl(module, &path);
|
||||||
|
|
||||||
|
exit:
|
||||||
|
/* Cleanup for path */
|
||||||
|
path_cleanup(&path);
|
||||||
|
|
||||||
|
return return_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* defined(MS_WINDOWS) */
|
||||||
|
|
||||||
|
#if defined(MS_WINDOWS)
|
||||||
|
|
||||||
PyDoc_STRVAR(os__getfinalpathname__doc__,
|
PyDoc_STRVAR(os__getfinalpathname__doc__,
|
||||||
"_getfinalpathname($module, path, /)\n"
|
"_getfinalpathname($module, path, /)\n"
|
||||||
"--\n"
|
"--\n"
|
||||||
|
@ -920,6 +952,38 @@ exit:
|
||||||
|
|
||||||
#if defined(MS_WINDOWS)
|
#if defined(MS_WINDOWS)
|
||||||
|
|
||||||
|
PyDoc_STRVAR(os__isdir__doc__,
|
||||||
|
"_isdir($module, path, /)\n"
|
||||||
|
"--\n"
|
||||||
|
"\n");
|
||||||
|
|
||||||
|
#define OS__ISDIR_METHODDEF \
|
||||||
|
{"_isdir", (PyCFunction)os__isdir, METH_O, os__isdir__doc__},
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
os__isdir_impl(PyModuleDef *module, path_t *path);
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
os__isdir(PyModuleDef *module, PyObject *arg)
|
||||||
|
{
|
||||||
|
PyObject *return_value = NULL;
|
||||||
|
path_t path = PATH_T_INITIALIZE("_isdir", "path", 0, 0);
|
||||||
|
|
||||||
|
if (!PyArg_Parse(arg, "O&:_isdir", path_converter, &path))
|
||||||
|
goto exit;
|
||||||
|
return_value = os__isdir_impl(module, &path);
|
||||||
|
|
||||||
|
exit:
|
||||||
|
/* Cleanup for path */
|
||||||
|
path_cleanup(&path);
|
||||||
|
|
||||||
|
return return_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* defined(MS_WINDOWS) */
|
||||||
|
|
||||||
|
#if defined(MS_WINDOWS)
|
||||||
|
|
||||||
PyDoc_STRVAR(os__getvolumepathname__doc__,
|
PyDoc_STRVAR(os__getvolumepathname__doc__,
|
||||||
"_getvolumepathname($module, /, path)\n"
|
"_getvolumepathname($module, /, path)\n"
|
||||||
"--\n"
|
"--\n"
|
||||||
|
@ -5313,10 +5377,18 @@ exit:
|
||||||
#define OS_LINK_METHODDEF
|
#define OS_LINK_METHODDEF
|
||||||
#endif /* !defined(OS_LINK_METHODDEF) */
|
#endif /* !defined(OS_LINK_METHODDEF) */
|
||||||
|
|
||||||
|
#ifndef OS__GETFULLPATHNAME_METHODDEF
|
||||||
|
#define OS__GETFULLPATHNAME_METHODDEF
|
||||||
|
#endif /* !defined(OS__GETFULLPATHNAME_METHODDEF) */
|
||||||
|
|
||||||
#ifndef OS__GETFINALPATHNAME_METHODDEF
|
#ifndef OS__GETFINALPATHNAME_METHODDEF
|
||||||
#define OS__GETFINALPATHNAME_METHODDEF
|
#define OS__GETFINALPATHNAME_METHODDEF
|
||||||
#endif /* !defined(OS__GETFINALPATHNAME_METHODDEF) */
|
#endif /* !defined(OS__GETFINALPATHNAME_METHODDEF) */
|
||||||
|
|
||||||
|
#ifndef OS__ISDIR_METHODDEF
|
||||||
|
#define OS__ISDIR_METHODDEF
|
||||||
|
#endif /* !defined(OS__ISDIR_METHODDEF) */
|
||||||
|
|
||||||
#ifndef OS__GETVOLUMEPATHNAME_METHODDEF
|
#ifndef OS__GETVOLUMEPATHNAME_METHODDEF
|
||||||
#define OS__GETVOLUMEPATHNAME_METHODDEF
|
#define OS__GETVOLUMEPATHNAME_METHODDEF
|
||||||
#endif /* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */
|
#endif /* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */
|
||||||
|
@ -5716,4 +5788,4 @@ exit:
|
||||||
#ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF
|
#ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF
|
||||||
#define OS_SET_HANDLE_INHERITABLE_METHODDEF
|
#define OS_SET_HANDLE_INHERITABLE_METHODDEF
|
||||||
#endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */
|
#endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */
|
||||||
/*[clinic end generated code: output=bba73c13a01c09a0 input=a9049054013a1b77]*/
|
/*[clinic end generated code: output=f3f92b2d2e2c3fe3 input=a9049054013a1b77]*/
|
||||||
|
|
|
@ -3748,62 +3748,53 @@ os_listdir_impl(PyModuleDef *module, path_t *path)
|
||||||
|
|
||||||
#ifdef MS_WINDOWS
|
#ifdef MS_WINDOWS
|
||||||
/* A helper function for abspath on win32 */
|
/* A helper function for abspath on win32 */
|
||||||
/* AC 3.5: probably just convert to using path converter */
|
/*[clinic input]
|
||||||
static PyObject *
|
os._getfullpathname
|
||||||
posix__getfullpathname(PyObject *self, PyObject *args)
|
|
||||||
{
|
|
||||||
const char *path;
|
|
||||||
char outbuf[MAX_PATH];
|
|
||||||
char *temp;
|
|
||||||
PyObject *po;
|
|
||||||
|
|
||||||
if (PyArg_ParseTuple(args, "U|:_getfullpathname", &po))
|
path: path_t
|
||||||
|
/
|
||||||
|
|
||||||
|
[clinic start generated code]*/
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
os__getfullpathname_impl(PyModuleDef *module, path_t *path)
|
||||||
|
/*[clinic end generated code: output=b90b1f103b08773f input=332ed537c29d0a3e]*/
|
||||||
|
{
|
||||||
|
if (!path->narrow)
|
||||||
{
|
{
|
||||||
wchar_t *wpath;
|
|
||||||
wchar_t woutbuf[MAX_PATH], *woutbufp = woutbuf;
|
wchar_t woutbuf[MAX_PATH], *woutbufp = woutbuf;
|
||||||
wchar_t *wtemp;
|
wchar_t *wtemp;
|
||||||
DWORD result;
|
DWORD result;
|
||||||
PyObject *v;
|
PyObject *v;
|
||||||
|
|
||||||
wpath = PyUnicode_AsUnicode(po);
|
result = GetFullPathNameW(path->wide,
|
||||||
if (wpath == NULL)
|
|
||||||
return NULL;
|
|
||||||
result = GetFullPathNameW(wpath,
|
|
||||||
Py_ARRAY_LENGTH(woutbuf),
|
Py_ARRAY_LENGTH(woutbuf),
|
||||||
woutbuf, &wtemp);
|
woutbuf, &wtemp);
|
||||||
if (result > Py_ARRAY_LENGTH(woutbuf)) {
|
if (result > Py_ARRAY_LENGTH(woutbuf)) {
|
||||||
woutbufp = PyMem_New(wchar_t, result);
|
woutbufp = PyMem_New(wchar_t, result);
|
||||||
if (!woutbufp)
|
if (!woutbufp)
|
||||||
return PyErr_NoMemory();
|
return PyErr_NoMemory();
|
||||||
result = GetFullPathNameW(wpath, result, woutbufp, &wtemp);
|
result = GetFullPathNameW(path->wide, result, woutbufp, &wtemp);
|
||||||
}
|
}
|
||||||
if (result)
|
if (result)
|
||||||
v = PyUnicode_FromWideChar(woutbufp, wcslen(woutbufp));
|
v = PyUnicode_FromWideChar(woutbufp, wcslen(woutbufp));
|
||||||
else
|
else
|
||||||
v = win32_error_object("GetFullPathNameW", po);
|
v = win32_error_object("GetFullPathNameW", path->object);
|
||||||
if (woutbufp != woutbuf)
|
if (woutbufp != woutbuf)
|
||||||
PyMem_Free(woutbufp);
|
PyMem_Free(woutbufp);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
/* Drop the argument parsing error as narrow strings
|
else {
|
||||||
are also valid. */
|
char outbuf[MAX_PATH];
|
||||||
PyErr_Clear();
|
char *temp;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple (args, "y:_getfullpathname",
|
if (!GetFullPathName(path->narrow, Py_ARRAY_LENGTH(outbuf),
|
||||||
&path))
|
outbuf, &temp)) {
|
||||||
return NULL;
|
win32_error_object("GetFullPathName", path->object);
|
||||||
if (win32_warn_bytes_api())
|
return NULL;
|
||||||
return NULL;
|
}
|
||||||
if (!GetFullPathName(path, Py_ARRAY_LENGTH(outbuf),
|
return PyBytes_FromString(outbuf);
|
||||||
outbuf, &temp)) {
|
|
||||||
win32_error("GetFullPathName", path);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
if (PyUnicode_Check(PyTuple_GetItem(args, 0))) {
|
|
||||||
return PyUnicode_Decode(outbuf, strlen(outbuf),
|
|
||||||
Py_FileSystemDefaultEncoding, NULL);
|
|
||||||
}
|
|
||||||
return PyBytes_FromString(outbuf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -3872,37 +3863,28 @@ os__getfinalpathname_impl(PyModuleDef *module, PyObject *path)
|
||||||
PyDoc_STRVAR(posix__isdir__doc__,
|
PyDoc_STRVAR(posix__isdir__doc__,
|
||||||
"Return true if the pathname refers to an existing directory.");
|
"Return true if the pathname refers to an existing directory.");
|
||||||
|
|
||||||
/* AC 3.5: convert using path converter */
|
/*[clinic input]
|
||||||
|
os._isdir
|
||||||
|
|
||||||
|
path: path_t
|
||||||
|
/
|
||||||
|
|
||||||
|
[clinic start generated code]*/
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
posix__isdir(PyObject *self, PyObject *args)
|
os__isdir_impl(PyModuleDef *module, path_t *path)
|
||||||
|
/*[clinic end generated code: output=f17b2d4e1994b0ff input=e794f12faab62a2a]*/
|
||||||
{
|
{
|
||||||
const char *path;
|
|
||||||
PyObject *po;
|
|
||||||
DWORD attributes;
|
DWORD attributes;
|
||||||
|
|
||||||
if (PyArg_ParseTuple(args, "U|:_isdir", &po)) {
|
if (!path->narrow)
|
||||||
wchar_t *wpath = PyUnicode_AsUnicode(po);
|
attributes = GetFileAttributesW(path->wide);
|
||||||
if (wpath == NULL)
|
else
|
||||||
return NULL;
|
attributes = GetFileAttributesA(path->narrow);
|
||||||
|
|
||||||
attributes = GetFileAttributesW(wpath);
|
|
||||||
if (attributes == INVALID_FILE_ATTRIBUTES)
|
|
||||||
Py_RETURN_FALSE;
|
|
||||||
goto check;
|
|
||||||
}
|
|
||||||
/* Drop the argument parsing error as narrow strings
|
|
||||||
are also valid. */
|
|
||||||
PyErr_Clear();
|
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "y:_isdir", &path))
|
|
||||||
return NULL;
|
|
||||||
if (win32_warn_bytes_api())
|
|
||||||
return NULL;
|
|
||||||
attributes = GetFileAttributesA(path);
|
|
||||||
if (attributes == INVALID_FILE_ATTRIBUTES)
|
if (attributes == INVALID_FILE_ATTRIBUTES)
|
||||||
Py_RETURN_FALSE;
|
Py_RETURN_FALSE;
|
||||||
|
|
||||||
check:
|
|
||||||
if (attributes & FILE_ATTRIBUTE_DIRECTORY)
|
if (attributes & FILE_ATTRIBUTE_DIRECTORY)
|
||||||
Py_RETURN_TRUE;
|
Py_RETURN_TRUE;
|
||||||
else
|
else
|
||||||
|
@ -12351,10 +12333,8 @@ static PyMethodDef posix_methods[] = {
|
||||||
OS_FPATHCONF_METHODDEF
|
OS_FPATHCONF_METHODDEF
|
||||||
OS_PATHCONF_METHODDEF
|
OS_PATHCONF_METHODDEF
|
||||||
OS_ABORT_METHODDEF
|
OS_ABORT_METHODDEF
|
||||||
#ifdef MS_WINDOWS
|
OS__GETFULLPATHNAME_METHODDEF
|
||||||
{"_getfullpathname", posix__getfullpathname, METH_VARARGS, NULL},
|
OS__ISDIR_METHODDEF
|
||||||
{"_isdir", posix__isdir, METH_VARARGS, posix__isdir__doc__},
|
|
||||||
#endif
|
|
||||||
OS__GETDISKUSAGE_METHODDEF
|
OS__GETDISKUSAGE_METHODDEF
|
||||||
OS__GETFINALPATHNAME_METHODDEF
|
OS__GETFINALPATHNAME_METHODDEF
|
||||||
OS__GETVOLUMEPATHNAME_METHODDEF
|
OS__GETVOLUMEPATHNAME_METHODDEF
|
||||||
|
|
Loading…
Reference in New Issue