summaryrefslogtreecommitdiffstats
path: root/Modules/nismodule.c
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2010-08-19 09:11:51 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2010-08-19 09:11:51 (GMT)
commit5ea823cf55911c03b196f1bf45de4c9a2474a903 (patch)
tree47ef2b4895786b51e0f57edfb9eebcf1fa64e028 /Modules/nismodule.c
parentf241afaeadabb5837ce8ccc94c85545f584ce056 (diff)
downloadcpython-5ea823cf55911c03b196f1bf45de4c9a2474a903.zip
cpython-5ea823cf55911c03b196f1bf45de4c9a2474a903.tar.gz
cpython-5ea823cf55911c03b196f1bf45de4c9a2474a903.tar.bz2
Decode NIS data to fs encoding, using the surrogate error handler.
Diffstat (limited to 'Modules/nismodule.c')
-rw-r--r--Modules/nismodule.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/Modules/nismodule.c b/Modules/nismodule.c
index d75af5d..a81ca8c 100644
--- a/Modules/nismodule.c
+++ b/Modules/nismodule.c
@@ -117,8 +117,8 @@ nis_foreach (int instatus, char *inkey, int inkeylen, char *inval,
if (invallen > 0 && inval[invallen-1] == '\0')
invallen--;
}
- key = PyUnicode_FromStringAndSize(inkey, inkeylen);
- val = PyUnicode_FromStringAndSize(inval, invallen);
+ key = PyUnicode_DecodeFSDefaultAndSize(inkey, inkeylen);
+ val = PyUnicode_DecodeFSDefaultAndSize(inval, invallen);
if (key == NULL || val == NULL) {
/* XXX error -- don't know how to handle */
PyErr_Clear();
@@ -159,30 +159,40 @@ nis_match (PyObject *self, PyObject *args, PyObject *kwdict)
{
char *match;
char *domain = NULL;
- int keylen, len;
+ Py_ssize_t keylen;
+ int len;
char *key, *map;
int err;
- PyObject *res;
+ PyObject *ukey, *bkey, *res;
int fix;
static char *kwlist[] = {"key", "map", "domain", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwdict,
- "s#s|s:match", kwlist,
- &key, &keylen, &map, &domain))
+ "Us|s:match", kwlist,
+ &ukey, &map, &domain))
return NULL;
- if (!domain && ((err = yp_get_default_domain(&domain)) != 0))
+ if ((bkey = PyUnicode_EncodeFSDefault(ukey)) == NULL)
+ return NULL;
+ if (PyBytes_AsStringAndSize(bkey, &key, &keylen) == -1) {
+ Py_DECREF(bkey);
+ return NULL;
+ }
+ if (!domain && ((err = yp_get_default_domain(&domain)) != 0)) {
+ Py_DECREF(bkey);
return nis_error(err);
+ }
map = nis_mapname (map, &fix);
if (fix)
keylen++;
Py_BEGIN_ALLOW_THREADS
err = yp_match (domain, map, key, keylen, &match, &len);
Py_END_ALLOW_THREADS
+ Py_DECREF(bkey);
if (fix)
len--;
if (err != 0)
return nis_error(err);
- res = PyUnicode_FromStringAndSize (match, len);
+ res = PyUnicode_DecodeFSDefaultAndSize(match, len);
free (match);
return res;
}