From: Dan S. <drs...@gm...> - 2011-04-18 21:11:47
|
On Mon, Apr 18, 2011 at 12:19 PM, Chris Clark <Chr...@in...> wrote: > Dan Stromberg wrote: >> >> I believe Jython isn't conformant on this, >> but perhaps the standard (if such we can call it at this time) is >> flexible on what is returned? >> >> $ for i in /usr/local/*/bin/python /usr/local/pypy-1.4.1/bin/pypy >> /usr/local/pypy-trunk-2011-04-10/bin/pypy >> /usr/local/jython-2.5.2/bin/jython; do echo $i $($i -c 'import os; >> print(type(os.read(os.open("/etc/protocols", os.O_RDONLY), 1)))'); >> done >> /usr/local/cpython-2.5/bin/python <type 'str'> >> /usr/local/cpython-2.6/bin/python <type 'str'> >> /usr/local/cpython-2.7/bin/python <type 'str'> >> /usr/local/cpython-3.0/bin/python <class 'bytes'> >> /usr/local/cpython-3.1/bin/python <class 'bytes'> >> /usr/local/cpython-3.2/bin/python <class 'bytes'> >> /usr/local/pypy-1.4.1/bin/pypy <type 'str'> >> /usr/local/pypy-trunk-2011-04-10/bin/pypy <type 'str'> >> /usr/local/jython-2.5.2/bin/jython <type 'unicode'> > > My 2 cents, I suspect most focus has been on the builtin "open()" (like the > posix fopen function). I would suggest sticking with open() rather than > os.open() where the Jython 2.5.x results are like Cpython. As has already > been discussed using 'rb' is usually the ideal thing to do unless you > explicitly use the codec module. I may special-case my code to use os.open on CPython and PyPy, and open with 'b' on Jython. > Out of idle curiosity what are you using os.open for that open can't handle? 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; 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? 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? |