Coverage Report

Created: 2026-10-17 06:15

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/cpython/Modules/clinic/getpath.c.h
Line
Count
Source
1
/*[clinic input]
2
preserve
3
[clinic start generated code]*/
4
5
#include "pycore_modsupport.h"    // _PyArg_BadArgument()
6
7
PyDoc_STRVAR(getpath_abspath__doc__,
8
"abspath($module, path, /)\n"
9
"--\n"
10
"\n"
11
"Return the absolute path.");
12
13
#define GETPATH_ABSPATH_METHODDEF    \
14
    {"abspath", (PyCFunction)getpath_abspath, METH_O, getpath_abspath__doc__},
15
16
static PyObject *
17
getpath_abspath_impl(PyObject *module, const wchar_t *path);
18
19
static PyObject *
20
getpath_abspath(PyObject *module, PyObject *arg)
21
0
{
22
0
    PyObject *return_value = NULL;
23
0
    const wchar_t *path = NULL;
24
25
0
    if (!PyUnicode_Check(arg)) {
26
0
        _PyArg_BadArgument("abspath", "argument", "str", arg);
27
0
        goto exit;
28
0
    }
29
0
    path = PyUnicode_AsWideCharString(arg, NULL);
30
0
    if (path == NULL) {
31
0
        goto exit;
32
0
    }
33
0
    return_value = getpath_abspath_impl(module, path);
34
35
0
exit:
36
    /* Cleanup for path */
37
0
    PyMem_Free((void *)path);
38
39
0
    return return_value;
40
0
}
41
42
PyDoc_STRVAR(getpath_basename__doc__,
43
"basename($module, path, /)\n"
44
"--\n"
45
"\n"
46
"Return the final component of the path.");
47
48
#define GETPATH_BASENAME_METHODDEF    \
49
    {"basename", (PyCFunction)getpath_basename, METH_O, getpath_basename__doc__},
50
51
static PyObject *
52
getpath_basename_impl(PyObject *module, PyObject *path);
53
54
static PyObject *
55
getpath_basename(PyObject *module, PyObject *arg)
56
0
{
57
0
    PyObject *return_value = NULL;
58
0
    PyObject *path;
59
60
0
    if (!PyUnicode_Check(arg)) {
61
0
        _PyArg_BadArgument("basename", "argument", "str", arg);
62
0
        goto exit;
63
0
    }
64
0
    path = arg;
65
0
    return_value = getpath_basename_impl(module, path);
66
67
0
exit:
68
0
    return return_value;
69
0
}
70
71
PyDoc_STRVAR(getpath_dirname__doc__,
72
"dirname($module, path, /)\n"
73
"--\n"
74
"\n"
75
"Return the directory component of the path.");
76
77
#define GETPATH_DIRNAME_METHODDEF    \
78
    {"dirname", (PyCFunction)getpath_dirname, METH_O, getpath_dirname__doc__},
79
80
static PyObject *
81
getpath_dirname_impl(PyObject *module, PyObject *path);
82
83
static PyObject *
84
getpath_dirname(PyObject *module, PyObject *arg)
85
111
{
86
111
    PyObject *return_value = NULL;
87
111
    PyObject *path;
88
89
111
    if (!PyUnicode_Check(arg)) {
90
0
        _PyArg_BadArgument("dirname", "argument", "str", arg);
91
0
        goto exit;
92
0
    }
93
111
    path = arg;
94
111
    return_value = getpath_dirname_impl(module, path);
95
96
111
exit:
97
111
    return return_value;
98
111
}
99
100
PyDoc_STRVAR(getpath_isabs__doc__,
101
"isabs($module, path, /)\n"
102
"--\n"
103
"\n"
104
"Return True if the path is absolute.");
105
106
#define GETPATH_ISABS_METHODDEF    \
107
    {"isabs", (PyCFunction)getpath_isabs, METH_O, getpath_isabs__doc__},
108
109
static int
110
getpath_isabs_impl(PyObject *module, const wchar_t *path);
111
112
static PyObject *
113
getpath_isabs(PyObject *module, PyObject *arg)
114
0
{
115
0
    PyObject *return_value = NULL;
116
0
    const wchar_t *path = NULL;
117
0
    int _return_value;
118
119
0
    if (!PyUnicode_Check(arg)) {
120
0
        _PyArg_BadArgument("isabs", "argument", "str", arg);
121
0
        goto exit;
122
0
    }
123
0
    path = PyUnicode_AsWideCharString(arg, NULL);
124
0
    if (path == NULL) {
125
0
        goto exit;
126
0
    }
127
0
    _return_value = getpath_isabs_impl(module, path);
128
0
    if ((_return_value == -1) && PyErr_Occurred()) {
129
0
        goto exit;
130
0
    }
131
0
    return_value = PyBool_FromLong((long)_return_value);
132
133
0
exit:
134
    /* Cleanup for path */
135
0
    PyMem_Free((void *)path);
136
137
0
    return return_value;
138
0
}
139
140
PyDoc_STRVAR(getpath_hassuffix__doc__,
141
"hassuffix($module, path, suffix, /)\n"
142
"--\n"
143
"\n"
144
"Return True if the path ends with the suffix, ignoring the case.");
145
146
#define GETPATH_HASSUFFIX_METHODDEF    \
147
    {"hassuffix", _PyCFunction_CAST(getpath_hassuffix), METH_FASTCALL, getpath_hassuffix__doc__},
