From: <pj...@us...> - 2010-04-11 03:18:43
|
Revision: 7016 http://jython.svn.sourceforge.net/jython/?rev=7016&view=rev Author: pjenvey Date: 2010-04-11 03:18:37 +0000 (Sun, 11 Apr 2010) Log Message: ----------- have os.listdir return unicode when requested fixes #1520 Modified Paths: -------------- trunk/jython/NEWS trunk/jython/src/org/python/modules/posix/PosixModule.java Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2010-04-10 20:50:46 UTC (rev 7015) +++ trunk/jython/NEWS 2010-04-11 03:18:37 UTC (rev 7016) @@ -17,7 +17,7 @@ - [ 1396 ] Assigning os module funcs as class attributes incompatible with CPython - [ 1504 ] Inheriting twice from the same Java interface causes MRO problems - [ 1511 ] PySet doesn't support Java serialization - - [ 1426 ] JSR 223 Bindings changes not taking effect and leaking between threads; unnecessary synchronization + - [ 1426 ] JSR 223 Bindings changes not taking effect and leaking between threads; unnecessary synchronization - [ 1548 ] Parentheses in CLASSPATH cause errors in jython.bat - [ 1576 ] files opened in 'a+' mode not readable - [ 1563 ] unicode() for Java objects working differently in 2.2 and 2.5 @@ -27,6 +27,7 @@ - [ 1534 ] new style object __dict__[name] ignored - [ 1479 ] xml parser file lock - [ 1582 ] com.ziclix.python.sql.PyConnection leaks memory + - [ 1520 ] os.listdir doesn't return unicode when requested - Fix runtime issues during exitfuncs triggered via SystemRestart (such as during Django or Pylons development mode reloading) - Fix pickling of collections.defaultdict objects Modified: trunk/jython/src/org/python/modules/posix/PosixModule.java =================================================================== --- trunk/jython/src/org/python/modules/posix/PosixModule.java 2010-04-10 20:50:46 UTC (rev 7015) +++ trunk/jython/src/org/python/modules/posix/PosixModule.java 2010-04-11 03:18:37 UTC (rev 7016) @@ -474,12 +474,12 @@ "path: path of directory to list\n\n" + "The list is in arbitrary order. It does not include the special\n" + "entries '.' and '..' even if they are present in the directory."); - public static PyList listdir(String path) { - ensurePath(path); + public static PyList listdir(PyObject pathObj) { + ensurePath(pathObj); + String path = pathObj.asString(); PyList list = new PyList(); File file = new RelativeFile(path); String[] names = file.list(); - if (names == null) { // Can't read the path for some reason. stat will throw an error if it can't // read it either @@ -493,8 +493,10 @@ } throw Py.OSError("listdir(): an unknown error occured: " + path); } + + PyString string = (PyString) pathObj; for (String name : names) { - list.append(new PyString(name)); + list.append(string.createInstance(name)); } return list; } @@ -894,6 +896,13 @@ return new RelativeFile(path).getPath(); } + private static void ensurePath(PyObject path) { + if (!(path instanceof PyString)) { + throw Py.TypeError(String.format("coercing to Unicode: need string, %s type found", + path.getType().fastGetName())); + } + } + private static void ensurePath(String path) { if (path == null) { throw Py.TypeError("coercing to Unicode: need string or buffer, NoneType found"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |