Source

python-clinic / Modules / posixmodule_clinic.c


PyDoc_STRVAR(os_stat__doc__,
"os.stat(path, *[, dir_fd=None[, follow_symlinks=True]]) -> stat result\n"
"\n"
"Perform a stat system call on the given path.\n"
"\n"
"path\n"
"    Path to be examined; can be string, bytes, or open-file-descriptor int.\n"
"\n"
"dir_fd\n"
"    If not None, it should be a file descriptor open to a directory,\n"
"    and path should be a relative string; path will then be relative to\n"
"    that directory.\n"
"\n"
"follow_symlinks\n"
"    If False, and the last element of the path is a symbolic link,\n"
"    stat will examine the symbolic link itself instead of the file\n"
"    the link points to.\n"
"\n"
"dir_fd and follow_symlinks may not be implemented\n"
"  on your platform.  If they are unavailable, using them will raise a\n"
"  NotImplementedError.\n"
"\n"
"It's an error to use dir_fd or follow_symlinks when specifying path as\n"
"  an open file descriptor.\n"
"\n");

#define OS_STAT_METHODDEF    \
    {"stat", (PyCFunction)os_stat, METH_VARARGS | METH_KEYWORDS, os_stat__doc__}

static PyObject *
os_stat_impl(PyObject *self, path_t path, int dir_fd, int follow_symlinks);

static PyObject *
os_stat(PyObject *self, PyObject *args, PyObject *kwargs)
{
    PyObject *_return_value;
    path_t path = PATH_T_INITIALIZE("stat", 0, 1);
    int dir_fd = DEFAULT_DIR_FD;
    int follow_symlinks = 1;
    static char *_keywords[] = {"path", "dir_fd", "follow_symlinks", NULL};

    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
        "O&|$O&p:stat", _keywords,
        path_converter, &path, OS_STAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks))
        return NULL;

    _return_value = os_stat_impl(self, path, dir_fd, follow_symlinks);
    path_cleanup(&path);
    return _return_value;
}



PyDoc_STRVAR(os_access__doc__,
"os.access(path, mode, *[, dir_fd=None[, effective_ids=False[, follow_symlinks=True]]])\n"
"\n"
"Use the real uid/gid to test for access to a path.\n"
"Returns True if granted, False otherwise.\n"
"\n"
"path\n"
"    Path to be tested; can be string, bytes, or open-file-descriptor int.\n"
"\n"
"mode\n"
"    Operating-system mode bitfield.  Can be F_OK to test existence,\n"
"    or the inclusive-OR of R_OK, W_OK, and X_OK.\n"
"\n"
"dir_fd\n"
"    If not None, it should be a file descriptor open to a directory,\n"
"    and path should be relative; path will then be relative to that\n"
"    directory.\n"
"\n"
"effective_ids\n"
"    If True, access will use the effective uid/gid instead of\n"
"    the real uid/gid.\n"
"\n"
"follow_symlinks\n"
"    If False, and the last element of the path is a symbolic link,\n"
"    access will examine the symbolic link itself instead of the file\n"
"    the link points to.\n"
"\n"
"dir_fd, effective_ids, and follow_symlinks may not be implemented\n"
"  on your platform.  If they are unavailable, using them will raise a\n"
"  NotImplementedError.\n"
"\n"
"Note that most operations will use the effective uid/gid, therefore this\n"
"  routine can be used in a suid/sgid environment to test if the invoking user\n"
"  has the specified access to the path.\n"
"\n");

#define OS_ACCESS_METHODDEF    \
    {"access", (PyCFunction)os_access, METH_VARARGS | METH_KEYWORDS, os_access__doc__}

static PyObject *
os_access_impl(PyObject *self, path_t path, int mode, int dir_fd, int effective_ids, int follow_symlinks);

static PyObject *
os_access(PyObject *self, PyObject *args, PyObject *kwargs)
{
    PyObject *_return_value;
    path_t path = PATH_T_INITIALIZE("access", 0, 1);
    int mode;
    int dir_fd = DEFAULT_DIR_FD;
    int effective_ids = 0;
    int follow_symlinks = 1;
    static char *_keywords[] = {"path", "mode", "dir_fd", "effective_ids", "follow_symlinks", NULL};

    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
        "O&i|$O&pp:access", _keywords,
        path_converter, &path, &mode, OS_ACCESS_DIR_FD_CONVERTER, &dir_fd, &effective_ids, &follow_symlinks))
        return NULL;

    _return_value = os_access_impl(self, path, mode, dir_fd, effective_ids, follow_symlinks);
    path_cleanup(&path);
    return _return_value;
}