diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2010-06-11 22:09:51 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2010-06-11 22:09:51 (GMT) |
commit | 9e19ca42d31ba9ff3bc3dc901d832877d3815adb (patch) | |
tree | c4bebc4e77740883b8e96e2d1968da35f5af3eab /Modules | |
parent | c629d51ea9655964843df31df46112bd78bfcabf (diff) | |
download | cpython-9e19ca42d31ba9ff3bc3dc901d832877d3815adb.zip cpython-9e19ca42d31ba9ff3bc3dc901d832877d3815adb.tar.gz cpython-9e19ca42d31ba9ff3bc3dc901d832877d3815adb.tar.bz2 |
locale.bindtextdomain(): use PyUnicode_FSConverter() to parse the filename
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_localemodule.c | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/Modules/_localemodule.c b/Modules/_localemodule.c index 84e393e..88f6add 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 |