148
149
static int
150
getpath_hassuffix_impl(PyObject *module, PyObject *pathobj,
151
                       PyObject *suffixobj);
152
153
static PyObject *
154
getpath_hassuffix(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
155
0
{
156
0
    PyObject *return_value = NULL;
157
0
    PyObject *pathobj;
158
0
    PyObject *suffixobj;
159
0
    int _return_value;
160
161
0
    if (!_PyArg_CheckPositional("hassuffix", nargs, 2, 2)) {
162
0
        goto exit;
163
0
    }
164
0
    if (!PyUnicode_Check(args[0])) {
165
0
        _PyArg_BadArgument("hassuffix", "argument 1", "str", args[0]);
166
0
        goto exit;
167
0
    }
168
0
    pathobj = args[0];
169
0
    if (!PyUnicode_Check(args[1])) {
170
0
        _PyArg_BadArgument("hassuffix", "argument 2", "str", args[1]);
171
0
        goto exit;
172
0
    }
173
0
    suffixobj = args[1];
174
0
    _return_value = getpath_hassuffix_impl(module, pathobj, suffixobj);
175
0
    if ((_return_value == -1) && PyErr_Occurred()) {
176
0
        goto exit;
177
0
    }
178
0
    return_value = PyBool_FromLong((long)_return_value);
179
180
0
exit:
181
0
    return return_value;
182
0
}
183
184
PyDoc_STRVAR(getpath_isdir__doc__,
185
"isdir($module, path, /)\n"
186
"--\n"
187
"\n"
188
"Return True if the path is a directory.");
189
190
#define GETPATH_ISDIR_METHODDEF    \
191
    {"isdir", (PyCFunction)getpath_isdir, METH_O, getpath_isdir__doc__},
192
193
static int
194
getpath_isdir_impl(PyObject *module, const wchar_t *path);
195
196
static PyObject *
197
getpath_isdir(PyObject *module, PyObject *arg)
198
74
{
199
74
    PyObject *return_value = NULL;
200
74
    const wchar_t *path = NULL;
201
74
    int _return_value;
202
203
74
    if (!PyUnicode_Check(arg)) {
204
0
        _PyArg_BadArgument("isdir", "argument", "str", arg);
205
0
        goto exit;
206
0
    }
207
74
    path = PyUnicode_AsWideCharString(arg, NULL);
208
74
    if (path == NULL) {
209
0
        goto exit;
210
0
    }
211
74
    _return_value = getpath_isdir_impl(module, path);
212
74
    if ((_return_value == -1) && PyErr_Occurred()) {
213
0
        goto exit;
214
0
    }
215
74
    return_value = PyBool_FromLong((long)_return_value);
216
217
74
exit:
218
    /* Cleanup for path */
219
74
    PyMem_Free((void *)path);
220
221
74
    return return_value;
222
74
}
223
224
PyDoc_STRVAR(getpath_isfile__doc__,
225
"isfile($module, path, /)\n"
226
"--\n"
227
"\n"
228
"Return True if the path is a regular file.");
229
230
#define GETPATH_ISFILE_METHODDEF    \
231
    {"isfile", (PyCFunction)getpath_isfile, METH_O, getpath_isfile__doc__},
232
233
static int
234
getpath_isfile_impl(PyObject *module, PyObject *pathobj);
235
236
static PyObject *
237
getpath_isfile(PyObject *module, PyObject *arg)
238
37
{
239
37
    PyObject *return_value = NULL;
240
37
    PyObject *pathobj;
241
37
    int _return_value;
242
243
37
    if (!PyUnicode_Check(arg)) {
244
0
        _PyArg_BadArgument("isfile", "argument", "str", arg);
245
0
        goto exit;
246
0
    }
247
37
    pathobj = arg;
248
37
    _return_value = getpath_isfile_impl(module, pathobj);
249
37
    if ((_return_value == -1) && PyErr_Occurred()) {
250
0
        goto exit;
251
0
    }
252
37
    return_value = PyBool_FromLong((long)_return_value);
253
254
37
exit:
255
37
    return return_value;
256
37
}
257
258
PyDoc_STRVAR(getpath_isxfile__doc__,
259
"isxfile($module, path, /)\n"
260
"--\n"
261
"\n"
262
"Return True if the path is an executable file.");
263
264
#define GETPATH_ISXFILE_METHODDEF    \
265
    {"isxfile", (PyCFunction)getpath_isxfile, METH_O, getpath_isxfile__doc__},
266
267
static int
268
getpath_isxfile_impl(PyObject *module, PyObject *pathobj);
269
270
static PyObject *
271
getpath_isxfile(PyObject *module, PyObject *arg)
272
74
{
273
74
    PyObject *return_value = NULL;
274
74
    PyObject *pathobj;
275
74
    int _return_value;
276
277
74
    if (!PyUnicode_Check(arg)) {
278
0
        _PyArg_BadArgument("isxfile", "argument", "str", arg);
279
0
        goto exit;
280
0
    }
281
74
    pathobj = arg;
282
74
    _return_value = getpath_isxfile_impl(module, pathobj);
283
74
    if ((_return_value == -1) && PyErr_Occurred()) {
284
0
        goto exit;
285
0
    }
286
74
    return_value = PyBool_FromLong((long)_return_value);
287
288
74
exit:
289
74
    return return_value;
290
74
}
291
292
PyDoc_STRVAR(getpath_joinpath__doc__,
293
"joinpath($module, /, *args)\n"
294
"--\n"
295
"\n"
296
"Join the path components.");
297
298
#define GETPATH_JOINPATH_METHODDEF    \
299
    {"joinpath", _PyCFunction_CAST(getpath_joinpath), METH_FASTCALL, getpath_joinpath__doc__},
300
301
static PyObject *
302
getpath_joinpath_impl(PyObject *module, PyObject *args);
303
304
static PyObject *
305
getpath_joinpath(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
306
296
{
307
296
    PyObject *return_value = NULL;
308
296
    PyObject *__clinic_args = NULL;
309
310
296
    __clinic_args = PyTuple_FromArray(args, nargs);
311
296
    if (__clinic_args == NULL) {
312
0
        goto exit;
313
0
    }
314
296
    return_value = getpath_joinpath_impl(module, __clinic_args);
315
316
296
exit:
317
    /* Cleanup for args */
318
296
    Py_XDECREF(__clinic_args);
319
320
296
    return return_value;
321
296
}
322
323
PyDoc_STRVAR(getpath_readlines__doc__,
324
"readlines($module, path, /)\n"
325
"--\n"
326
"\n"
327
"Return the lines of the file.");
328
329
#define GETPATH_READLINES_METHODDEF    \
330
    {"readlines", (PyCFunction)getpath_readlines, METH_O, getpath_readlines__doc__},
331
332
static PyObject *
333
getpath_readlines_impl(PyObject *module, PyObject *pathobj);
334
335
static PyObject *
336
getpath_readlines(PyObject *module, PyObject *arg)
337
185
{
338
185
    PyObject *return_value = NULL;
339
185
    PyObject *pathobj;
340
341
185
    if (!PyUnicode_Check(arg)) {
342
0
        _PyArg_BadArgument("readlines", "argument", "str", arg);
343
0
        goto exit;
344
0
    }
345
185
    pathobj = arg;
346
185
    return_value = getpath_readlines_impl(module, pathobj);
347
348
185
exit:
349
185
    return return_value;
350
185
}
351
352
PyDoc_STRVAR(getpath_realpath__doc__,
353
"realpath($module, path, /)\n"
354
"--\n"
355
"\n"
356
"Resolve a symlinked file.");
357
358
#define GETPATH_REALPATH_METHODDEF    \
359
    {"realpath", (PyCFunction)getpath_realpath, METH_O, getpath_realpath__doc__},
360
361
static PyObject *
362
getpath_realpath_impl(PyObject *module, PyObject *pathobj);
363
364
static PyObject *
365
getpath_realpath(PyObject *module, PyObject *arg)
366
37
{
367
37
    PyObject *return_value = NULL;
368
37
    PyObject *pathobj;
369
370
37
    if (!PyUnicode_Check(arg)) {
371
0
        _PyArg_BadArgument("realpath", "argument", "str", arg);
372
0
        goto exit;
373
0
    }
374
37
    pathobj = arg;
375
37
    return_value = getpath_realpath_impl(module, pathobj);
376
377
37
exit:
378
37
    return return_value;
379
37
}
380
/*[clinic end generated code: output=74266cdd2d87e28d input=a9049054013a1b77]*/