From: <pj...@us...> - 2008-07-17 04:59:55
|
Revision: 4963 http://jython.svn.sourceforge.net/jython/?rev=4963&view=rev Author: pjenvey Date: 2008-07-17 04:59:53 +0000 (Thu, 17 Jul 2008) Log Message: ----------- o fix PythonPOSIXHandler getEnv/getCurrentWorkingDirectory return signatures o fix posixpath.__all__ o only enable os.symlink/readlink and posixpath friends if the posix factory appears native. pure java support for symlinks is still sketchy -- in particular with dead links -- switching these on enables tests in test_glob, test_posixpath, test_tarfile that utilize dead links and are doomed to failure o allow partial filling of stat results from jna-posix, padding the rest with 0s Modified Paths: -------------- branches/asm/Lib/os.py branches/asm/Lib/posixpath.py Modified: branches/asm/Lib/os.py =================================================================== --- branches/asm/Lib/os.py 2008-07-17 03:29:17 UTC (rev 4962) +++ branches/asm/Lib/os.py 2008-07-17 04:59:53 UTC (rev 4963) @@ -93,17 +93,8 @@ # should *NOT* use it _name = get_os_type() -if _name in ('nt', 'ce'): - import ntpath as path -else: - import posixpath as path +from org.python.posix import JavaPOSIX, POSIXHandler, POSIXFactory -sys.modules['os.path'] = _path = path -from os.path import curdir, pardir, sep, pathsep, defpath, extsep, altsep, devnull -linesep = java.lang.System.getProperty('line.separator') - -from org.python.posix import POSIXHandler, POSIXFactory - class PythonPOSIXHandler(POSIXHandler): def error(self, error, msg): err = getattr(errno, error.name(), None) @@ -117,9 +108,9 @@ def isVerbose(self): return False def getCurrentWorkingDirectory(self): - return getcwd() + return File(getcwd()) def getEnv(self): - return environ + return ['%s=%s' % (key, val) for key, val in environ.iteritems()] def getInputStream(self): return getattr(java.lang.System, 'in') # XXX handle resetting def getOutputStream(self): @@ -130,7 +121,17 @@ return java.lang.System.err # XXX handle resetting _posix = POSIXFactory.getPOSIX(PythonPOSIXHandler(), True) +_native_posix = not isinstance(_posix, JavaPOSIX) +if _name in ('nt', 'ce'): + import ntpath as path +else: + import posixpath as path + +sys.modules['os.path'] = _path = path +from os.path import curdir, pardir, sep, pathsep, defpath, extsep, altsep, devnull +linesep = java.lang.System.getProperty('line.separator') + # open for reading only O_RDONLY = 0x0 # open for writing only @@ -188,6 +189,17 @@ for (name, index) in stat_result._stat_members: self.__dict__[name] = results[index] + @classmethod + def from_jnastat(cls, s): + results = [] + for meth in (s.mode, s.ino, s.dev, s.nlink, s.uid, s.gid, s.st_size, + s.atime, s.mtime, s.ctime): + try: + results.append(meth()) + except NotImplementedError: + results.append(0) + return cls(results) + def __getitem__(self, i): if i < 0 or i > 9: raise IndexError(i) @@ -421,10 +433,7 @@ """ abs_path = sys.getPath(path) try: - s = _posix.stat(abs_path) - return stat_result((s.mode(), s.ino(), s.dev(), s.nlink(), - s.uid(), s.gid(), s.st_size(), - s.atime(), s.mtime(), s.ctime())) + return stat_result.from_jnastat(_posix.stat(abs_path)) except NotImplementedError: pass except: @@ -452,10 +461,7 @@ """ abs_path = sys.getPath(path) try: - s = _posix.lstat(abs_path) - return stat_result((s.mode(), s.ino(), s.dev(), s.nlink(), - s.uid(), s.gid(), s.st_size(), - s.atime(), s.mtime(), s.ctime())) + return stat_result.from_jnastat(_posix.lstat(abs_path)) except NotImplementedError: pass except: @@ -639,7 +645,7 @@ except: raise OSError(errno.EBADF, errno.strerror(errno.EBADF)) -if _name == 'posix': +if _name == 'posix' and _native_posix: def symlink(src, dst): """symlink(src, dst) Modified: branches/asm/Lib/posixpath.py =================================================================== --- branches/asm/Lib/posixpath.py 2008-07-17 03:29:17 UTC (rev 4962) +++ branches/asm/Lib/posixpath.py 2008-07-17 04:59:53 UTC (rev 4963) @@ -33,9 +33,6 @@ altsep = None devnull = '/dev/null' -# XXX: There should be a global way of disabling native JNA posix -native_posix = True - # Normalize the case of a pathname. Trivial in Posix, string.lower on Mac. # On MS-DOS this may also turn slashes into backslashes; however, other # normalizations (such as optimizing '../' away) are not allowed @@ -218,7 +215,7 @@ # Are two filenames really pointing to the same file? -if not native_posix: +if not os._native_posix: def samefile(f1, f2): """Test whether two pathnames reference the same actual file""" canon1 = java.io.File(_ensure_str(f1)).getCanonicalPath() @@ -243,8 +240,10 @@ s2 = os.fstat(fp2) return samestat(s1, s2) + __all__append("sameopenfile") -if native_posix: + +if os._native_posix: # Are two stat buffers (obtained from stat, fstat or lstat) # describing the same file? @@ -274,7 +273,7 @@ return True # path/.. is the same i-node as path return False - __all__.extend(["sameopenfile", "samestat", "ismount"]) + __all__.extend(["samestat", "ismount"]) # Directory tree walk. @@ -442,7 +441,7 @@ return abspath(filename) -if not native_posix: +if not os._native_posix: def _resolve_link(path): """Internal helper function. Takes a path and follows symlinks until we either arrive at something that isn't a symlink, or This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |