From 9e19ca42d31ba9ff3bc3dc901d832877d3815adb Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 11 Jun 2010 22:09:51 +0000 Subject: [PATCH] locale.bindtextdomain(): use PyUnicode_FSConverter() to parse the filename --- Modules/_localemodule.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/Modules/_localemodule.c b/Modules/_localemodule.c index 84e393e1737..88f6addd44c 100644 --- a/Modules/_localemodule.c +++ b/Modules/_localemodule.c @@ -572,19 +572,31 @@ PyDoc_STRVAR(bindtextdomain__doc__, static PyObject* PyIntl_bindtextdomain(PyObject* self,PyObject*args) { - char *domain, *dirname; - if (!PyArg_ParseTuple(args, "sz", &domain, &dirname)) + char *domain, *dirname, *current_dirname; + PyObject *dirname_obj, *dirname_bytes = NULL, *result; + if (!PyArg_ParseTuple(args, "sO", &domain, &dirname_obj)) return 0; if (!strlen(domain)) { PyErr_SetString(Error, "domain must be a non-empty string"); return 0; } - dirname = bindtextdomain(domain, dirname); - if (!dirname) { + if (dirname_obj != Py_None) { + if (!PyUnicode_FSConverter(dirname_obj, &dirname_bytes)) + return NULL; + dirname = PyBytes_AsString(dirname_bytes); + } else { + dirname_bytes = NULL; + dirname = NULL; + } + current_dirname = bindtextdomain(domain, dirname); + if (current_dirname == NULL) { + Py_XDECREF(dirname_bytes); PyErr_SetFromErrno(PyExc_OSError); return NULL; } - return str2uni(dirname); + result = str2uni(current_dirname); + Py_XDECREF(dirname_bytes); + return result; } #ifdef HAVE_BIND_TEXTDOMAIN_CODESET