From: <pj...@us...> - 2008-07-17 03:21:37
|
Revision: 4961 http://jython.svn.sourceforge.net/jython/?rev=4961&view=rev Author: pjenvey Date: 2008-07-17 03:21:35 +0000 (Thu, 17 Jul 2008) Log Message: ----------- fix the symlink related tests by adding readlink, using _posix.lstat and utilizing _posix symlink stuff in posixpath. also utilize real stat results in posixpath, and re-enable ismount in ntpath since we can support it in posixpath Modified Paths: -------------- branches/asm/Lib/ntpath.py branches/asm/Lib/os.py branches/asm/Lib/posixpath.py Modified: branches/asm/Lib/ntpath.py =================================================================== --- branches/asm/Lib/ntpath.py 2008-07-17 01:43:59 UTC (rev 4960) +++ branches/asm/Lib/ntpath.py 2008-07-17 03:21:35 UTC (rev 4961) @@ -13,7 +13,7 @@ __all__ = ["normcase","isabs","join","splitdrive","split","splitext", "basename","dirname","commonprefix","getsize","getmtime", "getatime","getctime", "islink","exists","lexists","isdir","isfile", - "walk","expanduser","expandvars","normpath","abspath", + "ismount","walk","expanduser","expandvars","normpath","abspath", "splitunc","curdir","pardir","sep","pathsep","defpath","altsep", "extsep","devnull","realpath","supports_unicode_filenames"] @@ -287,21 +287,18 @@ return stat.S_ISREG(st.st_mode) -if os.name != 'java': - # Is a path a mount point? Either a root (with or without drive letter) - # or an UNC path with at most a / or \ after the mount point. +# Is a path a mount point? Either a root (with or without drive letter) +# or an UNC path with at most a / or \ after the mount point. - def ismount(path): - """Test whether a path is a mount point (defined as root of drive)""" - unc, rest = splitunc(path) - if unc: - return rest in ("", "/", "\\") - p = splitdrive(path)[1] - return len(p) == 1 and p[0] in '/\\' +def ismount(path): + """Test whether a path is a mount point (defined as root of drive)""" + unc, rest = splitunc(path) + if unc: + return rest in ("", "/", "\\") + p = splitdrive(path)[1] + return len(p) == 1 and p[0] in '/\\' - __all__.append("ismount") - # Directory tree walk. # For each directory under top (including top itself, but excluding # '.' and '..'), func(arg, dirname, filenames) is called, where Modified: branches/asm/Lib/os.py =================================================================== --- branches/asm/Lib/os.py 2008-07-17 01:43:59 UTC (rev 4960) +++ branches/asm/Lib/os.py 2008-07-17 03:21:35 UTC (rev 4961) @@ -283,7 +283,6 @@ just the rightmost) will be created if it does not exist. The optional parameter is currently ignored. """ - sys_path = sys.getPath(path) if File(sys_path).mkdirs(): return @@ -451,6 +450,16 @@ Like stat(path), but do not follow symbolic links. """ + 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())) + except NotImplementedError: + pass + except: + raise f = File(sys.getPath(path)) abs_parent = f.getAbsoluteFile().getParentFile() if not abs_parent: @@ -636,8 +645,16 @@ Create a symbolic link pointing to src named dst. """ - return _posix.symlink(src, dst) + _posix.symlink(src, sys.getPath(dst)) + def readlink(path): + """readlink(path) -> path + + Return a string representing the path to which the symbolic link + points. + """ + return _posix.readlink(sys.getPath(path)) + # Provide lazy popen*, and system objects # Do these lazily, as most jython programs don't need them, # and they are very expensive to initialize Modified: branches/asm/Lib/posixpath.py =================================================================== --- branches/asm/Lib/posixpath.py 2008-07-17 01:43:59 UTC (rev 4960) +++ branches/asm/Lib/posixpath.py 2008-07-17 03:21:35 UTC (rev 4961) @@ -33,6 +33,9 @@ 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 @@ -215,7 +218,7 @@ # Are two filenames really pointing to the same file? -if os.name == 'java': +if not native_posix: def samefile(f1, f2): """Test whether two pathnames reference the same actual file""" canon1 = java.io.File(_ensure_str(f1)).getCanonicalPath() @@ -241,6 +244,7 @@ return samestat(s1, s2) +if native_posix: # Are two stat buffers (obtained from stat, fstat or lstat) # describing the same file? @@ -438,7 +442,7 @@ return abspath(filename) -if os.name == 'java': +if not 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. |
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. |
From: <pj...@us...> - 2008-07-28 04:56:05
|
Revision: 5006 http://jython.svn.sourceforge.net/jython/?rev=5006&view=rev Author: pjenvey Date: 2008-07-28 04:56:03 +0000 (Mon, 28 Jul 2008) Log Message: ----------- o add os.link (fixes test_shutil) o fix test_re's test output -- it shouldn't have any now Modified Paths: -------------- branches/asm/Lib/os.py Removed Paths: ------------- branches/asm/Lib/test/output/test_re Modified: branches/asm/Lib/os.py =================================================================== --- branches/asm/Lib/os.py 2008-07-28 02:41:38 UTC (rev 5005) +++ branches/asm/Lib/os.py 2008-07-28 04:56:03 UTC (rev 5006) @@ -646,6 +646,13 @@ raise OSError(errno.EBADF, errno.strerror(errno.EBADF)) if _name == 'posix' and _native_posix: + def link(src, dst): + """link(src, dst) + + Create a hard link to a file. + """ + _posix.link(sys.getPath(src), sys.getPath(dst)) + def symlink(src, dst): """symlink(src, dst) Deleted: branches/asm/Lib/test/output/test_re =================================================================== --- branches/asm/Lib/test/output/test_re 2008-07-28 02:41:38 UTC (rev 5005) +++ branches/asm/Lib/test/output/test_re 2008-07-28 04:56:03 UTC (rev 5006) @@ -1,15 +0,0 @@ -test_re -re (test_re.py) -basic functions -search -match -sub -symbolic references -subn -split -match.groups -match.group -escape -flags -symbolic groups in regex's -perl5-compatible regex's This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nr...@us...> - 2008-07-28 22:56:57
|
Revision: 5015 http://jython.svn.sourceforge.net/jython/?rev=5015&view=rev Author: nriley Date: 2008-07-28 22:56:55 +0000 (Mon, 28 Jul 2008) Log Message: ----------- pwd, grp; test_posix no longer skipped Modified Paths: -------------- branches/asm/Lib/test/regrtest.py Added Paths: ----------- branches/asm/Lib/grp.py branches/asm/Lib/pwd.py Added: branches/asm/Lib/grp.py =================================================================== --- branches/asm/Lib/grp.py (rev 0) +++ branches/asm/Lib/grp.py 2008-07-28 22:56:55 UTC (rev 5015) @@ -0,0 +1,77 @@ +""" +"Access to the Unix group database. + +Group entries are reported as 4-tuples containing the following fields +from the group database, in order: + + name - name of the group + passwd - group password (encrypted); often empty + gid - numeric ID of the group + mem - list of members + +The gid is an integer, name and password are strings. (Note that most +users are not explicitly listed as members of the groups they are in +according to the password database. Check both databases to get +complete membership information.) +""" + +__all__ = ['getgrgid', 'getgrnam', 'getgrall'] + +from os import _posix +from java.lang import NullPointerException + +class struct_group(tuple): + """ + grp.struct_group: Results from getgr*() routines. + + This object may be accessed either as a tuple of + (gr_name,gr_passwd,gr_gid,gr_mem) + or via the object attributes as named in the above tuple. + """ + + attrs = ['gr_name', 'gr_passwd', 'gr_gid', 'gr_mem'] + + def __new__(cls, grp): + return tuple.__new__(cls, (grp.gr_name, grp.gr_passwd, grp.gr_gid, + list(grp.getMembers()))) + + def __getattr__(self, attr): + try: + return self[self.attrs.index(attr)] + except ValueError: + raise AttributeError + +def getgrgid(uid): + """ + getgrgid(id) -> tuple + Return the group database entry for the given numeric group ID. If + id is not valid, raise KeyError."}, + """ + try: + return struct_group(_posix.getgrgid(uid)) + except NullPointerException: + raise KeyError, uid + +def getgrnam(name): + """ + getgrnam(name) -> tuple + Return the group database entry for the given group name. If + name is not valid, raise KeyError. + """ + try: + return struct_group(_posix.getgrnam(name)) + except NullPointerException: + raise KeyError, name + +def getgrall(): + """ + getgrall() -> list of tuples + Return a list of all available group database entries, + in arbitrary order. + """ + groups = [] + try: + while True: + groups.append(struct_group(_posix.getgrent())) + except NullPointerException: + return groups Added: branches/asm/Lib/pwd.py =================================================================== --- branches/asm/Lib/pwd.py (rev 0) +++ branches/asm/Lib/pwd.py 2008-07-28 22:56:55 UTC (rev 5015) @@ -0,0 +1,73 @@ +""" +This module provides access to the Unix password database. + +Password database entries are reported as 7-tuples containing the +following items from the password database (see `<pwd.h>'), in order: +pw_name, pw_passwd, pw_uid, pw_gid, pw_gecos, pw_dir, pw_shell. The +uid and gid items are integers, all others are strings. An exception +is raised if the entry asked for cannot be found. +""" + +__all__ = ['getpwuid', 'getpwnam', 'getpwall'] + +from os import _posix +from java.lang import NullPointerException + +class struct_passwd(tuple): + """ + pwd.struct_passwd: Results from getpw*() routines. + + This object may be accessed either as a tuple of + (pw_name,pw_passwd,pw_uid,pw_gid,pw_gecos,pw_dir,pw_shell) + or via the object attributes as named in the above tuple. + """ + + attrs = ['pw_name', 'pw_passwd', 'pw_uid', 'pw_gid', 'pw_gecos', + 'pw_dir', 'pw_shell'] + + def __new__(cls, pwd): + return tuple.__new__(cls, (getattr(pwd, attr) for attr in cls.attrs)) + + def __getattr__(self, attr): + try: + return self[self.attrs.index(attr)] + except ValueError: + raise AttributeError + +def getpwuid(uid): + """ + getpwuid(uid) -> (pw_name,pw_passwd,pw_uid, + pw_gid,pw_gecos,pw_dir,pw_shell) + Return the password database entry for the given numeric user ID. + See pwd.__doc__ for more on password database entries. + """ + try: + return struct_passwd(_posix.getpwuid(uid)) + except NullPointerException: + raise KeyError, uid + +def getpwnam(name): + """ + getpwnam(name) -> (pw_name,pw_passwd,pw_uid, + pw_gid,pw_gecos,pw_dir,pw_shell) + Return the password database entry for the given user name. + See pwd.__doc__ for more on password database entries. + """ + try: + return struct_passwd(_posix.getpwnam(name)) + except NullPointerException: + raise KeyError, name + +def getpwall(): + """ + getpwall() -> list_of_entries + Return a list of all available password database entries, + in arbitrary order. + See pwd.__doc__ for more on password database entries. + """ + entries = [] + try: + while True: + entries.append(struct_passwd(_posix.getpwent())) + except NullPointerException: + return entries Modified: branches/asm/Lib/test/regrtest.py =================================================================== --- branches/asm/Lib/test/regrtest.py 2008-07-28 22:55:35 UTC (rev 5014) +++ branches/asm/Lib/test/regrtest.py 2008-07-28 22:56:55 UTC (rev 5015) @@ -1406,7 +1406,6 @@ test_gdbm test_getargs2 test_gl - test_grp test_hotshot test_imageop test_imgfile @@ -1430,7 +1429,6 @@ test_poll test_profile test_pty - test_pwd test_pyexpat test_resource test_rgbimg This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-31 18:47:37
|
Revision: 5029 http://jython.svn.sourceforge.net/jython/?rev=5029&view=rev Author: pjenvey Date: 2008-07-31 18:47:34 +0000 (Thu, 31 Jul 2008) Log Message: ----------- rearrange imports to fix test_threaded_import -- a bogus fix, but also what CPython did for this problem Modified Paths: -------------- branches/asm/Lib/os.py branches/asm/Lib/random.py Modified: branches/asm/Lib/os.py =================================================================== --- branches/asm/Lib/os.py 2008-07-31 16:14:55 UTC (rev 5028) +++ branches/asm/Lib/os.py 2008-07-31 18:47:34 UTC (rev 5029) @@ -46,7 +46,8 @@ import stat as _stat import sys from java.io import File -from org.python.core.io import FileDescriptors +from org.python.core import PyFile +from org.python.core.io import FileDescriptors, FileIO, IOBase # Mapping of: os._name: [name list, shell command list] _os_map = dict(nt=[ @@ -537,7 +538,6 @@ if rawio.closed(): raise OSError(errno.EBADF, errno.strerror(errno.EBADF)) - from org.python.core import PyFile try: fp = PyFile(rawio, '<fdopen>', mode, bufsize) except IOError: @@ -588,7 +588,6 @@ # Default to reading reading = True - from org.python.core.io import FileIO if truncating and not writing: # Explicitly truncate, writing will truncate anyway FileIO(filename, 'w').close() @@ -966,8 +965,6 @@ if isinstance(fileno, FileDescriptor): return _posix.isatty(fileno) - from org.python.core.io import IOBase - if not isinstance(fileno, IOBase): print fileno raise TypeError('a file descriptor is required') Modified: branches/asm/Lib/random.py =================================================================== --- branches/asm/Lib/random.py 2008-07-31 16:14:55 UTC (rev 5028) +++ branches/asm/Lib/random.py 2008-07-31 18:47:34 UTC (rev 5029) @@ -38,6 +38,7 @@ a single Python step, and is, therefore, threadsafe. """ +import time from types import BuiltinMethodType as _BuiltinMethodType from math import log as _log, exp as _exp, pi as _pi, e as _e from math import sqrt as _sqrt, acos as _acos, cos as _cos, sin as _sin @@ -96,7 +97,6 @@ """ if a is None: - import time a = long(time.time() * 256) # use fractional seconds super(Random, self).seed(a) self.gauss_next = None This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <le...@us...> - 2008-08-12 22:58:49
|
Revision: 5163 http://jython.svn.sourceforge.net/jython/?rev=5163&view=rev Author: leosoto Date: 2008-08-12 22:58:47 +0000 (Tue, 12 Aug 2008) Log Message: ----------- subprocess.Popen now "inherits" os.environ if env is not explictely set. Fixes #1104 Modified Paths: -------------- branches/asm/Lib/subprocess.py Added Paths: ----------- branches/asm/Lib/test/test_subprocess_jy.py Modified: branches/asm/Lib/subprocess.py =================================================================== --- branches/asm/Lib/subprocess.py 2008-08-12 19:47:24 UTC (rev 5162) +++ branches/asm/Lib/subprocess.py 2008-08-12 22:58:47 UTC (rev 5163) @@ -1156,11 +1156,16 @@ except java.lang.IllegalArgumentException, iae: raise OSError(iae.getMessage() or iae) - if env is not None: - builder_env = builder.environment() - builder_env.clear() - builder_env.putAll(dict(env)) + if env is None: + # This is for compatibility with the CPython implementation, + # that ends up calling os.execvp(). So os.environ is "inherited" + # there if env is not explicitly set. + env = os.environ + builder_env = builder.environment() + builder_env.clear() + builder_env.putAll(dict(env)) + if cwd is None: cwd = os.getcwd() elif not os.path.exists(cwd): Added: branches/asm/Lib/test/test_subprocess_jy.py =================================================================== --- branches/asm/Lib/test/test_subprocess_jy.py (rev 0) +++ branches/asm/Lib/test/test_subprocess_jy.py 2008-08-12 22:58:47 UTC (rev 5163) @@ -0,0 +1,23 @@ +"Tests for cmp() compatibility with CPython" +import unittest +import os +import sys +from test import test_support +from subprocess import Popen, PIPE + +class EnvironmentInheritanceTest(unittest.TestCase): + def testDefaultEnvIsInherited(self): + # Test for issue #1104 + os.environ['foo'] = 'something' + p1 = Popen([sys.executable, "-c", + 'import os, sys; sys.stdout.write(os.environ["foo"])'], + stdout=PIPE) + self.assertEquals('something', p1.stdout.read()) + +def test_main(): + test_support.run_unittest(EnvironmentInheritanceTest) + +if __name__ == '__main__': + test_main() + + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |