diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2009-05-29 15:23:17 (GMT) |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2009-05-29 15:23:17 (GMT) |
commit | b6a748b817205413ac75ccee5f9b4728b5ea3b2d (patch) | |
tree | ca69f2aea6235e35952a2d5cac84cde1237afb52 /Modules/spwdmodule.c | |
parent | c15bdef8190241357970c9d65783c929860b933a (diff) | |
download | cpython-b6a748b817205413ac75ccee5f9b4728b5ea3b2d.zip cpython-b6a748b817205413ac75ccee5f9b4728b5ea3b2d.tar.gz cpython-b6a748b817205413ac75ccee5f9b4728b5ea3b2d.tar.bz2 |
Issue #4859: Implement PEP 383 for pwd, spwd, and grp.
Diffstat (limited to 'Modules/spwdmodule.c')
-rw-r--r-- | Modules/spwdmodule.c | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/Modules/spwdmodule.c b/Modules/spwdmodule.c index a6b9d93..230b57c 100644 --- a/Modules/spwdmodule.c +++ b/Modules/spwdmodule.c @@ -59,9 +59,12 @@ static PyTypeObject StructSpwdType; static void sets(PyObject *v, int i, const char* val) { - if (val) - PyStructSequence_SET_ITEM(v, i, PyUnicode_FromString(val)); - else { + if (val) { + PyObject *o = PyUnicode_Decode(val, strlen(val), + Py_FileSystemDefaultEncoding, + "surrogateescape"); + PyStructSequence_SET_ITEM(v, i, o); + } else { PyStructSequence_SET_ITEM(v, i, Py_None); Py_INCREF(Py_None); } @@ -113,13 +116,24 @@ static PyObject* spwd_getspnam(PyObject *self, PyObject *args) { char *name; struct spwd *p; - if (!PyArg_ParseTuple(args, "s:getspnam", &name)) + PyObject *arg, *bytes, *retval = NULL; + + if (!PyArg_ParseTuple(args, "U:getspnam", &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 = getspnam(name)) == NULL) { PyErr_SetString(PyExc_KeyError, "getspnam(): name not found"); - return NULL; + goto out; } - return mkspent(p); + retval = mkspent(p); +out: + Py_DECREF(bytes); + return retval; } #endif /* HAVE_GETSPNAM */ |