Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
8fb7bb2f
Commit
8fb7bb2f
authored
Aug 22, 2014
by
Brett Cannon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #20152: Convert the grp module to Argument Clinic.
parent
f2de1fc2
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
140 additions
and
26 deletions
+140
-26
Modules/clinic/grpmodule.c.h
Modules/clinic/grpmodule.c.h
+87
-0
Modules/grpmodule.c
Modules/grpmodule.c
+53
-26
No files found.
Modules/clinic/grpmodule.c.h
0 → 100644
View file @
8fb7bb2f
/*[clinic input]
preserve
[clinic start generated code]*/
PyDoc_STRVAR
(
grp_getgrgid__doc__
,
"getgrgid($module, /, id)
\n
"
"--
\n
"
"
\n
"
"Return the group database entry for the given numeric group ID.
\n
"
"
\n
"
"If id is not valid, raise KeyError."
);
#define GRP_GETGRGID_METHODDEF \
{"getgrgid", (PyCFunction)grp_getgrgid, METH_VARARGS|METH_KEYWORDS, grp_getgrgid__doc__},
static
PyObject
*
grp_getgrgid_impl
(
PyModuleDef
*
module
,
PyObject
*
id
);
static
PyObject
*
grp_getgrgid
(
PyModuleDef
*
module
,
PyObject
*
args
,
PyObject
*
kwargs
)
{
PyObject
*
return_value
=
NULL
;
static
char
*
_keywords
[]
=
{
"id"
,
NULL
};
PyObject
*
id
;
if
(
!
PyArg_ParseTupleAndKeywords
(
args
,
kwargs
,
"O:getgrgid"
,
_keywords
,
&
id
))
goto
exit
;
return_value
=
grp_getgrgid_impl
(
module
,
id
);
exit:
return
return_value
;
}
PyDoc_STRVAR
(
grp_getgrnam__doc__
,
"getgrnam($module, /, name)
\n
"
"--
\n
"
"
\n
"
"Return the group database entry for the given group name.
\n
"
"
\n
"
"If name is not valid, raise KeyError."
);
#define GRP_GETGRNAM_METHODDEF \
{"getgrnam", (PyCFunction)grp_getgrnam, METH_VARARGS|METH_KEYWORDS, grp_getgrnam__doc__},
static
PyObject
*
grp_getgrnam_impl
(
PyModuleDef
*
module
,
PyObject
*
name
);
static
PyObject
*
grp_getgrnam
(
PyModuleDef
*
module
,
PyObject
*
args
,
PyObject
*
kwargs
)
{
PyObject
*
return_value
=
NULL
;
static
char
*
_keywords
[]
=
{
"name"
,
NULL
};
PyObject
*
name
;
if
(
!
PyArg_ParseTupleAndKeywords
(
args
,
kwargs
,
"U:getgrnam"
,
_keywords
,
&
name
))
goto
exit
;
return_value
=
grp_getgrnam_impl
(
module
,
name
);
exit:
return
return_value
;
}
PyDoc_STRVAR
(
grp_getgrall__doc__
,
"getgrall($module, /)
\n
"
"--
\n
"
"
\n
"
"Return a list of all available group entries, in arbitrary order.
\n
"
"
\n
"
"An entry whose name starts with
\'
+
\'
or
\'
-
\'
represents an instruction
\n
"
"to use YP/NIS and may not be accessible via getgrnam or getgrgid."
);
#define GRP_GETGRALL_METHODDEF \
{"getgrall", (PyCFunction)grp_getgrall, METH_NOARGS, grp_getgrall__doc__},
static
PyObject
*
grp_getgrall_impl
(
PyModuleDef
*
module
);
static
PyObject
*
grp_getgrall
(
PyModuleDef
*
module
,
PyObject
*
Py_UNUSED
(
ignored
))
{
return
grp_getgrall_impl
(
module
);
}
/*[clinic end generated code: output=4709a6ba40bb8df9 input=a9049054013a1b77]*/
Modules/grpmodule.c
View file @
8fb7bb2f
...
@@ -6,6 +6,13 @@
...
@@ -6,6 +6,13 @@
#include <grp.h>
#include <grp.h>
#include "clinic/grpmodule.c.h"
/*[clinic input]
output preset file
module grp
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=68180a9a9efb8506]*/
static
PyStructSequence_Field
struct_group_type_fields
[]
=
{
static
PyStructSequence_Field
struct_group_type_fields
[]
=
{
{
"gr_name"
,
"group name"
},
{
"gr_name"
,
"group name"
},
{
"gr_passwd"
,
"password"
},
{
"gr_passwd"
,
"password"
},
...
@@ -76,14 +83,25 @@ mkgrent(struct group *p)
...
@@ -76,14 +83,25 @@ mkgrent(struct group *p)
return
v
;
return
v
;
}
}
/*[clinic input]
grp.getgrgid
id: object
Return the group database entry for the given numeric group ID.
If id is not valid, raise KeyError.
[clinic start generated code]*/
static
PyObject
*
static
PyObject
*
grp_getgrgid
(
PyObject
*
self
,
PyObject
*
pyo_id
)
grp_getgrgid_impl
(
PyModuleDef
*
module
,
PyObject
*
id
)
/*[clinic end generated code: output=8a11f5fdeb8c78a0 input=15fa0e2ccf5cda25]*/
{
{
PyObject
*
py_int_id
;
PyObject
*
py_int_id
;
gid_t
gid
;
gid_t
gid
;
struct
group
*
p
;
struct
group
*
p
;
py_int_id
=
PyNumber_Long
(
pyo_
id
);
py_int_id
=
PyNumber_Long
(
id
);
if
(
!
py_int_id
)
if
(
!
py_int_id
)
return
NULL
;
return
NULL
;
if
(
!
_Py_Gid_Converter
(
py_int_id
,
&
gid
))
{
if
(
!
_Py_Gid_Converter
(
py_int_id
,
&
gid
))
{
...
@@ -103,22 +121,31 @@ grp_getgrgid(PyObject *self, PyObject *pyo_id)
...
@@ -103,22 +121,31 @@ grp_getgrgid(PyObject *self, PyObject *pyo_id)
return
mkgrent
(
p
);
return
mkgrent
(
p
);
}
}
/*[clinic input]
grp.getgrnam
name: unicode
Return the group database entry for the given group name.
If name is not valid, raise KeyError.
[clinic start generated code]*/
static
PyObject
*
static
PyObject
*
grp_getgrnam
(
PyObject
*
self
,
PyObject
*
args
)
grp_getgrnam_impl
(
PyModuleDef
*
module
,
PyObject
*
name
)
/*[clinic end generated code: output=cd47511f4854da8e input=08ded29affa3c863]*/
{
{
char
*
name
;
char
*
name
_chars
;
struct
group
*
p
;
struct
group
*
p
;
PyObject
*
arg
,
*
bytes
,
*
retval
=
NULL
;
PyObject
*
bytes
,
*
retval
=
NULL
;
if
(
!
PyArg_ParseTuple
(
args
,
"U:getgrnam"
,
&
arg
))
if
((
bytes
=
PyUnicode_EncodeFSDefault
(
name
))
==
NULL
)
return
NULL
;
if
((
bytes
=
PyUnicode_EncodeFSDefault
(
arg
))
==
NULL
)
return
NULL
;
return
NULL
;
if
(
PyBytes_AsStringAndSize
(
bytes
,
&
name
,
NULL
)
==
-
1
)
if
(
PyBytes_AsStringAndSize
(
bytes
,
&
name
_chars
,
NULL
)
==
-
1
)
goto
out
;
goto
out
;
if
((
p
=
getgrnam
(
name
))
==
NULL
)
{
if
((
p
=
getgrnam
(
name
_chars
))
==
NULL
)
{
PyErr_Format
(
PyExc_KeyError
,
"getgrnam(): name not found: %s"
,
name
);
PyErr_Format
(
PyExc_KeyError
,
"getgrnam(): name not found: %s"
,
name
_chars
);
goto
out
;
goto
out
;
}
}
retval
=
mkgrent
(
p
);
retval
=
mkgrent
(
p
);
...
@@ -127,8 +154,18 @@ out:
...
@@ -127,8 +154,18 @@ out:
return
retval
;
return
retval
;
}
}
/*[clinic input]
grp.getgrall
Return a list of all available group entries, in arbitrary order.
An entry whose name starts with '+' or '-' represents an instruction
to use YP/NIS and may not be accessible via getgrnam or getgrgid.
[clinic start generated code]*/
static
PyObject
*
static
PyObject
*
grp_getgrall
(
PyObject
*
self
,
PyObject
*
ignore
)
grp_getgrall_impl
(
PyModuleDef
*
module
)
/*[clinic end generated code: output=add9037a20c202de input=d7df76c825c367df]*/
{
{
PyObject
*
d
;
PyObject
*
d
;
struct
group
*
p
;
struct
group
*
p
;
...
@@ -151,20 +188,10 @@ grp_getgrall(PyObject *self, PyObject *ignore)
...
@@ -151,20 +188,10 @@ grp_getgrall(PyObject *self, PyObject *ignore)
}
}
static
PyMethodDef
grp_methods
[]
=
{
static
PyMethodDef
grp_methods
[]
=
{
{
"getgrgid"
,
grp_getgrgid
,
METH_O
,
GRP_GETGRGID_METHODDEF
"getgrgid(id) -> tuple
\n
\
GRP_GETGRNAM_METHODDEF
Return the group database entry for the given numeric group ID. If
\n
\
GRP_GETGRALL_METHODDEF
id is not valid, raise KeyError."
},
{
NULL
,
NULL
}
{
"getgrnam"
,
grp_getgrnam
,
METH_VARARGS
,
"getgrnam(name) -> tuple
\n
\
Return the group database entry for the given group name. If
\n
\
name is not valid, raise KeyError."
},
{
"getgrall"
,
grp_getgrall
,
METH_NOARGS
,
"getgrall() -> list of tuples
\n
\
Return a list of all available group entries, in arbitrary order.
\n
\
An entry whose name starts with '+' or '-' represents an instruction
\n
\
to use YP/NIS and may not be accessible via getgrnam or getgrgid."
},
{
NULL
,
NULL
}
/* sentinel */
};
};
PyDoc_STRVAR
(
grp__doc__
,
PyDoc_STRVAR
(
grp__doc__
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment