From: Chris C. <Chr...@in...> - 2011-04-18 21:38:35
|
Dan Stromberg wrote: > os.open always returns bytes on CPython 2.x and CPython 3.x. open > returns bytes on 2.x and unicode on 3.x. Until I started > experimenting with Jython, it seemed that os.open was a way to get > some easy portability, since in my current project I'm mostly > interested in byte strings rather than text - a backup program > shouldn't break if a file doesn't fit its encoding assumptions. > > Also, use of os.open just seems a more direct route to use of os.fstat > as a security measure, to deter symlink races - though I've never > found a way of doing fstat in java short of JNI, JNA or similar, > despite some asking around; Java (and ergo Jython) does seem to be missing a few (what I would consider to be basic) unix/posix routines (cross platform, e.g. try using subprocess which needs fork under VMS). I don't have a solution, this is just a "me too!" comment :-( One slightly long winded option would be to use the new to 2.5.2 ctypes support to load libc - potentially easier than straight JNI. A lot of the boiler plat can be generated with http://code.google.com/p/ctypesgen/ - NOTE I've only use ctypes with Cpython, I've not sat down and use ctypes with Jython. > it seems like java is mostly used for user > applications, and not systems programming. Or maybe I'm overlooking > something - how do Java developers deal with the possibility of > symlink races? > > And os.open is a little faster for "transfer lots of blocks" sorts of > operations. But that's a pretty minor concern. > > FWIW, it appears that Jython 2.5.2's os.read and os.write are taking > extra steps to convert in an unexpected way... Would the > corresponding tiny patch be well received? > I'm not a Jython dev, we'd have to see what Jim's response is. From my perspective, the current behavior is a bug. There have been discussions at Pycon on a project for shared test suite and standard libraries between the different implementations (http://www.boredomandlaziness.org/2011/03/python-vm-summit-rough-notes.html). This seems like a great addition if that gets started. I'm not sure who to raise this with other than joining the python-dev mailing list. This is probably more than you were thinking of :-) RE your compatibility library for versions/implementations take a look at http://packages.python.org/six/ > Though I'm now realizing, that's not as significant as the lack of an > os.fstat for my current application. It seems like os.fstat is in > Jython's documentation, but upon import os, I don't see it. > > There appears to be a few mentions of JNA in the current code... Is > there a policy governing its use in Jython? > > BTW, do you know Jim Gramling and/or Karl Schendel? > I know-of Jim but I do not know him (I'm not sure if he is still at Microsoft). I know Karl, he's at Ingres :-) Small world! Chris |