[Python-checkins] r81914 - python/branches/py3k/Modules/_localemodule.c

victor.stinner python-checkins at python.org
Sat Jun 12 00:09:52 CEST 2010


Author: victor.stinner
Date: Sat Jun 12 00:09:51 2010
New Revision: 81914

Log:
locale.bindtextdomain(): use PyUnicode_FSConverter() to parse the filename


Modified:
   python/branches/py3k/Modules/_localemodule.c

Modified: python/branches/py3k/Modules/_localemodule.c
==============================================================================
--- python/branches/py3k/Modules/_localemodule.c	(original)
+++ python/branches/py3k/Modules/_localemodule.c	Sat Jun 12 00:09:51 2010
@@ -572,19 +572,31 @@
 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


More information about the Python-checkins mailing list