return False
-def getsize(filename):
+def getsize(filename, /):
"""Return the size of a file, reported by os.stat()."""
return os.stat(filename).st_size
-def getmtime(filename):
+def getmtime(filename, /):
"""Return the last modification time of a file, reported by os.stat()."""
return os.stat(filename).st_mtime
-def getatime(filename):
+def getatime(filename, /):
"""Return the last access time of a file, reported by os.stat()."""
return os.stat(filename).st_atime
-def getctime(filename):
+def getctime(filename, /):
"""Return the metadata change time of a file, reported by os.stat()."""
return os.stat(filename).st_ctime
# Return the longest prefix of all list elements.
-def commonprefix(m):
+def commonprefix(m, /):
"Given a list of pathnames, returns the longest common leading component"
if not m: return ''
# Some people pass in a list of pathname parts to operate in an OS-agnostic
# Are two stat buffers (obtained from stat, fstat or lstat)
# describing the same file?
-def samestat(s1, s2):
+def samestat(s1, s2, /):
"""Test whether two stat buffers reference the same file"""
return (s1.st_ino == s2.st_ino and
s1.st_dev == s2.st_dev)
# Are two filenames really pointing to the same file?
-def samefile(f1, f2):
+def samefile(f1, f2, /):
"""Test whether two pathnames reference the same actual file or directory
This is determined by the device number and i-node number and
LOCALE_NAME_INVARIANT as _LOCALE_NAME_INVARIANT,
LCMAP_LOWERCASE as _LCMAP_LOWERCASE)
- def normcase(s):
+ def normcase(s, /):
"""Normalize case of pathname.
Makes all characters lowercase and all slashes into backslashes.
_LCMAP_LOWERCASE,
s.replace('/', '\\'))
except ImportError:
- def normcase(s):
+ def normcase(s, /):
"""Normalize case of pathname.
Makes all characters lowercase and all slashes into backslashes.
return s.replace('/', '\\').lower()
-def isabs(s):
+def isabs(s, /):
"""Test whether a path is absolute"""
s = os.fspath(s)
if isinstance(s, bytes):
# Join two (or more) paths.
-def join(path, *paths):
+def join(path, /, *paths):
path = os.fspath(path)
if isinstance(path, bytes):
sep = b'\\'
# Split a path in a drive specification (a drive letter followed by a
# colon) and the path specification.
# It is always true that drivespec + pathspec == p
-def splitdrive(p):
+def splitdrive(p, /):
"""Split a pathname into drive/UNC sharepoint and relative path specifiers.
Returns a 2-tuple (drive_or_unc, path); either part may be empty.
try:
from nt import _path_splitroot_ex as splitroot
except ImportError:
- def splitroot(p):
+ def splitroot(p, /):
"""Split a pathname into drive, root and tail.
The tail contains anything after the root."""
# join(head, tail) == p holds.
# The resulting head won't end in '/' unless it is the root.
-def split(p):
+def split(p, /):
"""Split a pathname.
Return tuple (head, tail) where tail is everything after the final slash.
# pathname component; the root is everything before that.
# It is always true that root + ext == p.
-def splitext(p):
+def splitext(p, /):
p = os.fspath(p)
if isinstance(p, bytes):
return genericpath._splitext(p, b'\\', b'/', b'.')
# Return the tail (basename) part of a path.
-def basename(p):
+def basename(p, /):
"""Returns the final component of a pathname"""
return split(p)[1]
# Return the head (dirname) part of a path.
-def dirname(p):
+def dirname(p, /):
"""Returns the directory component of a pathname"""
return split(p)[0]
from nt import _findfirstfile, _getfinalpathname, readlink as _nt_readlink
except ImportError:
# realpath is a no-op on systems without _getfinalpathname support.
- def realpath(path, *, strict=False):
+ def realpath(path, /, *, strict=False):
return abspath(path)
else:
def _readlink_deep(path, ignored_error=OSError):
tail = join(name, tail) if tail else name
return tail
- def realpath(path, *, strict=False):
+ def realpath(path, /, *, strict=False):
path = normpath(path)
if isinstance(path, bytes):
prefix = b'\\\\?\\'
# normalizations (such as optimizing '../' away) are not allowed
# (another function should be defined to do that).
-def normcase(s):
+def normcase(s, /):
"""Normalize case of pathname. Has no effect under Posix"""
return os.fspath(s)
# Return whether a path is absolute.
# Trivial in Posix, harder on the Mac or MS-DOS.
-def isabs(s):
+def isabs(s, /):
"""Test whether a path is absolute"""
s = os.fspath(s)
sep = _get_sep(s)
# Ignore the previous parts if a part is absolute.
# Insert a '/' unless the first part is empty or already ends in '/'.
-def join(a, *p):
+def join(a, /, *p):
"""Join two or more pathname components, inserting '/' as needed.
If any component is an absolute path, all previous path components
will be discarded. An empty last part will result in a path that
# '/' in the path, head will be empty.
# Trailing '/'es are stripped from head unless it is the root.
-def split(p):
+def split(p, /):
"""Split a pathname. Returns tuple "(head, tail)" where "tail" is
everything after the final slash. Either part may be empty."""
p = os.fspath(p)
# pathname component; the root is everything before that.
# It is always true that root + ext == p.
-def splitext(p):
+def splitext(p, /):
p = os.fspath(p)
if isinstance(p, bytes):
sep = b'/'
# Split a pathname into a drive specification and the rest of the
# path. Useful on DOS/Windows/NT; on Unix, the drive is always empty.
-def splitdrive(p):
+def splitdrive(p, /):
"""Split a pathname into drive and path. On Posix, drive is always
empty."""
p = os.fspath(p)
try:
from posix import _path_splitroot_ex as splitroot
except ImportError:
- def splitroot(p):
+ def splitroot(p, /):
"""Split a pathname into drive, root and tail.
The tail contains anything after the root."""
# Return the tail (basename) part of a path, same as split(path)[1].
-def basename(p):
+def basename(p, /):
"""Returns the final component of a pathname"""
p = os.fspath(p)
sep = _get_sep(p)
# Return the head (dirname) part of a path, same as split(path)[0].
-def dirname(p):
+def dirname(p, /):
"""Returns the directory component of a pathname"""
p = os.fspath(p)
sep = _get_sep(p)
# Return a canonical path (i.e. the absolute location of a file on the
# filesystem).
-def realpath(filename, *, strict=False):
+def realpath(filename, /, *, strict=False):
"""Return the canonical path of the specified filename, eliminating any
symbolic links encountered in the path."""
filename = os.fspath(filename)
#if defined(MS_WINDOWS)
PyDoc_STRVAR(os__path_splitroot__doc__,
-"_path_splitroot($module, /, path)\n"
+"_path_splitroot($module, path, /)\n"
"--\n"
"\n"
"Removes everything after the root on Win32.");
#define OS__PATH_SPLITROOT_METHODDEF \
- {"_path_splitroot", _PyCFunction_CAST(os__path_splitroot), METH_FASTCALL|METH_KEYWORDS, os__path_splitroot__doc__},
+ {"_path_splitroot", (PyCFunction)os__path_splitroot, METH_O, os__path_splitroot__doc__},
static PyObject *
os__path_splitroot_impl(PyObject *module, path_t *path);
static PyObject *
-os__path_splitroot(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+os__path_splitroot(PyObject *module, PyObject *arg)
{
PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-
- #define NUM_KEYWORDS 1
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- Py_hash_t ob_hash;
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_hash = -1,
- .ob_item = { &_Py_ID(path), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
-
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
-
- static const char * const _keywords[] = {"path", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "_path_splitroot",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[1];
path_t path = PATH_T_INITIALIZE_P("_path_splitroot", "path", 0, 0, 0, 0);
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
- /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!path_converter(args[0], &path)) {
+ if (!path_converter(arg, &path)) {
goto exit;
}
return_value = os__path_splitroot_impl(module, &path);
#if defined(MS_WINDOWS)
PyDoc_STRVAR(os__path_isdir__doc__,
-"_path_isdir($module, /, s)\n"
+"_path_isdir($module, path, /)\n"
"--\n"
"\n"
"Return true if the pathname refers to an existing directory.");
#define OS__PATH_ISDIR_METHODDEF \
- {"_path_isdir", _PyCFunction_CAST(os__path_isdir), METH_FASTCALL|METH_KEYWORDS, os__path_isdir__doc__},
+ {"_path_isdir", (PyCFunction)os__path_isdir, METH_O, os__path_isdir__doc__},
static int
os__path_isdir_impl(PyObject *module, path_t *path);
static PyObject *
-os__path_isdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+os__path_isdir(PyObject *module, PyObject *arg)
{
PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-
- #define NUM_KEYWORDS 1
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- Py_hash_t ob_hash;
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_hash = -1,
- .ob_item = { _Py_LATIN1_CHR('s'), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
-
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
-
- static const char * const _keywords[] = {"s", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "_path_isdir",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[1];
path_t path = PATH_T_INITIALIZE_P("_path_isdir", "path", 0, 0, 1, 1);
int _return_value;
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
- /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!path_converter(args[0], &path)) {
+ if (!path_converter(arg, &path)) {
goto exit;
}
_return_value = os__path_isdir_impl(module, &path);
#endif /* defined(MS_WINDOWS) */
PyDoc_STRVAR(os__path_splitroot_ex__doc__,
-"_path_splitroot_ex($module, /, p)\n"
+"_path_splitroot_ex($module, path, /)\n"
"--\n"
"\n"
"Split a pathname into drive, root and tail.\n"
"The tail contains anything after the root.");
#define OS__PATH_SPLITROOT_EX_METHODDEF \
- {"_path_splitroot_ex", _PyCFunction_CAST(os__path_splitroot_ex), METH_FASTCALL|METH_KEYWORDS, os__path_splitroot_ex__doc__},
+ {"_path_splitroot_ex", (PyCFunction)os__path_splitroot_ex, METH_O, os__path_splitroot_ex__doc__},
static PyObject *
os__path_splitroot_ex_impl(PyObject *module, path_t *path);
static PyObject *
-os__path_splitroot_ex(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+os__path_splitroot_ex(PyObject *module, PyObject *arg)
{
PyObject *return_value = NULL;
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-
- #define NUM_KEYWORDS 1
- static struct {
- PyGC_Head _this_is_not_used;
- PyObject_VAR_HEAD
- Py_hash_t ob_hash;
- PyObject *ob_item[NUM_KEYWORDS];
- } _kwtuple = {
- .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_hash = -1,
- .ob_item = { _Py_LATIN1_CHR('p'), },
- };
- #undef NUM_KEYWORDS
- #define KWTUPLE (&_kwtuple.ob_base.ob_base)
-
- #else // !Py_BUILD_CORE
- # define KWTUPLE NULL
- #endif // !Py_BUILD_CORE
-
- static const char * const _keywords[] = {"p", NULL};
- static _PyArg_Parser _parser = {
- .keywords = _keywords,
- .fname = "_path_splitroot_ex",
- .kwtuple = KWTUPLE,
- };
- #undef KWTUPLE
- PyObject *argsbuf[1];
path_t path = PATH_T_INITIALIZE("_path_splitroot_ex", "path", 0, 1, 1, 0, 0);
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
- /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!path_converter(args[0], &path)) {
+ if (!path_converter(arg, &path)) {
goto exit;
}
return_value = os__path_splitroot_ex_impl(module, &path);
#ifndef OS__EMSCRIPTEN_LOG_METHODDEF
#define OS__EMSCRIPTEN_LOG_METHODDEF
#endif /* !defined(OS__EMSCRIPTEN_LOG_METHODDEF) */
-/*[clinic end generated code: output=608e9bc5f631f688 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=b1e2615384347102 input=a9049054013a1b77]*/
/*[clinic input]
os._path_splitroot
- path: path_t
+ path: path_t,
+ /
Removes everything after the root on Win32.
[clinic start generated code]*/
static PyObject *
os__path_splitroot_impl(PyObject *module, path_t *path)
-/*[clinic end generated code: output=ab7f1a88b654581c input=dc93b1d3984cffb6]*/
+/*[clinic end generated code: output=ab7f1a88b654581c input=42831e41f8458f6d]*/
{
wchar_t *buffer;
wchar_t *end;
/*[clinic input]
os._path_isdir -> bool
- s as path: path_t(allow_fd=True, suppress_value_error=True)
+ path: path_t(allow_fd=True, suppress_value_error=True),
+ /
Return true if the pathname refers to an existing directory.
static int
os__path_isdir_impl(PyObject *module, path_t *path)
-/*[clinic end generated code: output=d5786196f9e2fa7a input=132a3b5301aecf79]*/
+/*[clinic end generated code: output=d5786196f9e2fa7a input=0d3fd790564d244b]*/
{
return _testFileType(path, PY_IFDIR);
}
/*[clinic input]
os._path_splitroot_ex
- p as path: path_t(make_wide=True, nonstrict=True)
+ path: path_t(make_wide=True, nonstrict=True),
+ /
Split a pathname into drive, root and tail.
static PyObject *
os__path_splitroot_ex_impl(PyObject *module, path_t *path)
-/*[clinic end generated code: output=4b0072b6cdf4b611 input=4556b615c7cc13f2]*/
+/*[clinic end generated code: output=4b0072b6cdf4b611 input=4ac47b394d68bd21]*/
{
Py_ssize_t drvsize, rootsize;
PyObject *drv = NULL, *root = NULL, *tail = NULL, *result = NULL;