summaryrefslogtreecommitdiffstats
path: root/Modules/pwdmodule.c
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2009-05-29 15:23:17 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2009-05-29 15:23:17 (GMT)
commitb6a748b817205413ac75ccee5f9b4728b5ea3b2d (patch)
treeca69f2aea6235e35952a2d5cac84cde1237afb52 /Modules/pwdmodule.c
parentc15bdef8190241357970c9d65783c929860b933a (diff)
downloadcpython-b6a748b817205413ac75ccee5f9b4728b5ea3b2d.zip
cpython-b6a748b817205413ac75ccee5f9b4728b5ea3b2d.tar.gz
cpython-b6a748b817205413ac75ccee5f9b4728b5ea3b2d.tar.bz2
Issue #4859: Implement PEP 383 for pwd, spwd, and grp.
Diffstat (limited to 'Modules/pwdmodule.c')
-rw-r--r--Modules/pwdmodule.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/Modules/pwdmodule.c b/Modules/pwdmodule.c
index 061a0a5..5802818 100644
--- a/Modules/pwdmodule.c
+++ b/Modules/pwdmodule.c
@@ -49,8 +49,9 @@ static void
sets(PyObject *v, int i, const char* val)
{
if (val) {
- PyObject *o =
- PyUnicode_DecodeUnicodeEscape(val, strlen(val), "strict");
+ PyObject *o = PyUnicode_Decode(val, strlen(val),
+ Py_FileSystemDefaultEncoding,
+ "surrogateescape");
PyStructSequence_SET_ITEM(v, i, o);
}
else {
@@ -129,14 +130,25 @@ pwd_getpwnam(PyObject *self, PyObject *args)
{
char *name;
struct passwd *p;
- if (!PyArg_ParseTuple(args, "s:getpwnam", &name))
+ PyObject *arg, *bytes, *retval = NULL;
+
+ if (!PyArg_ParseTuple(args, "U:getpwnam", &arg))
+ return NULL;
+ if ((bytes = PyUnicode_AsEncodedString(arg,
+ Py_FileSystemDefaultEncoding,
+ "surrogateescape")) == NULL)
return NULL;
+ if (PyBytes_AsStringAndSize(bytes, &name, NULL) == -1)
+ goto out;
if ((p = getpwnam(name)) == NULL) {
PyErr_Format(PyExc_KeyError,
"getpwnam(): name not found: %s", name);
- return NULL;
+ goto out;
}
- return mkpwent(p);
+ retval = mkpwent(p);
+out:
+ Py_DECREF(bytes);
+ return retval;
}
#ifdef HAVE_GETPWENT