[Python-checkins] bpo-34604: Use %R because of invisible characters or trailing whitespaces. (GH-9165). (GH-10947)

Serhiy Storchaka webhook-mailer at python.org
Wed Dec 5 16:23:09 EST 2018


https://github.com/python/cpython/commit/ac8b47c8b4edd59aaee857717d434df52ec49e6c
commit: ac8b47c8b4edd59aaee857717d434df52ec49e6c
branch: 3.7
author: Serhiy Storchaka <storchaka at gmail.com>
committer: GitHub <noreply at github.com>
date: 2018-12-05T23:23:06+02:00
summary:

bpo-34604: Use %R because of invisible characters or trailing whitespaces. (GH-9165). (GH-10947)

(cherry picked from commit 34c7f0c04e2b4e715b2c3df1875af8939fbe7d0b)

Co-authored-by: William Grzybowski <wg at FreeBSD.org>

files:
A Misc/NEWS.d/next/Library/2018-09-07-10-16-34.bpo-34604.xL7-kG.rst
M Modules/grpmodule.c
M Modules/pwdmodule.c

diff --git a/Misc/NEWS.d/next/Library/2018-09-07-10-16-34.bpo-34604.xL7-kG.rst b/Misc/NEWS.d/next/Library/2018-09-07-10-16-34.bpo-34604.xL7-kG.rst
new file mode 100644
index 000000000000..958b74fd0da6
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2018-09-07-10-16-34.bpo-34604.xL7-kG.rst
@@ -0,0 +1,3 @@
+Fix possible mojibake in the error message of `pwd.getpwnam` and
+`grp.getgrnam` using string representation because of invisible characters
+or trailing whitespaces. Patch by William Grzybowski.
diff --git a/Modules/grpmodule.c b/Modules/grpmodule.c
index 43e45ef7aad5..8a724b6b438f 100644
--- a/Modules/grpmodule.c
+++ b/Modules/grpmodule.c
@@ -156,7 +156,7 @@ grp_getgrnam_impl(PyObject *module, PyObject *name)
         goto out;
 
     if ((p = getgrnam(name_chars)) == NULL) {
-        PyErr_Format(PyExc_KeyError, "getgrnam(): name not found: %S", name);
+        PyErr_Format(PyExc_KeyError, "getgrnam(): name not found: %R", name);
         goto out;
     }
     retval = mkgrent(p);
diff --git a/Modules/pwdmodule.c b/Modules/pwdmodule.c
index 21c2b546f6dd..810427a229b7 100644
--- a/Modules/pwdmodule.c
+++ b/Modules/pwdmodule.c
@@ -163,7 +163,7 @@ pwd_getpwnam_impl(PyObject *module, PyObject *arg)
         goto out;
     if ((p = getpwnam(name)) == NULL) {
         PyErr_Format(PyExc_KeyError,
-                     "getpwnam(): name not found: %S", arg);
+                     "getpwnam(): name not found: %R", arg);
         goto out;
     }
     retval = mkpwent(p);



More information about the Python-checkins mailing list