From: Pekka K. <re...@bu...> - 2010-09-26 21:23:52
|
New submission from Pekka Klärck <pe...@ik...>: Here's a simple example demonstrating the problem: import os for c in 254, 255, 256: f = unichr(c)+'.txt' open(f, 'w').close() print repr(f), 'exists', os.path.exists(f) os.stat(f) When the above code is run Linux, it reports all created files as existing and exits cleanly. On Windows you get this: D:\>jython os_stat_bug.py u'\xfe.txt' exists True u'\xff.txt' exists True u'\u0100.txt' exists False Traceback (most recent call last): File "os_stat_bug.py", line 6, in <module> os.stat(f) File "C:\jython2.5.1\Lib\os.py", line 478, in stat return stat_result.from_jnastat(_posix.stat(abs_path)) File "C:\jython2.5.1\Lib\os.py", line 103, in error raise OSError(err, strerror(err), asPyString(msg)) OSError: [Errno 2] No such file or directory: 'D:\\\u0100.txt' As the failing os.path.exists in the above code already illustrated, a bug in os.stat is pretty annoying because so many other methods depend on it. I originally noticed this problem when shutil.rmtree didn't work. The error occurs when the stat method calls _posix.stat. This _posix is returned by a factory and in my case it was WindowsPOSIX. I was able to make our projects acceptance tests pass with this workarounds: if sys.platform.startswith('java') and os.sep == '\\': os._posix = os.JavaPOSIX(os.PythonPOSIXHandler()) os._native_posix = False Could someone who knows Jython internals better comment is this workaround valid? Hopefully this is can be fixed in 2.5.2. ---------- messages: 6097 nosy: pekka.klarck severity: normal status: open title: os.stat fails on Windows if path contains chars with ordinal over 255 _______________________________________ Jython tracker <re...@bu...> <http://bugs.jython.org/issue1658> _______________________________________ |