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
9cc4ed5c
Commit
9cc4ed5c
authored
Jan 18, 2016
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #26129: Deprecated accepting non-integers in grp.getgrgid().
parent
9def2843
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
5 deletions
+31
-5
Doc/library/grp.rst
Doc/library/grp.rst
+3
-0
Lib/test/test_grp.py
Lib/test/test_grp.py
+10
-0
Misc/NEWS
Misc/NEWS
+2
-0
Modules/grpmodule.c
Modules/grpmodule.c
+16
-5
No files found.
Doc/library/grp.rst
View file @
9cc4ed5c
...
...
@@ -42,6 +42,9 @@ It defines the following items:
Return the group database entry for the given numeric group ID. :exc:`KeyError`
is raised if the entry asked for cannot be found.
.. deprecated:: 3.6
Since Python 3.6 the support of non-integer arguments like floats or
strings in :func:`getgrgid` is deprecated.
.. function:: getgrnam(name)
...
...
Lib/test/test_grp.py
View file @
9cc4ed5c
...
...
@@ -92,5 +92,15 @@ class GroupDatabaseTestCase(unittest.TestCase):
self
.
assertRaises
(
KeyError
,
grp
.
getgrgid
,
fakegid
)
def
test_noninteger_gid
(
self
):
entries
=
grp
.
getgrall
()
if
not
entries
:
self
.
skipTest
(
'no groups'
)
# Choose an existent gid.
gid
=
entries
[
0
][
2
]
self
.
assertWarns
(
DeprecationWarning
,
grp
.
getgrgid
,
float
(
gid
))
self
.
assertWarns
(
DeprecationWarning
,
grp
.
getgrgid
,
str
(
gid
))
if
__name__
==
"__main__"
:
unittest
.
main
()
Misc/NEWS
View file @
9cc4ed5c
...
...
@@ -131,6 +131,8 @@ Core and Builtins
Library
-------
- Issue #26129: Deprecated accepting non-integers in grp.getgrgid().
- Issue #25850: Use cross-compilation by default for 64-bit Windows.
- Issue #25822: Add docstrings to the fields of urllib.parse results.
...
...
Modules/grpmodule.c
View file @
9cc4ed5c
...
...
@@ -100,14 +100,25 @@ grp_getgrgid_impl(PyModuleDef *module, PyObject *id)
gid_t
gid
;
struct
group
*
p
;
py_int_id
=
PyNumber_Long
(
id
);
if
(
!
py_int_id
)
if
(
!
_Py_Gid_Converter
(
id
,
&
gid
))
{
if
(
!
PyErr_ExceptionMatches
(
PyExc_TypeError
))
{
return
NULL
;
if
(
!
_Py_Gid_Converter
(
py_int_id
,
&
gid
))
{
}
PyErr_Clear
();
if
(
PyErr_WarnFormat
(
PyExc_DeprecationWarning
,
1
,
"group id must be int, not %.200"
,
id
->
ob_type
->
tp_name
)
<
0
)
{
return
NULL
;
}
py_int_id
=
PyNumber_Long
(
id
);
if
(
!
py_int_id
)
return
NULL
;
if
(
!
_Py_Gid_Converter
(
py_int_id
,
&
gid
))
{
Py_DECREF
(
py_int_id
);
return
NULL
;
}
Py_DECREF
(
py_int_id
);
return
NULL
;
}
Py_DECREF
(
py_int_id
);
if
((
p
=
getgrgid
(
gid
))
==
NULL
)
{
PyObject
*
gid_obj
=
_PyLong_FromGid
(
gid
);
...
...
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