[Python-checkins] python/dist/src/Modules posixmodule.c,2.286,2.287

jvr@users.sourceforge.net jvr@users.sourceforge.net
Tue, 25 Feb 2003 13:42:19 -0800


Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1:/tmp/cvs-serv16063/Modules

Modified Files:
	posixmodule.c 
Log Message:
Patch #683592: unicode support for os.listdir()
os.listdir() may now return unicode strings on platforms that set
Py_FileSystemDefaultEncoding.


Index: posixmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/posixmodule.c,v
retrieving revision 2.286
retrieving revision 2.287
diff -C2 -d -r2.286 -r2.287
*** posixmodule.c	19 Feb 2003 04:08:27 -0000	2.286
--- posixmodule.c	25 Feb 2003 21:42:15 -0000	2.287
***************
*** 1796,1799 ****
--- 1796,1823 ----
  			break;
  		}
+ #ifdef Py_USING_UNICODE
+ 		if (Py_FileSystemDefaultEncoding != NULL) {
+ 			PyObject *w;
+ 
+ 			w = PyUnicode_FromEncodedObject(v,
+ 					Py_FileSystemDefaultEncoding, 
+ 					"strict");
+ 			Py_DECREF(v);
+ 			v = w;
+ 			if (v == NULL) {
+ 				Py_DECREF(d);
+ 				d = NULL;
+ 				break;
+ 			}
+ 			/* attempt to convert to ASCII */
+ 			w = PyUnicode_AsASCIIString(v);
+ 			if (w != NULL) {
+ 				Py_DECREF(v);
+ 				v = w;
+ 			}
+ 			else
+ 				PyErr_Clear();
+ 		}
+ #endif
  		if (PyList_Append(d, v) != 0) {
  			Py_DECREF(v);