Message1407

Author hsk0
Recipients
Date 2007-02-18.11:40:06
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
Problem is javaos.py always unconditionally loads javapath
Line 31: import javapath as path
This despite the comment at the top
Line 6: - os.path is one of the modules posixpath, ntpath, macpath, or dospath
To 'fix' aka to make os.path act like the native underlying OS-isms, rather than 'java-isms', replace the unconditional import statement with a conditional one:

...
import java
from java.io import File
from UserDict import UserDict

# Load the right flavor of os.path
_osname = None
_jythonospath = java.lang.System.getProperty('jython.os.path')
if _jythonospath:
    _jythonospath =  _jythonospath.lower()
    if _jythonospath in ['java', 'dos', 'mac', 'nt', 'posix']:
        _osname = _jythonospath
if _osname == None:
    _osname = java.lang.System.getProperty('os.name').lower()
if _osname == 'nt' or  _osname.startswith('windows'):
    import ntpath as path
elif _osname.startswith('mac') and not _osname.endswith('x'):
    import macpath as path
elif _osname == 'dos':
    import dospath as path
elif (_osname == 'posix') or ((File.pathSeparator == ':') and ('vms' not in _osname) and (not _osname.startswith('mac') or _osname.endswith('x'))):
    import posixpath as path
else:
    import javapath as path

class stat_result:
...


This auto-detects the OS unless explicitly overridden. The hunt sequence:
IF System.property jython.os.path = 'java', 'dos', 'mac', 'nt' or 'posix'
    use it
ELSE
    osname = java.lang.System.getProperty('os.name').lower()
    IF osname startswith 'windows'
        import ntpath as path
    ELSEIF osname startswith 'mac'
        import macpath as path
    ELSEIF osname startswith 'dos'
        import dospath as path
    ELSEIF pathsep == ':' and not VMS and (osname != Mac(classic) OR osname endswith 'x')
        import posixpath as path
    ELSE
        import javapath as path
    ENDIF
ENDIF

That autodetect for Unix looks funky, but it's right.
If the path separator is not ":", it's not Unix
If it's VMS, it's not Unix
If it's not MacOS OR it ends with 'X', it's Unix

That last part's a head bender at first.
MacOS falls thru.
MacOSX gets trapped as Unix
AIX, HP-UX, Linux and Irix are trapped as Unix
Solaris and SunOS are trapped as Unix

That last one because Solaris is not Mac; If you've got a ":" path separator, you're probably Unix, MacOS and VMS being the (known) exceptions

Voila.

Run with -v and you can see what gets loaded is what you'd expect.


And for those wondering if ntpath or posixpath is the right answer instead of javapath, yes, it is. It has to be. Java doesn't hide all underlying file system details; new File("C:\\foo.bar") is what's required to work on Windows and so forth. Java only generalized the API function calls, not the 'data' like filenames or pathing and so forth, so javapath is interesting but, ultimately, not the right answer consistent with other JVM behavior (at least, not for nt, mac, posix and dos).
History
Date User Action Args
2008-02-20 17:17:40adminlinkissue1648449 messages
2008-02-20 17:17:40admincreate