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)
|
||||
|
||||
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__,
|
||||
"_getfinalpathname($module, path, /)\n"
|
||||
"--\n"
|
||||
|
@ -920,6 +952,38 @@ exit:
|
|||
|
||||
#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__,
|
||||
"_getvolumepathname($module, /, path)\n"
|
||||
"--\n"
|
||||
|
@ -5313,10 +5377,18 @@ exit:
|
|||
#define 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
|
||||
#define 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
|
||||
#define OS__GETVOLUMEPATHNAME_METHODDEF
|
||||
#endif /* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */
|
||||
|
@ -5716,4 +5788,4 @@ exit:
|
|||
#ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF
|
||||
#define 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
|
||||
/* A helper function for abspath on win32 */
|
||||
/* AC 3.5: probably just convert to using path converter */
|
||||
static PyObject *
|
||||
posix__getfullpathname(PyObject *self, PyObject *args)
|
||||
{
|
||||
const char *path;
|
||||
char outbuf[MAX_PATH];
|
||||
char *temp;
|
||||
PyObject *po;
|
||||
/*[clinic input]
|
||||
os._getfullpathname
|
||||
|
||||
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 *wtemp;
|
||||
DWORD result;
|
||||
PyObject *v;
|
||||
|
||||
wpath = PyUnicode_AsUnicode(po);
|
||||
if (wpath == NULL)
|
||||
return NULL;
|
||||
result = GetFullPathNameW(wpath,
|
||||
result = GetFullPathNameW(path->wide,
|
||||
Py_ARRAY_LENGTH(woutbuf),
|
||||
woutbuf, &wtemp);
|
||||
if (result > Py_ARRAY_LENGTH(woutbuf)) {
|
||||
woutbufp = PyMem_New(wchar_t, result);
|
||||
if (!woutbufp)
|
||||
return PyErr_NoMemory();
|
||||
result = GetFullPathNameW(wpath, result, woutbufp, &wtemp);
|
||||
result = GetFullPathNameW(path->wide, result, woutbufp, &wtemp);
|
||||
}
|
||||
if (result)
|
||||
v = PyUnicode_FromWideChar(woutbufp, wcslen(woutbufp));
|
||||
else
|
||||
v = win32_error_object("GetFullPathNameW", po);
|
||||
v = win32_error_object("GetFullPathNameW", path->object);
|
||||
if (woutbufp != woutbuf)
|
||||
PyMem_Free(woutbufp);
|
||||
return v;
|
||||
}
|
||||
/* Drop the argument parsing error as narrow strings
|
||||
are also valid. */
|
||||
PyErr_Clear();
|
||||
else {
|
||||
char outbuf[MAX_PATH];
|
||||
char *temp;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "y:_getfullpathname",
|
||||
&path))
|
||||
return NULL;
|
||||
if (win32_warn_bytes_api())
|
||||
return NULL;
|
||||
if (!GetFullPathName(path, Py_ARRAY_LENGTH(outbuf),
|
||||
outbuf, &temp)) {
|
||||
win32_error("GetFullPathName", path);
|
||||
return NULL;
|
||||
if (!GetFullPathName(path->narrow, Py_ARRAY_LENGTH(outbuf),
|
||||
outbuf, &temp)) {
|
||||
win32_error_object("GetFullPathName", path->object);
|
||||
return NULL;
|
||||
}
|
||||
return PyBytes_FromString(outbuf);
|
||||
}
|
||||
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__,
|
||||
"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 *
|
||||
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;
|
||||
|
||||
if (PyArg_ParseTuple(args, "U|:_isdir", &po)) {
|
||||
wchar_t *wpath = PyUnicode_AsUnicode(po);
|
||||
if (wpath == NULL)
|
||||
return NULL;
|
||||
if (!path->narrow)
|
||||
attributes = GetFileAttributesW(path->wide);
|
||||
else
|
||||
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)
|
||||
Py_RETURN_FALSE;
|
||||
|
||||
check:
|
||||
if (attributes & FILE_ATTRIBUTE_DIRECTORY)
|
||||
Py_RETURN_TRUE;
|
||||
else
|
||||
|
@ -12351,10 +12333,8 @@ static PyMethodDef posix_methods[] = {
|
|||
OS_FPATHCONF_METHODDEF
|
||||
OS_PATHCONF_METHODDEF
|
||||
OS_ABORT_METHODDEF
|
||||
#ifdef MS_WINDOWS
|
||||
{"_getfullpathname", posix__getfullpathname, METH_VARARGS, NULL},
|
||||
{"_isdir", posix__isdir, METH_VARARGS, posix__isdir__doc__},
|
||||
#endif
|
||||
OS__GETFULLPATHNAME_METHODDEF
|
||||
OS__ISDIR_METHODDEF
|
||||
OS__GETDISKUSAGE_METHODDEF
|
||||
OS__GETFINALPATHNAME_METHODDEF
|
||||
OS__GETVOLUMEPATHNAME_METHODDEF
|
||||
|
|
Loading…
Reference in New Issue