You can subscribe to this list here.
2000 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
(107) |
Dec
(67) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2001 |
Jan
(76) |
Feb
(125) |
Mar
(72) |
Apr
(13) |
May
(18) |
Jun
(12) |
Jul
(129) |
Aug
(47) |
Sep
(1) |
Oct
(36) |
Nov
(128) |
Dec
(124) |
2002 |
Jan
(59) |
Feb
|
Mar
(14) |
Apr
(14) |
May
(72) |
Jun
(9) |
Jul
(3) |
Aug
(5) |
Sep
(18) |
Oct
(65) |
Nov
(28) |
Dec
(12) |
2003 |
Jan
(10) |
Feb
(2) |
Mar
(4) |
Apr
(33) |
May
(21) |
Jun
(9) |
Jul
(29) |
Aug
(34) |
Sep
(4) |
Oct
(8) |
Nov
(15) |
Dec
(4) |
2004 |
Jan
(26) |
Feb
(12) |
Mar
(11) |
Apr
(9) |
May
(7) |
Jun
|
Jul
(5) |
Aug
|
Sep
(3) |
Oct
(7) |
Nov
(1) |
Dec
(10) |
2005 |
Jan
(2) |
Feb
(72) |
Mar
(16) |
Apr
(39) |
May
(48) |
Jun
(97) |
Jul
(57) |
Aug
(13) |
Sep
(16) |
Oct
(24) |
Nov
(100) |
Dec
(24) |
2006 |
Jan
(15) |
Feb
(34) |
Mar
(33) |
Apr
(31) |
May
(79) |
Jun
(64) |
Jul
(41) |
Aug
(64) |
Sep
(31) |
Oct
(46) |
Nov
(55) |
Dec
(37) |
2007 |
Jan
(32) |
Feb
(61) |
Mar
(11) |
Apr
(58) |
May
(46) |
Jun
(30) |
Jul
(94) |
Aug
(93) |
Sep
(86) |
Oct
(69) |
Nov
(125) |
Dec
(177) |
2008 |
Jan
(169) |
Feb
(97) |
Mar
(74) |
Apr
(113) |
May
(120) |
Jun
(334) |
Jul
(215) |
Aug
(237) |
Sep
(72) |
Oct
(189) |
Nov
(126) |
Dec
(160) |
2009 |
Jan
(180) |
Feb
(45) |
Mar
(98) |
Apr
(140) |
May
(151) |
Jun
(71) |
Jul
(107) |
Aug
(119) |
Sep
(73) |
Oct
(121) |
Nov
(14) |
Dec
(6) |
2010 |
Jan
(13) |
Feb
(9) |
Mar
(10) |
Apr
(64) |
May
(3) |
Jun
(16) |
Jul
(7) |
Aug
(23) |
Sep
(17) |
Oct
(37) |
Nov
(5) |
Dec
(8) |
2011 |
Jan
(10) |
Feb
(11) |
Mar
(77) |
Apr
(11) |
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <otm...@us...> - 2009-05-23 06:22:51
|
Revision: 6369 http://jython.svn.sourceforge.net/jython/?rev=6369&view=rev Author: otmarhumbel Date: 2009-05-23 06:22:38 +0000 (Sat, 23 May 2009) Log Message: ----------- fix open(os.devnull, 'w') on German Windows, too Modified Paths: -------------- trunk/jython/src/org/python/core/io/FileIO.java Modified: trunk/jython/src/org/python/core/io/FileIO.java =================================================================== --- trunk/jython/src/org/python/core/io/FileIO.java 2009-05-23 06:21:19 UTC (rev 6368) +++ trunk/jython/src/org/python/core/io/FileIO.java 2009-05-23 06:22:38 UTC (rev 6369) @@ -170,7 +170,7 @@ String message = ioe.getMessage(); if (((Platform.IS_SOLARIS || Platform.IS_LINUX) && Errno.EINVAL.description().equals(message)) - || (Platform.IS_WINDOWS && "Incorrect function".equals(message))) { + || (Platform.IS_WINDOWS && isIncorrectFunction(message))) { return; } throw Py.IOError(ioe); @@ -178,6 +178,16 @@ } } + private boolean isIncorrectFunction(String msg) { + String ae = "\u00E4"; + if ("Incorrect function".equals(msg)) { // en + return true; + } else if ("Unzul".concat(ae).concat("ssige Funktion").equals(msg)) { // de_CH + return true; + } + return false; + } + /** {@inheritDoc} */ public boolean isatty() { checkClosed(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <otm...@us...> - 2009-05-23 06:21:31
|
Revision: 6368 http://jython.svn.sourceforge.net/jython/?rev=6368&view=rev Author: otmarhumbel Date: 2009-05-23 06:21:19 +0000 (Sat, 23 May 2009) Log Message: ----------- fix test_javashell Modified Paths: -------------- trunk/jython/Lib/javashell.py Modified: trunk/jython/Lib/javashell.py =================================================================== --- trunk/jython/Lib/javashell.py 2009-05-23 02:02:32 UTC (rev 6367) +++ trunk/jython/Lib/javashell.py 2009-05-23 06:21:19 UTC (rev 6368) @@ -89,5 +89,5 @@ def _getOsType(): return os._name -_shellEnv = _ShellEnv(subprocess.shell_command) +_shellEnv = _ShellEnv(subprocess._shell_command) shellexecute = _shellEnv.execute This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-05-23 02:22:28
|
Revision: 6365 http://jython.svn.sourceforge.net/jython/?rev=6365&view=rev Author: pjenvey Date: 2009-05-23 01:42:59 +0000 (Sat, 23 May 2009) Log Message: ----------- make the Jython extras especially private Modified Paths: -------------- trunk/jython/Lib/subprocess.py Modified: trunk/jython/Lib/subprocess.py =================================================================== --- trunk/jython/Lib/subprocess.py 2009-05-23 01:23:24 UTC (rev 6364) +++ trunk/jython/Lib/subprocess.py 2009-05-23 01:42:59 UTC (rev 6365) @@ -545,45 +545,45 @@ if jython: # Escape the command line arguments with list2cmdline on Windows - escape_args_oses = ['nt'] + _escape_args_oses = ['nt'] - escape_args = None - shell_command = None + _escape_args = None + _shell_command = None - def setup_platform(): + def _setup_platform(): """Setup the shell command and the command line argument escape function depending on the underlying platform """ - global escape_args, shell_command + global _escape_args, _shell_command - if os._name in escape_args_oses: - escape_args = lambda args: [list2cmdline([arg]) for arg in args] + if os._name in _escape_args_oses: + _escape_args = lambda args: [list2cmdline([arg]) for arg in args] else: - escape_args = lambda args: args + _escape_args = lambda args: args os_info = os._os_map.get(os._name) if os_info is None: os_info = os._os_map.get('posix') - for _shell_command in os_info[1]: - executable = _shell_command[0] + for shell_command in os_info[1]: + executable = shell_command[0] if not os.path.isabs(executable): import distutils.spawn executable = distutils.spawn.find_executable(executable) if not executable or not os.path.exists(executable): continue - _shell_command[0] = executable - shell_command = _shell_command + shell_command[0] = executable + _shell_command = shell_command return - if not shell_command: + if not _shell_command: import warnings - warnings.warn('Unable to determine shell_command for ' + warnings.warn('Unable to determine _shell_command for ' 'underlying os: %s' % os._name, RuntimeWarning, 3) - setup_platform() + _setup_platform() - class CouplerThread(java.lang.Thread): + class _CouplerThread(java.lang.Thread): """Couples a reader and writer RawIOBase. @@ -603,7 +603,8 @@ self.read_func = read_func self.write_func = write_func self.close_func = close_func - self.setName('CouplerThread-%s (%s)' % (id(self), name)) + self.setName('%s-%s (%s)' % (self.__class__.__name__, id(self), + name)) self.setDaemon(True) def run(self): @@ -720,7 +721,7 @@ self._stdout_thread = None self._stderr_thread = None - # 'ct' is for CouplerThread + # 'ct' is for _CouplerThread proc = self._process ct2cwrite = org.python.core.io.StreamIO(proc.getOutputStream(), True) @@ -737,8 +738,9 @@ if p2cread is None: # Coupling stdin is not supported: there's no way to # cleanly interrupt it if it blocks the - # CouplerThread forever (we can Thread.interrupt() - # its CouplerThread but that closes stdin's Channel) + # _CouplerThread forever (we can Thread.interrupt() + # its _CouplerThread but that closes stdin's + # Channel) pass else: self._stdin_thread = self._coupler_thread('stdin', @@ -1128,8 +1130,8 @@ def _coupler_thread(self, *args, **kwargs): - """Return a CouplerThread""" - return CouplerThread(*args, **kwargs) + """Return a _CouplerThread""" + return _CouplerThread(*args, **kwargs) def _setup_env(self, env, builder_env): @@ -1174,10 +1176,10 @@ # posix. Windows passes unicode through however if not isinstance(arg, (str, unicode)): raise TypeError('args must contain only strings') - args = escape_args(args) + args = _escape_args(args) if shell: - args = shell_command + args + args = _shell_command + args if executable is not None: args[0] = executable @@ -1200,8 +1202,8 @@ builder.directory(java.io.File(cwd)) # Let Java manage redirection of stderr to stdout (it's more - # accurate at doing so than CouplerThreads). We redirect not - # only when stderr is marked as STDOUT, but also when + # accurate at doing so than _CouplerThreads). We redirect + # not only when stderr is marked as STDOUT, but also when # c2pwrite is errwrite if self._stderr_is_stdout(errwrite, c2pwrite): builder.redirectErrorStream(True) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-05-23 02:03:37
|
Revision: 6367 http://jython.svn.sourceforge.net/jython/?rev=6367&view=rev Author: pjenvey Date: 2009-05-23 02:02:32 +0000 (Sat, 23 May 2009) Log Message: ----------- fix windows detection Modified Paths: -------------- trunk/jython/Lib/test/test_popen2.py Modified: trunk/jython/Lib/test/test_popen2.py =================================================================== --- trunk/jython/Lib/test/test_popen2.py 2009-05-23 02:01:49 UTC (rev 6366) +++ trunk/jython/Lib/test/test_popen2.py 2009-05-23 02:02:32 UTC (rev 6367) @@ -5,7 +5,7 @@ import os import sys -from test.test_support import TestSkipped, reap_children +from test.test_support import TestSkipped, is_jython, reap_children # popen2 contains its own testing routine # which is especially useful to see if open files @@ -40,7 +40,7 @@ assert not popen2._active, "Active pipes when test starts " + repr([c.cmd for c in popen2._active]) cmd = "cat" teststr = "ab cd\n" - if os.name == "nt": + if os.name == "nt" or (is_jython and os._name == 'nt'): cmd = "more" # "more" doesn't act the same way across Windows flavors, # sometimes adding an extra newline at the start or the This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-05-23 02:03:16
|
Revision: 6366 http://jython.svn.sourceforge.net/jython/?rev=6366&view=rev Author: pjenvey Date: 2009-05-23 02:01:49 +0000 (Sat, 23 May 2009) Log Message: ----------- from: http://svn.python.org/projects/python/branches/release25-maint/Lib/test/test_popen2.py Added Paths: ----------- trunk/jython/Lib/test/test_popen2.py Added: trunk/jython/Lib/test/test_popen2.py =================================================================== --- trunk/jython/Lib/test/test_popen2.py (rev 0) +++ trunk/jython/Lib/test/test_popen2.py 2009-05-23 02:01:49 UTC (rev 6366) @@ -0,0 +1,78 @@ +#! /usr/bin/env python +"""Test script for popen2.py + Christian Tismer +""" + +import os +import sys +from test.test_support import TestSkipped, reap_children + +# popen2 contains its own testing routine +# which is especially useful to see if open files +# like stdin can be read successfully by a forked +# subprocess. + +def main(): + print "Test popen2 module:" + if (sys.platform[:4] == 'beos' or sys.platform[:6] == 'atheos') \ + and __name__ != '__main__': + # Locks get messed up or something. Generally we're supposed + # to avoid mixing "posix" fork & exec with native threads, and + # they may be right about that after all. + raise TestSkipped, "popen2() doesn't work during import on " + sys.platform + try: + from os import popen + except ImportError: + # if we don't have os.popen, check that + # we have os.fork. if not, skip the test + # (by raising an ImportError) + from os import fork + import popen2 + popen2._test() + + +def _test(): + # same test as popen2._test(), but using the os.popen*() API + print "Testing os module:" + import popen2 + # When the test runs, there shouldn't be any open pipes + popen2._cleanup() + assert not popen2._active, "Active pipes when test starts " + repr([c.cmd for c in popen2._active]) + cmd = "cat" + teststr = "ab cd\n" + if os.name == "nt": + cmd = "more" + # "more" doesn't act the same way across Windows flavors, + # sometimes adding an extra newline at the start or the + # end. So we strip whitespace off both ends for comparison. + expected = teststr.strip() + print "testing popen2..." + w, r = os.popen2(cmd) + w.write(teststr) + w.close() + got = r.read() + if got.strip() != expected: + raise ValueError("wrote %r read %r" % (teststr, got)) + print "testing popen3..." + try: + w, r, e = os.popen3([cmd]) + except: + w, r, e = os.popen3(cmd) + w.write(teststr) + w.close() + got = r.read() + if got.strip() != expected: + raise ValueError("wrote %r read %r" % (teststr, got)) + got = e.read() + if got: + raise ValueError("unexpected %r on stderr" % (got,)) + for inst in popen2._active[:]: + inst.wait() + popen2._cleanup() + if popen2._active: + raise ValueError("_active not empty") + print "All OK" + +main() +_test() +reap_children() Property changes on: trunk/jython/Lib/test/test_popen2.py ___________________________________________________________________ Added: svn:keywords + Id This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-05-23 01:23:40
|
Revision: 6364 http://jython.svn.sourceforge.net/jython/?rev=6364&view=rev Author: pjenvey Date: 2009-05-23 01:23:24 +0000 (Sat, 23 May 2009) Log Message: ----------- handle failed __init__s Modified Paths: -------------- trunk/jython/Lib/popen2.py Modified: trunk/jython/Lib/popen2.py =================================================================== --- trunk/jython/Lib/popen2.py 2009-05-22 02:41:04 UTC (rev 6363) +++ trunk/jython/Lib/popen2.py 2009-05-23 01:23:24 UTC (rev 6364) @@ -47,7 +47,10 @@ self.childerr = self._popen.stderr def __del__(self): - self._popen.__del__() + # XXX: Should let _popen __del__ on its own, but it's a new + # style class: http://bugs.jython.org/issue1057 + if hasattr(self, '_popen'): + self._popen.__del__() def poll(self, _deadstate=None): """Return the exit status of the child process if it has finished, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-05-22 02:41:20
|
Revision: 6363 http://jython.svn.sourceforge.net/jython/?rev=6363&view=rev Author: pjenvey Date: 2009-05-22 02:41:04 +0000 (Fri, 22 May 2009) Log Message: ----------- don't use subprocess.call with PIPEs. it only wait()s -- without consuming those pipes, their buffers can fill and cause a chatty child (like test_run_module with the smaller Windows PIPE_BUF) to deadlock fixes #1351 Modified Paths: -------------- trunk/jython/Lib/test/test_cmd_line.py Modified: trunk/jython/Lib/test/test_cmd_line.py =================================================================== --- trunk/jython/Lib/test/test_cmd_line.py 2009-05-21 06:04:58 UTC (rev 6362) +++ trunk/jython/Lib/test/test_cmd_line.py 2009-05-22 02:41:04 UTC (rev 6363) @@ -1,4 +1,4 @@ - +import os import test.test_support, unittest import sys import popen2 @@ -18,8 +18,11 @@ def exit_code(self, *args): cmd_line = [sys.executable] cmd_line.extend(args) - return subprocess.call(cmd_line, stdout=subprocess.PIPE, - stderr=subprocess.PIPE) + devnull = open(os.devnull, 'w') + result = subprocess.call(cmd_line, stdout=devnull, + stderr=subprocess.STDOUT) + devnull.close() + return result def test_directories(self): self.assertNotEqual(self.exit_code('.'), 0) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-05-21 06:05:19
|
Revision: 6362 http://jython.svn.sourceforge.net/jython/?rev=6362&view=rev Author: pjenvey Date: 2009-05-21 06:04:58 +0000 (Thu, 21 May 2009) Log Message: ----------- bump pipe_buf back down to 512 for Windows, it can't handle 16384 Modified Paths: -------------- trunk/jython/Lib/test/test_subprocess.py Modified: trunk/jython/Lib/test/test_subprocess.py =================================================================== --- trunk/jython/Lib/test/test_subprocess.py 2009-05-21 04:10:49 UTC (rev 6361) +++ trunk/jython/Lib/test/test_subprocess.py 2009-05-21 06:04:58 UTC (rev 6362) @@ -323,7 +323,7 @@ # communicate() with writes larger than pipe_buf # This test will probably deadlock rather than fail, if # communicate() does not work properly. - if mswindows: + if mswindows or (jython and os._name == 'nt'): pipe_buf = 512 elif jython: pipe_buf = 16384 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-05-21 04:11:07
|
Revision: 6361 http://jython.svn.sourceforge.net/jython/?rev=6361&view=rev Author: pjenvey Date: 2009-05-21 04:10:49 +0000 (Thu, 21 May 2009) Log Message: ----------- fix open(os.devnull, 'w') on Windows Modified Paths: -------------- trunk/jython/.classpath trunk/jython/build.xml trunk/jython/src/org/python/core/io/FileIO.java Modified: trunk/jython/.classpath =================================================================== --- trunk/jython/.classpath 2009-05-20 15:09:43 UTC (rev 6360) +++ trunk/jython/.classpath 2009-05-21 04:10:49 UTC (rev 6361) @@ -17,5 +17,6 @@ <classpathentry kind="lib" path="extlibs/asm-3.1.jar"/> <classpathentry kind="lib" path="extlibs/asm-commons-3.1.jar"/> <classpathentry kind="lib" path="extlibs/constantine-0.4.jar"/> + <classpathentry kind="lib" path="extlibs/jna-posix.jar"/> <classpathentry kind="output" path="bugtests/classes"/> </classpath> Modified: trunk/jython/build.xml =================================================================== --- trunk/jython/build.xml 2009-05-20 15:09:43 UTC (rev 6360) +++ trunk/jython/build.xml 2009-05-21 04:10:49 UTC (rev 6361) @@ -158,6 +158,7 @@ <pathelement path="${extlibs.dir}/asm-3.1.jar" /> <pathelement path="${extlibs.dir}/asm-commons-3.1.jar" /> <pathelement path="${extlibs.dir}/constantine-0.4.jar" /> + <pathelement path="${extlibs.dir}/jna-posix.jar"/> </path> <available property="informix.present" classname="com.informix.jdbc.IfxDriver" classpath="${informix.jar}" /> Modified: trunk/jython/src/org/python/core/io/FileIO.java =================================================================== --- trunk/jython/src/org/python/core/io/FileIO.java 2009-05-20 15:09:43 UTC (rev 6360) +++ trunk/jython/src/org/python/core/io/FileIO.java 2009-05-21 04:10:49 UTC (rev 6361) @@ -13,6 +13,7 @@ import java.nio.channels.FileChannel; import com.kenai.constantine.platform.Errno; +import org.jruby.ext.posix.util.Platform; import org.python.core.Py; import org.python.core.util.FileUtil; import org.python.core.util.RelativeFile; @@ -162,12 +163,14 @@ try { fileChannel.truncate(0); } catch (IOException ioe) { - // On Solaris and Linux, ftruncate(3C) returns EINVAL - // if not a regular file whereas, e.g., - // open("/dev/null", "w") works fine. Because we have - // to simulate the "w" mode in Java, we suppress the - // exception. - if (ioe.getMessage().equals("Invalid argument")) { + // On Solaris and Linux, ftruncate(3C) returns EINVAL if not a regular + // file whereas, e.g., open(os.devnull, "w") works. Likewise Windows + // returns ERROR_INVALID_FUNCTION. Because we have to simulate the "w" + // mode in Java, we suppress the exception. + String message = ioe.getMessage(); + if (((Platform.IS_SOLARIS || Platform.IS_LINUX) + && Errno.EINVAL.description().equals(message)) + || (Platform.IS_WINDOWS && "Incorrect function".equals(message))) { return; } throw Py.IOError(ioe); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <am...@us...> - 2009-05-20 15:09:54
|
Revision: 6360 http://jython.svn.sourceforge.net/jython/?rev=6360&view=rev Author: amak Date: 2009-05-20 15:09:43 +0000 (Wed, 20 May 2009) Log Message: ----------- Backporting changes from trunk. 1. Socket options are now level specific 2. Explicit backlog parameter on listen 3. Setting has_ipv6 to False Modified Paths: -------------- branches/Release_2_2maint/jython/Lib/socket.py branches/Release_2_2maint/jython/Lib/test/test_socket.py Modified: branches/Release_2_2maint/jython/Lib/socket.py =================================================================== --- branches/Release_2_2maint/jython/Lib/socket.py 2009-05-20 06:09:43 UTC (rev 6359) +++ branches/Release_2_2maint/jython/Lib/socket.py 2009-05-20 15:09:43 UTC (rev 6360) @@ -141,17 +141,6 @@ SHUT_WR = 1 SHUT_RDWR = 2 -__all__ = ['AF_UNSPEC', 'AF_INET', 'AF_INET6', 'AI_PASSIVE', 'SOCK_DGRAM', - 'SOCK_RAW', 'SOCK_RDM', 'SOCK_SEQPACKET', 'SOCK_STREAM', 'SOL_SOCKET', - 'SO_BROADCAST', 'SO_ERROR', 'SO_KEEPALIVE', 'SO_LINGER', 'SO_OOBINLINE', - 'SO_RCVBUF', 'SO_REUSEADDR', 'SO_SNDBUF', 'SO_TIMEOUT', 'TCP_NODELAY', - 'SocketType', 'error', 'herror', 'gaierror', 'timeout', - 'getfqdn', 'gethostbyaddr', 'gethostbyname', 'gethostname', - 'socket', 'getaddrinfo', 'getdefaulttimeout', 'setdefaulttimeout', - 'has_ipv6', 'htons', 'htonl', 'ntohs', 'ntohl', - 'SHUT_RD', 'SHUT_WR', 'SHUT_RDWR', - ] - AF_UNSPEC = 0 AF_INET = 2 AF_INET6 = 23 @@ -165,6 +154,8 @@ SOCK_SEQPACKET = 5 # not supported SOL_SOCKET = 0xFFFF +IPPROTO_TCP = 6 +IPPROTO_UDP = 17 SO_BROADCAST = 1 SO_KEEPALIVE = 2 @@ -197,6 +188,28 @@ SO_TYPE = -1024 SO_USELOOPBACK = -2048 +__all__ = ['AF_UNSPEC', 'AF_INET', 'AF_INET6', 'AI_PASSIVE', 'SOCK_DGRAM', + 'SOCK_RAW', 'SOCK_RDM', 'SOCK_SEQPACKET', 'SOCK_STREAM', 'SOL_SOCKET', + 'SO_BROADCAST', 'SO_ERROR', 'SO_KEEPALIVE', 'SO_LINGER', 'SO_OOBINLINE', + 'SO_RCVBUF', 'SO_REUSEADDR', 'SO_SNDBUF', 'SO_TIMEOUT', 'TCP_NODELAY', + 'INADDR_ANY', 'INADDR_BROADCAST', 'IPPROTO_TCP', 'IPPROTO_UDP', + 'SocketType', 'error', 'herror', 'gaierror', 'timeout', + 'getfqdn', 'gethostbyaddr', 'gethostbyname', 'gethostname', + 'socket', 'getaddrinfo', 'getdefaulttimeout', 'setdefaulttimeout', + 'has_ipv6', 'htons', 'htonl', 'ntohs', 'ntohl', + 'SHUT_RD', 'SHUT_WR', 'SHUT_RDWR', + ] + +def _constant_to_name(const_value): + sock_module = sys.modules['socket'] + try: + for name in dir(sock_module): + if getattr(sock_module, name) is const_value: + return name + return "Unknown" + finally: + sock_module = None + class _nio_impl: timeout = None @@ -216,9 +229,9 @@ self._timeout_millis = int(timeout*1000) self.jsocket.setSoTimeout(self._timeout_millis) - def getsockopt(self, option): - if self.options.has_key(option): - result = getattr(self.jsocket, "get%s" % self.options[option])() + def getsockopt(self, level, option): + if self.options.has_key( (level, option) ): + result = getattr(self.jsocket, "get%s" % self.options[ (level, option) ])() if option == SO_LINGER: if result == -1: enabled, linger_time = 0, 0 @@ -227,17 +240,17 @@ return struct.pack('ii', enabled, linger_time) return result else: - raise error(errno.ENOPROTOOPT, "Option not supported on socket(%s): %d" % (str(self.jsocket), option)) + raise error(errno.ENOPROTOOPT, "Socket option '%s' (level '%s') not supported on socket(%s)" % (_constant_to_name(option), _constant_to_name(level), str(self.jsocket))) - def setsockopt(self, option, value): - if self.options.has_key(option): + def setsockopt(self, level, option, value): + if self.options.has_key( (level, option) ): if option == SO_LINGER: values = struct.unpack('ii', value) self.jsocket.setSoLinger(*values) else: - getattr(self.jsocket, "set%s" % self.options[option])(value) + getattr(self.jsocket, "set%s" % self.options[ (level, option) ])(value) else: - raise error(errno.ENOPROTOOPT, "Option not supported on socket(%s): %d" % (str(self.jsocket), option)) + raise error(errno.ENOPROTOOPT, "Socket option '%s' (level '%s') not supported on socket(%s)" % (_constant_to_name(option), _constant_to_name(level), str(self.jsocket))) def close(self): self.jsocket.close() @@ -250,14 +263,14 @@ class _client_socket_impl(_nio_impl): options = { - SO_KEEPALIVE: 'KeepAlive', - SO_LINGER: 'SoLinger', - SO_OOBINLINE: 'OOBInline', - SO_RCVBUF: 'ReceiveBufferSize', - SO_REUSEADDR: 'ReuseAddress', - SO_SNDBUF: 'SendBufferSize', - SO_TIMEOUT: 'SoTimeout', - TCP_NODELAY: 'TcpNoDelay', + (SOL_SOCKET, SO_KEEPALIVE): 'KeepAlive', + (SOL_SOCKET, SO_LINGER): 'SoLinger', + (SOL_SOCKET, SO_OOBINLINE): 'OOBInline', + (SOL_SOCKET, SO_RCVBUF): 'ReceiveBufferSize', + (SOL_SOCKET, SO_REUSEADDR): 'ReuseAddress', + (SOL_SOCKET, SO_SNDBUF): 'SendBufferSize', + (SOL_SOCKET, SO_TIMEOUT): 'SoTimeout', + (IPPROTO_TCP, TCP_NODELAY): 'TcpNoDelay', } def __init__(self, socket=None): @@ -325,9 +338,9 @@ class _server_socket_impl(_nio_impl): options = { - SO_RCVBUF: 'ReceiveBufferSize', - SO_REUSEADDR: 'ReuseAddress', - SO_TIMEOUT: 'SoTimeout', + (SOL_SOCKET, SO_RCVBUF): 'ReceiveBufferSize', + (SOL_SOCKET, SO_REUSEADDR): 'ReuseAddress', + (SOL_SOCKET, SO_TIMEOUT): 'SoTimeout', } def __init__(self, host, port, backlog, reuse_addr): @@ -353,20 +366,20 @@ return _client_socket_impl(new_cli_sock) def shutdown(self, how): - # This is no-op on java, for server sockets. - # What the user wants to achieve is achieved by calling close() on - # java/jython. But we can't call that here because that would then - # later cause the user explicit close() call to fail - pass - + # This is no-op on java, for server sockets. + # What the user wants to achieve is achieved by calling close() on + # java/jython. But we can't call that here because that would then + # later cause the user explicit close() call to fail + pass + class _datagram_socket_impl(_nio_impl): options = { - SO_BROADCAST: 'Broadcast', - SO_RCVBUF: 'ReceiveBufferSize', - SO_REUSEADDR: 'ReuseAddress', - SO_SNDBUF: 'SendBufferSize', - SO_TIMEOUT: 'SoTimeout', + (SOL_SOCKET, SO_BROADCAST): 'Broadcast', + (SOL_SOCKET, SO_RCVBUF): 'ReceiveBufferSize', + (SOL_SOCKET, SO_REUSEADDR): 'ReuseAddress', + (SOL_SOCKET, SO_SNDBUF): 'SendBufferSize', + (SOL_SOCKET, SO_TIMEOUT): 'SoTimeout', } def __init__(self, port=None, address=None, reuse_addr=0): @@ -394,12 +407,12 @@ self.jchannel.disconnect() def shutdown(self, how): - # This is no-op on java, for datagram sockets. - # What the user wants to achieve is achieved by calling close() on - # java/jython. But we can't call that here because that would then - # later cause the user explicit close() call to fail - pass - + # This is no-op on java, for datagram sockets. + # What the user wants to achieve is achieved by calling close() on + # java/jython. But we can't call that here because that would then + # later cause the user explicit close() call to fail + pass + def _do_send_net(self, byte_array, socket_address, flags): # Need two separate implementations because the java.nio APIs do not support timeouts num_bytes = len(byte_array) @@ -472,10 +485,11 @@ else: return self._do_receive_nio(0, num_bytes, flags) +# For now, we DO NOT have complete IPV6 support. +has_ipv6 = False + # Name and address functions -has_ipv6 = 1 - def _gethostbyaddr(name): # This is as close as I can get; at least the types are correct... addresses = java.net.InetAddress.getAllByName(gethostbyname(name)) @@ -532,13 +546,16 @@ # Same situation as above raise NotImplementedError("getprotobyname not yet supported on jython.") -def _realsocket(family = AF_INET, type = SOCK_STREAM, flags=0): - assert family == AF_INET - assert type in (SOCK_DGRAM, SOCK_STREAM) - assert flags == 0 +def _realsocket(family = AF_INET, type = SOCK_STREAM, protocol=0): + assert family == AF_INET, "Only AF_INET sockets are currently supported on jython" + assert type in (SOCK_DGRAM, SOCK_STREAM), "Only SOCK_STREAM and SOCK_DGRAM sockets are currently supported on jython" if type == SOCK_STREAM: + if protocol != 0: + assert protocol == IPPROTO_TCP, "Only IPPROTO_TCP supported on SOCK_STREAM sockets" return _tcpsocket() else: + if protocol != 0: + assert protocol == IPPROTO_UDP, "Only IPPROTO_UDP supported on SOCK_DGRAM sockets" return _udpsocket() def getaddrinfo(host, port, family=AF_INET, socktype=None, proto=0, flags=None): @@ -629,11 +646,11 @@ close_lock = threading.Lock() def __init__(self): - self.timeout = _defaulttimeout - if self.timeout is not None: - self.mode = MODE_TIMEOUT + self.timeout = _defaulttimeout + if self.timeout is not None: + self.mode = MODE_TIMEOUT self.pending_options = { - SO_REUSEADDR: 0, + (SOL_SOCKET, SO_REUSEADDR): 0, } def gettimeout(self): @@ -662,34 +679,32 @@ return self.mode == MODE_BLOCKING def setsockopt(self, level, optname, value): - if level != SOL_SOCKET: return try: if self.sock_impl: - self.sock_impl.setsockopt(optname, value) + self.sock_impl.setsockopt(level, optname, value) else: - self.pending_options[optname] = value + self.pending_options[ (level, optname) ] = value except java.lang.Exception, jlx: raise _map_exception(jlx) def getsockopt(self, level, optname): - if level != SOL_SOCKET: return try: if self.sock_impl: - return self.sock_impl.getsockopt(optname) + return self.sock_impl.getsockopt(level, optname) else: - return self.pending_options.get(optname, None) + return self.pending_options.get( (level, optname), None) except java.lang.Exception, jlx: raise _map_exception(jlx) def shutdown(self, how): assert how in (SHUT_RD, SHUT_WR, SHUT_RDWR) if not self.sock_impl: - raise error(errno.ENOTCONN, "Transport endpoint is not connected") + raise error(errno.ENOTCONN, "Transport endpoint is not connected") try: self.sock_impl.shutdown(how) except java.lang.Exception, jlx: raise _map_exception(jlx) - + def close(self): try: if self.sock_impl: @@ -701,9 +716,9 @@ assert self.mode in _permitted_modes if self.sock_impl: self.sock_impl.config(self.mode, self.timeout) - for k in self.pending_options.keys(): - if k != SO_REUSEADDR: - self.sock_impl.setsockopt(k, self.pending_options[k]) + for level, optname in self.pending_options.keys(): + if optname != SO_REUSEADDR: + self.sock_impl.setsockopt(level, optname, self.pending_options[ (level, optname) ]) def getchannel(self): if not self.sock_impl: @@ -745,7 +760,7 @@ _unpack_address_tuple(addr) self.local_addr = addr - def listen(self, backlog=50): + def listen(self, backlog): "This signifies a server socket" try: assert not self.sock_impl @@ -754,7 +769,7 @@ host, port = _unpack_address_tuple(self.local_addr) else: host, port = "", 0 - self.sock_impl = _server_socket_impl(host, port, backlog, self.pending_options[SO_REUSEADDR]) + self.sock_impl = _server_socket_impl(host, port, backlog, self.pending_options[ (SOL_SOCKET, SO_REUSEADDR) ]) self._config() except java.lang.Exception, jlx: raise _map_exception(jlx) @@ -769,7 +784,7 @@ if not new_sock: raise would_block_error() cliconn = _tcpsocket() - cliconn.pending_options[SO_REUSEADDR] = new_sock.jsocket.getReuseAddress() + cliconn.pending_options[ (SOL_SOCKET, SO_REUSEADDR) ] = new_sock.jsocket.getReuseAddress() cliconn.sock_impl = new_sock cliconn._setup() return cliconn, new_sock.getpeername() @@ -789,7 +804,7 @@ self.sock_impl = _client_socket_impl() if self.local_addr: # Has the socket been bound to a local address? bind_host, bind_port = _unpack_address_tuple(self.local_addr) - self.sock_impl.bind(bind_host, bind_port, self.pending_options[SO_REUSEADDR]) + self.sock_impl.bind(bind_host, bind_port, self.pending_options[ (SOL_SOCKET, SO_REUSEADDR) ]) self._config() # Configure timeouts, etc, now that the socket exists self.sock_impl.connect(host, port) except java.lang.Exception, jlx: @@ -886,7 +901,7 @@ if self.sock_impl: self.sock_impl.close() except java.lang.Exception, jlx: - raise _map_exception(jlx) + raise _map_exception(jlx) class _udpsocket(_nonblocking_api_mixin): @@ -903,7 +918,7 @@ if host == "": host = INADDR_ANY host_address = java.net.InetAddress.getByName(host) - self.sock_impl = _datagram_socket_impl(port, host_address, self.pending_options[SO_REUSEADDR]) + self.sock_impl = _datagram_socket_impl(port, host_address, self.pending_options[ (SOL_SOCKET, SO_REUSEADDR) ]) self._config() except java.lang.Exception, jlx: raise _map_exception(jlx) @@ -1003,7 +1018,7 @@ def __del__(self): self.close() - + _socketmethods = ( 'bind', 'connect', 'connect_ex', 'fileno', 'listen', 'getpeername', 'getsockname', 'getsockopt', 'setsockopt', Modified: branches/Release_2_2maint/jython/Lib/test/test_socket.py =================================================================== --- branches/Release_2_2maint/jython/Lib/test/test_socket.py 2009-05-20 06:09:43 UTC (rev 6359) +++ branches/Release_2_2maint/jython/Lib/test/test_socket.py 2009-05-20 15:09:43 UTC (rev 6360) @@ -21,6 +21,10 @@ MSG = 'Michael Gilfix was here\n' EIGHT_BIT_MSG = 'Bh\xed Al\xe1in \xd3 Cinn\xe9ide anseo\n' +import java +os_name = java.lang.System.getProperty('os.name') +is_bsd = os_name == 'Mac OS X' or 'BSD' in os_name + try: True except NameError: @@ -522,26 +526,27 @@ def setUp(self): self.test_udp = self.test_tcp_client = self.test_tcp_server = 0 - def _testSetAndGetOption(self, sock, option, values): + def _testSetAndGetOption(self, sock, level, option, values): for expected_value in values: - sock.setsockopt(socket.SOL_SOCKET, option, expected_value) - retrieved_value = sock.getsockopt(socket.SOL_SOCKET, option) + sock.setsockopt(level, option, expected_value) + retrieved_value = sock.getsockopt(level, option) self.failUnlessEqual(retrieved_value, expected_value, \ - "Retrieved option(%s) value %s != %s(value set)" % (option, retrieved_value, expected_value)) + "Retrieved option(%s, %s) value %s != %s(value set)" % (level, option, retrieved_value, expected_value)) - def _testUDPOption(self, option, values): + def _testUDPOption(self, level, option, values): try: sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - self._testSetAndGetOption(sock, option, values) + self._testSetAndGetOption(sock, level, option, values) # now bind the socket i.e. cause the implementation socket to be created sock.bind( (HOST, PORT) ) - self.failUnlessEqual(sock.getsockopt(socket.SOL_SOCKET, option), values[-1], \ - "Option value '%s'='%s' did not propagate to implementation socket" % (option, values[-1]) ) - self._testSetAndGetOption(sock, option, values) + self.failUnlessEqual(sock.getsockopt(level, option), values[-1], \ + "Option value '(%s, %s)'='%s' did not propagate to implementation socket" % (level, option, values[-1]) ) + self._testSetAndGetOption(sock, level, option, values) finally: sock.close() - def _testTCPClientOption(self, option, values): + def _testTCPClientOption(self, level, option, values): + sock = None try: # First listen on a server socket, so that the connection won't be refused. server_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) @@ -549,42 +554,51 @@ server_sock.listen(50) # Now do the tests sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - self._testSetAndGetOption(sock, option, values) + self._testSetAndGetOption(sock, level, option, values) # now connect the socket i.e. cause the implementation socket to be created # First bind, so that the SO_REUSEADDR setting propagates sock.bind( (HOST, PORT+1) ) sock.connect( (HOST, PORT) ) - self.failUnlessEqual(sock.getsockopt(socket.SOL_SOCKET, option), values[-1], \ - "Option value '%s'='%s' did not propagate to implementation socket" % (option, values[-1])) - self._testSetAndGetOption(sock, option, values) + msg = "Option value '%s'='%s' did not propagate to implementation socket" % (option, values[-1]) + if is_bsd and option in (socket.SO_RCVBUF, socket.SO_SNDBUF): + # XXX: there's no guarantee that bufsize will be the + # exact setsockopt value, particularly after + # establishing a connection. seems it will be *at least* + # the values we test (which are rather small) on + # BSDs. may need to relax this on other platforms also + self.assert_(sock.getsockopt(level, option) >= values[-1], msg) + else: + self.failUnlessEqual(sock.getsockopt(level, option), values[-1], msg) + self._testSetAndGetOption(sock, level, option, values) finally: server_sock.close() - sock.close() + if sock: + sock.close() - def _testTCPServerOption(self, option, values): + def _testTCPServerOption(self, level, option, values): try: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - self._testSetAndGetOption(sock, option, values) + self._testSetAndGetOption(sock, level, option, values) # now bind and listen on the socket i.e. cause the implementation socket to be created sock.bind( (HOST, PORT) ) sock.listen(50) - self.failUnlessEqual(sock.getsockopt(socket.SOL_SOCKET, option), values[-1], \ - "Option value '%s'='%s' did not propagate to implementation socket" % (option, values[-1])) - self._testSetAndGetOption(sock, option, values) + self.failUnlessEqual(sock.getsockopt(level, option), values[-1], \ + "Option value '(%s,%s)'='%s' did not propagate to implementation socket" % (level, option, values[-1])) + self._testSetAndGetOption(sock, level, option, values) finally: sock.close() - def _testOption(self, option, values): + def _testOption(self, level, option, values): for flag, func in [ (self.test_udp, self._testUDPOption), (self.test_tcp_server, self._testTCPServerOption), (self.test_tcp_client, self._testTCPClientOption), ]: if flag: - func(option, values) + func(level, option, values) else: try: - func(option, values) + func(level, option, values) except socket.error, se: self.failUnlessEqual(se[0], errno.ENOPROTOOPT, "Wrong errno from unsupported option exception: %d" % se[0]) except Exception, x: @@ -596,48 +610,48 @@ def testSO_BROADCAST(self): self.test_udp = 1 - self._testOption(socket.SO_BROADCAST, [0, 1]) + self._testOption(socket.SOL_SOCKET, socket.SO_BROADCAST, [0, 1]) def testSO_KEEPALIVE(self): self.test_tcp_client = 1 - self._testOption(socket.SO_KEEPALIVE, [0, 1]) + self._testOption(socket.SOL_SOCKET, socket.SO_KEEPALIVE, [0, 1]) def testSO_LINGER(self): self.test_tcp_client = 1 off = struct.pack('ii', 0, 0) on_2_seconds = struct.pack('ii', 1, 2) - self._testOption(socket.SO_LINGER, [off, on_2_seconds]) + self._testOption(socket.SOL_SOCKET, socket.SO_LINGER, [off, on_2_seconds]) def testSO_OOBINLINE(self): self.test_tcp_client = 1 - self._testOption(socket.SO_OOBINLINE, [0, 1]) + self._testOption(socket.SOL_SOCKET, socket.SO_OOBINLINE, [0, 1]) def testSO_RCVBUF(self): self.test_udp = 1 self.test_tcp_client = 1 self.test_tcp_server = 1 - self._testOption(socket.SO_RCVBUF, [1024, 4096, 16384]) + self._testOption(socket.SOL_SOCKET, socket.SO_RCVBUF, [1024, 4096, 16384]) def testSO_REUSEADDR(self): self.test_udp = 1 self.test_tcp_client = 1 self.test_tcp_server = 1 - self._testOption(socket.SO_REUSEADDR, [0, 1]) + self._testOption(socket.SOL_SOCKET, socket.SO_REUSEADDR, [0, 1]) def testSO_SNDBUF(self): self.test_udp = 1 self.test_tcp_client = 1 - self._testOption(socket.SO_SNDBUF, [1024, 4096, 16384]) + self._testOption(socket.SOL_SOCKET, socket.SO_SNDBUF, [1024, 4096, 16384]) def testSO_TIMEOUT(self): self.test_udp = 1 self.test_tcp_client = 1 self.test_tcp_server = 1 - self._testOption(socket.SO_TIMEOUT, [0, 1, 1000]) + self._testOption(socket.SOL_SOCKET, socket.SO_TIMEOUT, [0, 1, 1000]) def testTCP_NODELAY(self): self.test_tcp_client = 1 - self._testOption(socket.TCP_NODELAY, [0, 1]) + self._testOption(socket.IPPROTO_TCP, socket.TCP_NODELAY, [0, 1]) class TestUnsupportedOptions(TestSocketOptions): @@ -795,31 +809,31 @@ self.serv_conn.send(MSG) self.serv_conn.send('and ' + MSG) -class UDPBindTest(unittest.TestCase): - +class UDPBindTest(unittest.TestCase): + HOST = HOST PORT = PORT - def setUp(self): + def setUp(self): self.sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM) - - def testBindSpecific(self): + + def testBindSpecific(self): self.sock.bind( (self.HOST, self.PORT) ) # Use a specific port - actual_port = self.sock.getsockname()[1] - self.failUnless(actual_port == self.PORT, - "Binding to specific port number should have returned same number: %d != %d" % (actual_port, self.PORT)) + actual_port = self.sock.getsockname()[1] + self.failUnless(actual_port == self.PORT, + "Binding to specific port number should have returned same number: %d != %d" % (actual_port, self.PORT)) - def testBindEphemeral(self): + def testBindEphemeral(self): self.sock.bind( (self.HOST, 0) ) # let system choose a free port - self.failUnless(self.sock.getsockname()[1] != 0, "Binding to port zero should have allocated an ephemeral port number") + self.failUnless(self.sock.getsockname()[1] != 0, "Binding to port zero should have allocated an ephemeral port number") - def testShutdown(self): - self.sock.bind( (self.HOST, self.PORT) ) - self.sock.shutdown(socket.SHUT_RDWR) + def testShutdown(self): + self.sock.bind( (self.HOST, self.PORT) ) + self.sock.shutdown(socket.SHUT_RDWR) - def tearDown(self): - self.sock.close() - + def tearDown(self): + self.sock.close() + class BasicUDPTest(ThreadedUDPSocketTest): def __init__(self, methodName='runTest'): @@ -1327,7 +1341,7 @@ used, but if it is on your network this failure is bogus.''' % host) def testConnectDefaultTimeout(self): - _saved_timeout = socket.getdefaulttimeout() + _saved_timeout = socket.getdefaulttimeout() socket.setdefaulttimeout(0.1) cli = socket.socket(socket.AF_INET, socket.SOCK_STREAM) host = '192.168.192.168' This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <otm...@us...> - 2009-05-20 06:09:56
|
Revision: 6359 http://jython.svn.sourceforge.net/jython/?rev=6359&view=rev Author: otmarhumbel Date: 2009-05-20 06:09:43 +0000 (Wed, 20 May 2009) Log Message: ----------- changelog r6358 Modified Paths: -------------- trunk/jython/NEWS Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2009-05-20 05:44:58 UTC (rev 6358) +++ trunk/jython/NEWS 2009-05-20 06:09:43 UTC (rev 6359) @@ -4,6 +4,7 @@ Bugs fixed - [ 1344 ] setName semantics of threading.Thread different to CPython - Fixed JLine console on cygwin + - [ 1348 ] muti-threaded issue, maybe threads cannot exit Jython 2.5.0 a0 - rc1 Bugs fixed (new numbering due to move to Roundup) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <otm...@us...> - 2009-05-20 05:45:11
|
Revision: 6358 http://jython.svn.sourceforge.net/jython/?rev=6358&view=rev Author: otmarhumbel Date: 2009-05-20 05:44:58 +0000 (Wed, 20 May 2009) Log Message: ----------- on termination, delete the thread from the global _threads list fixes issue #1348 Modified Paths: -------------- trunk/jython/Lib/test/test_threading_jy.py trunk/jython/Lib/threading.py Modified: trunk/jython/Lib/test/test_threading_jy.py =================================================================== --- trunk/jython/Lib/test/test_threading_jy.py 2009-05-18 21:52:55 UTC (rev 6357) +++ trunk/jython/Lib/test/test_threading_jy.py 2009-05-20 05:44:58 UTC (rev 6358) @@ -4,6 +4,9 @@ """ import unittest from test import test_support +import threading +import time +import random from threading import Thread class ThreadingTestCase(unittest.TestCase): @@ -13,8 +16,26 @@ self.assertEqual(t.getName(), '1') t.setName(2) self.assertEqual(t.getName(), '2') + + # make sure activeCount() gets decremented (see issue 1348) + def test_activeCount(self): + activeBefore = threading.activeCount() + activeCount = 10 + for i in range(activeCount): + t = Thread(target=self._sleep, args=(i,)) + t.setDaemon(0) + t.start() + polls = activeCount + while activeCount > activeBefore and polls > 0: + time.sleep(1) + activeCount = threading.activeCount() + polls -= 1 + self.assertTrue(activeCount <= activeBefore, 'activeCount should to be <= %s, instead of %s' % (activeBefore, activeCount)) + def _sleep(self, n): + time.sleep(random.random()) + def test_main(): test_support.run_unittest(ThreadingTestCase) Modified: trunk/jython/Lib/threading.py =================================================================== --- trunk/jython/Lib/threading.py 2009-05-18 21:52:55 UTC (rev 6357) +++ trunk/jython/Lib/threading.py 2009-05-20 05:44:58 UTC (rev 6358) @@ -294,7 +294,7 @@ pass def __delete(self): - pass + del _threads[self._thread.getId()] class _MainThread(Thread): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <otm...@us...> - 2009-05-18 21:53:02
|
Revision: 6357 http://jython.svn.sourceforge.net/jython/?rev=6357&view=rev Author: otmarhumbel Date: 2009-05-18 21:52:55 +0000 (Mon, 18 May 2009) Log Message: ----------- re-enable setting a different console in the registry Modified Paths: -------------- trunk/jython/src/org/python/util/jython.java Added Paths: ----------- trunk/jython/tests/java/org/python/util/jythonTest.java Modified: trunk/jython/src/org/python/util/jython.java =================================================================== --- trunk/jython/src/org/python/util/jython.java 2009-05-18 05:02:53 UTC (rev 6356) +++ trunk/jython/src/org/python/util/jython.java 2009-05-18 21:52:55 UTC (rev 6357) @@ -322,7 +322,7 @@ } String interpClass = PySystemState.registry.getProperty("python.console", ""); - if (interpClass.length() == 0) { + if (interpClass.length() > 0) { try { return (InteractiveConsole)Class.forName(interpClass).newInstance(); } catch (Throwable t) { Added: trunk/jython/tests/java/org/python/util/jythonTest.java =================================================================== --- trunk/jython/tests/java/org/python/util/jythonTest.java (rev 0) +++ trunk/jython/tests/java/org/python/util/jythonTest.java 2009-05-18 21:52:55 UTC (rev 6357) @@ -0,0 +1,88 @@ +package org.python.util; + +import java.lang.reflect.Method; +import java.util.Properties; + +import org.python.core.PySystemState; + +import junit.framework.TestCase; + +/** + * Tests for creating the right interactive console. + */ +public class jythonTest extends TestCase { + + private static final String PYTHON_CONSOLE = "python.console"; + + private Properties _originalRegistry; + + @Override + protected void setUp() throws Exception { + _originalRegistry = PySystemState.registry; + Properties registry; + if (_originalRegistry != null) { + registry = new Properties(_originalRegistry); + } else { + registry = new Properties(); + } + PySystemState.registry = registry; + } + + @Override + protected void tearDown() throws Exception { + PySystemState.registry = _originalRegistry; + } + + /** + * test the default behavior + * + * @throws Exception + */ + public void testNewInterpreter() throws Exception { + assertEquals(JLineConsole.class, invokeNewInterpreter(true).getClass()); + } + + /** + * test registry override + * + * @throws Exception + */ + public void testNewInterpreter_registry() throws Exception { + PySystemState.registry.setProperty(PYTHON_CONSOLE, "org.python.util.InteractiveConsole"); + assertEquals(InteractiveConsole.class, invokeNewInterpreter(true).getClass()); + } + + /** + * test fallback in case of an invalid registry value + * + * @throws Exception + */ + public void testNewInterpreter_unknown() throws Exception { + PySystemState.registry.setProperty(PYTHON_CONSOLE, "foo.bar.NoConsole"); + assertEquals(JLineConsole.class, invokeNewInterpreter(true).getClass()); + } + + /** + * test non-interactive fallback to legacy console + * + * @throws Exception + */ + public void testNewInterpreter_NonInteractive() throws Exception { + assertEquals(InteractiveConsole.class, invokeNewInterpreter(false).getClass()); + } + + /** + * Invoke the private static method 'newInterpreter(boolean)' on jython.class + * + * @throws Exception + */ + private InteractiveConsole invokeNewInterpreter(boolean interactiveStdin) throws Exception { + Method method = jython.class.getDeclaredMethod("newInterpreter", Boolean.TYPE); + assertNotNull(method); + method.setAccessible(true); + Object result = method.invoke(null, interactiveStdin); + assertNotNull(result); + assertTrue(result instanceof InteractiveConsole); + return (InteractiveConsole)result; + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-05-18 05:03:16
|
Revision: 6356 http://jython.svn.sourceforge.net/jython/?rev=6356&view=rev Author: pjenvey Date: 2009-05-18 05:02:53 +0000 (Mon, 18 May 2009) Log Message: ----------- include the probably working smtpd and wsgiref's .egg-info Modified Paths: -------------- trunk/jython/CPythonLib.includes Modified: trunk/jython/CPythonLib.includes =================================================================== --- trunk/jython/CPythonLib.includes 2009-05-18 05:02:19 UTC (rev 6355) +++ trunk/jython/CPythonLib.includes 2009-05-18 05:02:53 UTC (rev 6356) @@ -134,6 +134,7 @@ SimpleXMLRPCServer.py site.py site-packages/README +smtpd.py smtplib.py sndhdr.py SocketServer.py @@ -166,6 +167,7 @@ weakref.py whichdb.py whrandom.py +wsgiref.egg-info wsgiref/*.py xdrlib.py xmllib.py This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-05-18 05:02:33
|
Revision: 6355 http://jython.svn.sourceforge.net/jython/?rev=6355&view=rev Author: pjenvey Date: 2009-05-18 05:02:19 +0000 (Mon, 18 May 2009) Log Message: ----------- changelog jline and some new modules Modified Paths: -------------- trunk/jython/NEWS Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2009-05-17 20:41:51 UTC (rev 6354) +++ trunk/jython/NEWS 2009-05-18 05:02:19 UTC (rev 6355) @@ -3,6 +3,7 @@ Jython 2.5.0 Bugs fixed - [ 1344 ] setName semantics of threading.Thread different to CPython + - Fixed JLine console on cygwin Jython 2.5.0 a0 - rc1 Bugs fixed (new numbering due to move to Roundup) @@ -315,10 +316,18 @@ New Features - PyDictionary now implements Map so it may be passed to any Java function expecting a Map. - modjy integrated into core + - The interactive interpreter now uses JLine by default Ported Modules + - _ast + - cmath - collections + - csv - filecmp + - functools + - hashlib + - itertools - threading.local + - zipimport Jython 2.2.2 rc1 Bugs fixed (new numbering due to move to Roundup) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <am...@us...> - 2009-05-17 20:41:57
|
Revision: 6354 http://jython.svn.sourceforge.net/jython/?rev=6354&view=rev Author: amak Date: 2009-05-17 20:41:51 +0000 (Sun, 17 May 2009) Log Message: ----------- Improving error reporting for unsupported socket options. Modified Paths: -------------- trunk/jython/Lib/socket.py Modified: trunk/jython/Lib/socket.py =================================================================== --- trunk/jython/Lib/socket.py 2009-05-16 05:15:28 UTC (rev 6353) +++ trunk/jython/Lib/socket.py 2009-05-17 20:41:51 UTC (rev 6354) @@ -192,7 +192,7 @@ SO_SNDTIMEO = -512 SO_TYPE = -1024 SO_USELOOPBACK = -2048 - + __all__ = ['AF_UNSPEC', 'AF_INET', 'AF_INET6', 'AI_PASSIVE', 'SOCK_DGRAM', 'SOCK_RAW', 'SOCK_RDM', 'SOCK_SEQPACKET', 'SOCK_STREAM', 'SOL_SOCKET', 'SO_BROADCAST', 'SO_ERROR', 'SO_KEEPALIVE', 'SO_LINGER', 'SO_OOBINLINE', @@ -205,6 +205,16 @@ 'SHUT_RD', 'SHUT_WR', 'SHUT_RDWR', ] +def _constant_to_name(const_value): + sock_module = sys.modules['socket'] + try: + for name in dir(sock_module): + if getattr(sock_module, name) is const_value: + return name + return "Unknown" + finally: + sock_module = None + class _nio_impl: timeout = None @@ -235,7 +245,7 @@ return struct.pack('ii', enabled, linger_time) return result else: - raise error(errno.ENOPROTOOPT, "Level %d option not supported on socket(%s): %d" % (level, str(self.jsocket), option)) + raise error(errno.ENOPROTOOPT, "Socket option '%s' (level '%s') not supported on socket(%s)" % (_constant_to_name(option), _constant_to_name(level), str(self.jsocket))) def setsockopt(self, level, option, value): if self.options.has_key( (level, option) ): @@ -245,7 +255,7 @@ else: getattr(self.jsocket, "set%s" % self.options[ (level, option) ])(value) else: - raise error(errno.ENOPROTOOPT, "Level %d option not supported on socket(%s): %d" % (level, str(self.jsocket), option)) + raise error(errno.ENOPROTOOPT, "Socket option '%s' (level '%s') not supported on socket(%s)" % (_constant_to_name(option), _constant_to_name(level), str(self.jsocket))) def close(self): self.jsocket.close() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-05-16 05:15:49
|
Revision: 6353 http://jython.svn.sourceforge.net/jython/?rev=6353&view=rev Author: pjenvey Date: 2009-05-16 05:15:28 +0000 (Sat, 16 May 2009) Log Message: ----------- handle stty failures and don't hardcode UnixTerminal when they happen thanks Weiqi Gao Modified Paths: -------------- trunk/jython/src/shell/jython Modified: trunk/jython/src/shell/jython =================================================================== --- trunk/jython/src/shell/jython 2009-05-16 01:58:51 UTC (rev 6352) +++ trunk/jython/src/shell/jython 2009-05-16 05:15:28 UTC (rev 6353) @@ -228,8 +228,10 @@ fi # fix JLine to use UnixTerminal - stty -icanon min 1 -echo - JAVA_OPTS="$JAVA_OPTS -Djline.terminal=jline.UnixTerminal" + stty -icanon min 1 -echo > /dev/null 2>&1 + if [ $? = 0 ]; then + JAVA_OPTS="$JAVA_OPTS -Djline.terminal=jline.UnixTerminal" + fi fi if [ -n "$profile_requested" -o -z "$boot_requested" ] ; then @@ -269,7 +271,7 @@ fi if $cygwin; then - stty icanon echo + stty icanon echo > /dev/null 2>&1 fi exit $JYTHON_STATUS This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-05-16 02:02:23
|
Revision: 6352 http://jython.svn.sourceforge.net/jython/?rev=6352&view=rev Author: pjenvey Date: 2009-05-16 01:58:51 +0000 (Sat, 16 May 2009) Log Message: ----------- refactor Modified Paths: -------------- trunk/jython/src/org/python/util/jython.java Modified: trunk/jython/src/org/python/util/jython.java =================================================================== --- trunk/jython/src/org/python/util/jython.java 2009-05-16 01:14:07 UTC (rev 6351) +++ trunk/jython/src/org/python/util/jython.java 2009-05-16 01:58:51 UTC (rev 6352) @@ -317,18 +317,19 @@ * unexpected behavior with the std file streams. */ private static InteractiveConsole newInterpreter(boolean interactiveStdin) { - if (interactiveStdin) { - String interpClass = PySystemState.registry.getProperty("python.console", ""); - if (interpClass.length() > 0) { - try { - return (InteractiveConsole)Class.forName(interpClass).newInstance(); - } catch (Throwable t) { - // fall through - } + if (!interactiveStdin) { + return new InteractiveConsole(); + } + + String interpClass = PySystemState.registry.getProperty("python.console", ""); + if (interpClass.length() == 0) { + try { + return (InteractiveConsole)Class.forName(interpClass).newInstance(); + } catch (Throwable t) { + // fall through } - return new JLineConsole(); } - return new InteractiveConsole(); + return new JLineConsole(); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-05-16 01:14:08
|
Revision: 6351 http://jython.svn.sourceforge.net/jython/?rev=6351&view=rev Author: pjenvey Date: 2009-05-16 01:14:07 +0000 (Sat, 16 May 2009) Log Message: ----------- cygwin fixes: tweak term settings/CP_DELIMITER and hardcode to UnixTerminal thanks Weiqi Gao Modified Paths: -------------- trunk/jython/src/shell/jython Modified: trunk/jython/src/shell/jython =================================================================== --- trunk/jython/src/shell/jython 2009-05-15 03:24:44 UTC (rev 6350) +++ trunk/jython/src/shell/jython 2009-05-16 01:14:07 UTC (rev 6351) @@ -91,7 +91,9 @@ fi if $cygwin; then - CP=`cygpath -wp "$CP"` + # switch delimiter only after building a Unix style $CP + CP_DELIMITER=";" + CP=`cygpath -p -w "$CP"` PRG=`cygpath -w "$PRG"` fi @@ -224,6 +226,10 @@ win_args=("$win_arg" "$@") set -- "${win_args[@]}" fi + + # fix JLine to use UnixTerminal + stty -icanon min 1 -echo + JAVA_OPTS="$JAVA_OPTS -Djline.terminal=jline.UnixTerminal" fi if [ -n "$profile_requested" -o -z "$boot_requested" ] ; then @@ -262,4 +268,8 @@ echo "JYTHON_OPTS: default command line arguments" >&2 fi +if $cygwin; then + stty icanon echo +fi + exit $JYTHON_STATUS This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-05-15 03:24:50
|
Revision: 6350 http://jython.svn.sourceforge.net/jython/?rev=6350&view=rev Author: pjenvey Date: 2009-05-15 03:24:44 +0000 (Fri, 15 May 2009) Log Message: ----------- o workaround broken ctrl-z handling on BSD platforms, but support ctrl-z return as EOF on windows o don't bother stripping newlines as jline never returns them Modified Paths: -------------- trunk/jython/src/org/python/util/JLineConsole.java Modified: trunk/jython/src/org/python/util/JLineConsole.java =================================================================== --- trunk/jython/src/org/python/util/JLineConsole.java 2009-05-15 01:33:01 UTC (rev 6349) +++ trunk/jython/src/org/python/util/JLineConsole.java 2009-05-15 03:24:44 UTC (rev 6350) @@ -10,9 +10,14 @@ import java.io.InputStream; import java.io.OutputStreamWriter; import java.io.Writer; +import java.util.Arrays; +import java.util.List; +import com.kenai.constantine.platform.Errno; + import jline.ConsoleReader; import jline.Terminal; +import jline.WindowsTerminal; import org.python.core.Py; import org.python.core.PyObject; @@ -24,8 +29,22 @@ */ public class JLineConsole extends InteractiveConsole { + /** Main interface to JLine. */ protected ConsoleReader reader; + /** Whether reader is a WindowsTerminal. */ + private boolean windows; + + /** The ctrl-z character String. */ + protected static final String CTRL_Z = "\u001a"; + + /** + * Errno strerrors possibly caused by a SIGSTP (ctrl-z). They may propagate up to + * IOException messages. + */ + private static final List<String> SUSPENDED_STRERRORS = + Arrays.asList(Errno.EINTR.description(), Errno.EIO.description()); + public JLineConsole() { this(null); } @@ -57,6 +76,8 @@ } catch (IOException e) { throw new RuntimeException(e); } + + windows = reader.getTerminal() instanceof WindowsTerminal; } /** @@ -84,21 +105,55 @@ } } catch (SecurityException se) { // continue - } + } return getClass().getResourceAsStream("jline-keybindings.properties"); } @Override public String raw_input(PyObject prompt) { String line = null; - try { - line = reader.readLine(prompt.toString()); - } catch (IOException io) { - throw Py.IOError(io); + String promptString = prompt.toString(); + + while (true) { + try { + line = reader.readLine(promptString); + break; + } catch (IOException ioe) { + if (!fromSuspend(ioe)) { + throw Py.IOError(ioe); + } + + // Hopefully an IOException caused by ctrl-z (seems only BSD throws this). + // Must reset jline to continue + try { + reader.getTerminal().initializeTerminal(); + } catch (Exception e) { + throw Py.IOError(e.getMessage()); + } + // Don't redisplay the prompt + promptString = ""; + } } - if (line == null) { - throw Py.EOFError("Ctrl-D exit"); + + if (isEOF(line)) { + throw Py.EOFError(""); } - return line.endsWith("\n") ? line.substring(0, line.length() - 1) : line; + + return line; } + + /** + * Determine if the IOException was likely caused by a SIGSTP (ctrl-z). Seems only + * applicable to BSD platforms. + */ + private boolean fromSuspend(IOException ioe) { + return !windows && SUSPENDED_STRERRORS.contains(ioe.getMessage()); + } + + /** + * Determine if line denotes an EOF. + */ + private boolean isEOF(String line) { + return line == null || (windows && CTRL_Z.equals(line)); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-05-15 03:15:16
|
Revision: 6349 http://jython.svn.sourceforge.net/jython/?rev=6349&view=rev Author: pjenvey Date: 2009-05-15 01:33:01 +0000 (Fri, 15 May 2009) Log Message: ----------- we support isatty now Modified Paths: -------------- trunk/jython/Lib/test/test_file.py Modified: trunk/jython/Lib/test/test_file.py =================================================================== --- trunk/jython/Lib/test/test_file.py 2009-05-13 03:02:05 UTC (rev 6348) +++ trunk/jython/Lib/test/test_file.py 2009-05-15 01:33:01 UTC (rev 6349) @@ -88,8 +88,7 @@ def testErrors(self): f = self.f self.assertEquals(f.name, TESTFN) - # XXX: Jython doesn't support isatty - #self.assert_(not f.isatty()) + self.assert_(not f.isatty()) self.assert_(not f.closed) self.assertRaises(TypeError, f.readinto, "") @@ -103,9 +102,7 @@ # 'readline', 'readlines', 'seek', 'tell', 'truncate', # 'write', 'xreadlines', '__iter__'] noarg = object() - # XXX: Jython doesn't support isatty - #methods = dict(fileno=noarg, flush=noarg, isatty=noarg, next=noarg, - methods = dict(fileno=noarg, flush=noarg, next=noarg, + methods = dict(fileno=noarg, flush=noarg, isatty=noarg, next=noarg, read=-1, readinto=array('c', 'x'), readline=-1, readlines=noarg, seek=0, tell=noarg, truncate=0, write='x', xreadlines=noarg, __iter__=noarg) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-05-13 03:02:26
|
Revision: 6348 http://jython.svn.sourceforge.net/jython/?rev=6348&view=rev Author: pjenvey Date: 2009-05-13 03:02:05 +0000 (Wed, 13 May 2009) Log Message: ----------- changelog r6347 Modified Paths: -------------- trunk/jython/NEWS Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2009-05-13 02:59:46 UTC (rev 6347) +++ trunk/jython/NEWS 2009-05-13 03:02:05 UTC (rev 6348) @@ -1,5 +1,9 @@ Jython NEWS +Jython 2.5.0 + Bugs fixed + - [ 1344 ] setName semantics of threading.Thread different to CPython + Jython 2.5.0 a0 - rc1 Bugs fixed (new numbering due to move to Roundup) - [ 1188 ] Patch against trunk to handle SecurityExceptions This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-05-13 03:00:05
|
Revision: 6347 http://jython.svn.sourceforge.net/jython/?rev=6347&view=rev Author: pjenvey Date: 2009-05-13 02:59:46 +0000 (Wed, 13 May 2009) Log Message: ----------- strify the thread name fixes #1344 Modified Paths: -------------- trunk/jython/Lib/threading.py Added Paths: ----------- trunk/jython/Lib/test/test_threading_jy.py Added: trunk/jython/Lib/test/test_threading_jy.py =================================================================== --- trunk/jython/Lib/test/test_threading_jy.py (rev 0) +++ trunk/jython/Lib/test/test_threading_jy.py 2009-05-13 02:59:46 UTC (rev 6347) @@ -0,0 +1,23 @@ +"""Misc threading module tests + +Made for Jython. +""" +import unittest +from test import test_support +from threading import Thread + +class ThreadingTestCase(unittest.TestCase): + + def test_str_name(self): + t = Thread(name=1) + self.assertEqual(t.getName(), '1') + t.setName(2) + self.assertEqual(t.getName(), '2') + + +def test_main(): + test_support.run_unittest(ThreadingTestCase) + + +if __name__ == "__main__": + test_main() Property changes on: trunk/jython/Lib/test/test_threading_jy.py ___________________________________________________________________ Added: svn:keywords + Id Modified: trunk/jython/Lib/threading.py =================================================================== --- trunk/jython/Lib/threading.py 2009-05-13 02:50:33 UTC (rev 6346) +++ trunk/jython/Lib/threading.py 2009-05-13 02:59:46 UTC (rev 6347) @@ -200,7 +200,7 @@ return self._thread.getName() def setName(self, name): - self._thread.setName(name) + self._thread.setName(str(name)) def isAlive(self): return self._thread.isAlive() @@ -228,7 +228,7 @@ self._args = args self._kwargs = kwargs if name: - self._thread.setName(name) + self._thread.setName(str(name)) def _create_thread(self): return _newFunctionThread(self.__bootstrap, ()) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-05-13 02:50:54
|
Revision: 6346 http://jython.svn.sourceforge.net/jython/?rev=6346&view=rev Author: pjenvey Date: 2009-05-13 02:50:33 +0000 (Wed, 13 May 2009) Log Message: ----------- apply tempfile workarounds from r3712. with r6345 makes _TemporaryFileWrapper a context manager Modified Paths: -------------- trunk/jython/Lib/tempfile.py trunk/jython/Lib/test/test_tempfile.py Modified: trunk/jython/Lib/tempfile.py =================================================================== --- trunk/jython/Lib/tempfile.py 2009-05-13 02:48:53 UTC (rev 6345) +++ trunk/jython/Lib/tempfile.py 2009-05-13 02:50:33 UTC (rev 6346) @@ -377,6 +377,19 @@ self.name = name self.close_called = False + # XXX: CPython assigns unlink as a class var but this would + # rebind Jython's os.unlink (to be a classmethod) because it's + # not a built-in function (unfortunately built-in functions act + # differently when binding: + # http://mail.python.org/pipermail/python-dev/2003-April/034749.html) + + # Cache the unlinker so we don't get spurious errors at + # shutdown when the module-level "os" is None'd out. Note + # that this must be referenced as self.unlink, because the + # name TemporaryFileWrapper may also get None'd out before + # __del__ is called. + self.unlink = _os.unlink + def __getattr__(self, name): # Attribute lookups are delegated to the underlying file # and cached for non-numeric results @@ -397,13 +410,6 @@ # the wrapper to do anything special. We still use it so that # file.name is useful (i.e. not "(fdopen)") with NamedTemporaryFile. if _os.name != 'nt': - # Cache the unlinker so we don't get spurious errors at - # shutdown when the module-level "os" is None'd out. Note - # that this must be referenced as self.unlink, because the - # name TemporaryFileWrapper may also get None'd out before - # __del__ is called. - unlink = _os.unlink - def close(self): if not self.close_called: self.close_called = True Modified: trunk/jython/Lib/test/test_tempfile.py =================================================================== --- trunk/jython/Lib/test/test_tempfile.py 2009-05-13 02:48:53 UTC (rev 6345) +++ trunk/jython/Lib/test/test_tempfile.py 2009-05-13 02:50:33 UTC (rev 6346) @@ -1,3 +1,4 @@ +# From Python 2.5.1 # tempfile.py unit tests. from __future__ import with_statement import tempfile @@ -207,21 +208,32 @@ class mkstemped: _bflags = tempfile._bin_openflags _tflags = tempfile._text_openflags - _close = os.close - _unlink = os.unlink def __init__(self, dir, pre, suf, bin): if bin: flags = self._bflags else: flags = self._tflags + # XXX: CPython assigns _close/_unlink as class vars but this + # would rebind Jython's close/unlink (to be classmethods) + # because they're not built-in functions (unfortunately + # built-in functions act differently when binding: + # http://mail.python.org/pipermail/python-dev/2003-April/034749.html) + self._close = os.close + self._unlink = os.unlink (self.fd, self.name) = tempfile._mkstemp_inner(dir, pre, suf, flags) def write(self, str): os.write(self.fd, str) + # XXX: self.test_choose_directory expects the file to have been deleted + # (via __del__) by the time it's called, which is CPython specific + # garbage collection behavior. We need to delete it now in Jython + self._close(self.fd) + self._unlink(self.name) def __del__(self): self._close(self.fd) - self._unlink(self.name) + if os.path.exists(self.name): + self._unlink(self.name) def do_create(self, dir=None, pre="", suf="", bin=1): if dir is None: @@ -247,6 +259,10 @@ extant = range(TEST_FILES) for i in extant: extant[i] = self.do_create(pre="aa") + # XXX: Ensure mkstemped files are deleted (can't rely on Java's + # GC) + for i in extant: + i.__del__() def test_choose_directory(self): # _mkstemp_inner can create files in a user-selected directory @@ -256,7 +272,8 @@ finally: os.rmdir(dir) - def test_file_mode(self): + # XXX: Jython can't set the write mode yet + def _test_file_mode(self): # _mkstemp_inner creates files with the proper mode if not has_stat: return # ugh, can't use TestSkipped. @@ -477,6 +494,9 @@ # mkdtemp creates directories with the proper mode if not has_stat: return # ugh, can't use TestSkipped. + if os.name == 'java': + # Java doesn't support stating files for permissions + return dir = self.do_create() try: @@ -509,18 +529,25 @@ self.dir = None class mktemped: - _unlink = os.unlink _bflags = tempfile._bin_openflags def __init__(self, dir, pre, suf): + # XXX: Assign _unlink here, instead of as a class var. See + # mkstemped.__init__ for an explanation + self._unlink = os.unlink + self.name = tempfile.mktemp(dir=dir, prefix=pre, suffix=suf) # Create the file. This will raise an exception if it's # mysteriously appeared in the meanwhile. os.close(os.open(self.name, self._bflags, 0600)) - - def __del__(self): + # XXX: test_mktemp.tearDown expects the file to have been deleted + # (via __del__) by the time it's called, which is CPython specific + # garbage collection behavior. We need to delete it now in Jython self._unlink(self.name) + #def __del__(self): + # self._unlink(self.name) + def do_create(self, pre="", suf=""): try: file = self.mktemped(self.dir, pre, suf) @@ -675,3 +702,7 @@ if __name__ == "__main__": test_main() + # XXX: Nudge Java's GC in an attempt to trigger any temp file's + # __del__ (cause them to be deleted) that hasn't been called + from java.lang import System + System.gc() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-05-13 02:49:13
|
Revision: 6345 http://jython.svn.sourceforge.net/jython/?rev=6345&view=rev Author: pjenvey Date: 2009-05-13 02:48:53 +0000 (Wed, 13 May 2009) Log Message: ----------- from: http://svn.python.org/projects/python/branches/release25-maint/Lib/tempfile.py@60728 http://svn.python.org/projects/python/branches/release25-maint/Lib/test/test_tempfile.py@60728 Modified Paths: -------------- trunk/jython/Lib/tempfile.py trunk/jython/Lib/test/test_tempfile.py Modified: trunk/jython/Lib/tempfile.py =================================================================== --- trunk/jython/Lib/tempfile.py 2009-05-12 01:51:08 UTC (rev 6344) +++ trunk/jython/Lib/tempfile.py 2009-05-13 02:48:53 UTC (rev 6345) @@ -377,30 +377,32 @@ self.name = name self.close_called = False - # XXX: CPython assigns unlink as a class var but this would - # rebind Jython's os.unlink (to be a classmethod) because it's - # not a built-in function (unfortunately built-in functions act - # differently when binding: - # http://mail.python.org/pipermail/python-dev/2003-April/034749.html) - - # Cache the unlinker so we don't get spurious errors at - # shutdown when the module-level "os" is None'd out. Note - # that this must be referenced as self.unlink, because the - # name TemporaryFileWrapper may also get None'd out before - # __del__ is called. - self.unlink = _os.unlink - def __getattr__(self, name): + # Attribute lookups are delegated to the underlying file + # and cached for non-numeric results + # (i.e. methods are cached, closed and friends are not) file = self.__dict__['file'] a = getattr(file, name) if type(a) != type(0): setattr(self, name, a) return a + # The underlying __enter__ method returns the wrong object + # (self.file) so override it to return the wrapper + def __enter__(self): + self.file.__enter__() + return self + # NT provides delete-on-close as a primitive, so we don't need # the wrapper to do anything special. We still use it so that # file.name is useful (i.e. not "(fdopen)") with NamedTemporaryFile. if _os.name != 'nt': + # Cache the unlinker so we don't get spurious errors at + # shutdown when the module-level "os" is None'd out. Note + # that this must be referenced as self.unlink, because the + # name TemporaryFileWrapper may also get None'd out before + # __del__ is called. + unlink = _os.unlink def close(self): if not self.close_called: @@ -411,6 +413,14 @@ def __del__(self): self.close() + # Need to trap __exit__ as well to ensure the file gets + # deleted when used in a with statement + def __exit__(self, exc, value, tb): + result = self.file.__exit__(exc, value, tb) + self.close() + return result + + def NamedTemporaryFile(mode='w+b', bufsize=-1, suffix="", prefix=template, dir=None): """Create and return a temporary file. Modified: trunk/jython/Lib/test/test_tempfile.py =================================================================== --- trunk/jython/Lib/test/test_tempfile.py 2009-05-12 01:51:08 UTC (rev 6344) +++ trunk/jython/Lib/test/test_tempfile.py 2009-05-13 02:48:53 UTC (rev 6345) @@ -1,6 +1,5 @@ -# From Python 2.5.1 # tempfile.py unit tests. - +from __future__ import with_statement import tempfile import os import sys @@ -208,32 +207,21 @@ class mkstemped: _bflags = tempfile._bin_openflags _tflags = tempfile._text_openflags + _close = os.close + _unlink = os.unlink def __init__(self, dir, pre, suf, bin): if bin: flags = self._bflags else: flags = self._tflags - # XXX: CPython assigns _close/_unlink as class vars but this - # would rebind Jython's close/unlink (to be classmethods) - # because they're not built-in functions (unfortunately - # built-in functions act differently when binding: - # http://mail.python.org/pipermail/python-dev/2003-April/034749.html) - self._close = os.close - self._unlink = os.unlink (self.fd, self.name) = tempfile._mkstemp_inner(dir, pre, suf, flags) def write(self, str): os.write(self.fd, str) - # XXX: self.test_choose_directory expects the file to have been deleted - # (via __del__) by the time it's called, which is CPython specific - # garbage collection behavior. We need to delete it now in Jython - self._close(self.fd) - self._unlink(self.name) def __del__(self): self._close(self.fd) - if os.path.exists(self.name): - self._unlink(self.name) + self._unlink(self.name) def do_create(self, dir=None, pre="", suf="", bin=1): if dir is None: @@ -259,10 +247,6 @@ extant = range(TEST_FILES) for i in extant: extant[i] = self.do_create(pre="aa") - # XXX: Ensure mkstemped files are deleted (can't rely on Java's - # GC) - for i in extant: - i.__del__() def test_choose_directory(self): # _mkstemp_inner can create files in a user-selected directory @@ -272,8 +256,7 @@ finally: os.rmdir(dir) - # XXX: Jython can't set the write mode yet - def _test_file_mode(self): + def test_file_mode(self): # _mkstemp_inner creates files with the proper mode if not has_stat: return # ugh, can't use TestSkipped. @@ -315,7 +298,7 @@ # On Windows a spawn* /path/ with embedded spaces shouldn't be quoted, # but an arg with embedded spaces should be decorated with double # quotes on each end - if sys.platform in ('win32'): + if sys.platform in ('win32',): decorated = '"%s"' % sys.executable tester = '"%s"' % tester else: @@ -494,9 +477,6 @@ # mkdtemp creates directories with the proper mode if not has_stat: return # ugh, can't use TestSkipped. - if os.name == 'java': - # Java doesn't support stating files for permissions - return dir = self.do_create() try: @@ -529,25 +509,18 @@ self.dir = None class mktemped: + _unlink = os.unlink _bflags = tempfile._bin_openflags def __init__(self, dir, pre, suf): - # XXX: Assign _unlink here, instead of as a class var. See - # mkstemped.__init__ for an explanation - self._unlink = os.unlink - self.name = tempfile.mktemp(dir=dir, prefix=pre, suffix=suf) # Create the file. This will raise an exception if it's # mysteriously appeared in the meanwhile. os.close(os.open(self.name, self._bflags, 0600)) - # XXX: test_mktemp.tearDown expects the file to have been deleted - # (via __del__) by the time it's called, which is CPython specific - # garbage collection behavior. We need to delete it now in Jython + + def __del__(self): self._unlink(self.name) - #def __del__(self): - # self._unlink(self.name) - def do_create(self, pre="", suf=""): try: file = self.mktemped(self.dir, pre, suf) @@ -628,7 +601,6 @@ def test_multiple_close(self): # A NamedTemporaryFile can be closed many times without error - f = tempfile.NamedTemporaryFile() f.write('abc\n') f.close() @@ -638,6 +610,16 @@ except: self.failOnException("close") + def test_context_manager(self): + # A NamedTemporaryFile can be used as a context manager + with tempfile.NamedTemporaryFile() as f: + self.failUnless(os.path.exists(f.name)) + self.failIf(os.path.exists(f.name)) + def use_closed(): + with f: + pass + self.failUnlessRaises(ValueError, use_closed) + # How to test the mode and bufsize parameters? test_classes.append(test_NamedTemporaryFile) @@ -693,7 +675,3 @@ if __name__ == "__main__": test_main() - # XXX: Nudge Java's GC in an attempt to trigger any temp file's - # __del__ (cause them to be deleted) that hasn't been called - from java.lang import System - System.gc() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |