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...> - 2010-05-25 05:40:21
|
Revision: 7058 http://jython.svn.sourceforge.net/jython/?rev=7058&view=rev Author: otmarhumbel Date: 2010-05-25 05:40:14 +0000 (Tue, 25 May 2010) Log Message: ----------- add missing quotes around sys.executable Modified Paths: -------------- trunk/jython/Lib/test/test_bat_jy.py Modified: trunk/jython/Lib/test/test_bat_jy.py =================================================================== --- trunk/jython/Lib/test/test_bat_jy.py 2010-05-17 22:38:50 UTC (rev 7057) +++ trunk/jython/Lib/test/test_bat_jy.py 2010-05-25 05:40:14 UTC (rev 7058) @@ -130,7 +130,7 @@ return home def assertOutput(self, flags=None, javaHome=None, jythonHome=None, jythonOpts=None): - args = [sys.executable, '--print'] + args = [self.quote(sys.executable), '--print'] memory = None stack = None prop = None This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <otm...@us...> - 2010-05-17 22:38:57
|
Revision: 7057 http://jython.svn.sourceforge.net/jython/?rev=7057&view=rev Author: otmarhumbel Date: 2010-05-17 22:38:50 +0000 (Mon, 17 May 2010) Log Message: ----------- increase test coverage Modified Paths: -------------- trunk/jython/Lib/test/test_bat_jy.py Modified: trunk/jython/Lib/test/test_bat_jy.py =================================================================== --- trunk/jython/Lib/test/test_bat_jy.py 2010-04-30 17:06:38 UTC (rev 7056) +++ trunk/jython/Lib/test/test_bat_jy.py 2010-05-17 22:38:50 UTC (rev 7057) @@ -6,7 +6,6 @@ import tempfile from test import test_support -from subprocess import Popen, PIPE from java.lang import IllegalThreadStateException from java.lang import Runtime @@ -47,34 +46,67 @@ def getStream(self): return self.process.getErrorStream() -class SimpleSubprocess: - def __init__(self, args): - self.args = args - self.exitValue = -999 +class StarterProcess: + def writeStarter(self, args, javaHome, jythonHome, jythonOpts): + (starter, starterPath) = tempfile.mkstemp(suffix='.bat', prefix='starter', text=True) + starter.close() + outfilePath = starterPath[:-4] + '.out' + starter = open(starterPath, 'w') # open starter as simple file + try: + if javaHome: + starter.write('set JAVA_HOME=%s\n' % javaHome) + if jythonHome: + starter.write('set JYTHON_HOME=%s\n' % jythonHome) + if jythonOpts: + starter.write('set JYTHON_OPTS=%s\n' % jythonOpts) + starter.write(self.buildCommand(args, outfilePath)) + return (starterPath, outfilePath) + finally: + starter.close() - def run(self): - self.process = Runtime.getRuntime().exec(self.args) - self.stdoutMonitor = StdoutMonitor(self.process) - self.stderrMonitor = StderrMonitor(self.process) - self.stdoutMonitor.start() - self.stderrMonitor.start() - while self.isAlive(): - Thread.sleep(1000) - return self.exitValue + def buildCommand(self, args, outfilePath): + line = '' + for arg in args: + line += arg + line += ' ' + line += '> ' + line += outfilePath + line += ' 2>&1' + return line - def getStdout(self): - return self.stdoutMonitor.getOutput() + def getOutput(self, outfilePath): + lines = '' + outfile = open(outfilePath, 'r') + try: + for line in outfile.readlines(): + lines += line + finally: + outfile.close() + return lines - def getStderr(self): - return self.stderrMonitor.getOutput() - - def isAlive(self): + def isAlive(self, process): try: - self.exitValue = self.process.exitValue() + process.exitValue() return False except IllegalThreadStateException: return True + def run(self, args, javaHome, jythonHome, jythonOpts): + ''' creates a start script, executes it and captures the output ''' + (starterPath, outfilePath) = self.writeStarter(args, javaHome, jythonHome, jythonOpts) + try: + process = Runtime.getRuntime().exec(starterPath) + stdoutMonitor = StdoutMonitor(process) + stderrMonitor = StderrMonitor(process) + stdoutMonitor.start() + stderrMonitor.start() + while self.isAlive(process): + Thread.sleep(500) + return self.getOutput(outfilePath) + finally: + os.remove(starterPath) + os.remove(outfilePath) + class BaseTest(unittest.TestCase): def quote(self, s): return '"' + s + '"' @@ -97,12 +129,6 @@ home = ex[:-11] # \jython.bat return home - def copyOsEnviron(self): - theCopy = {} - for key in os.environ.keys(): - theCopy[key] = os.environ[key] - return theCopy - def assertOutput(self, flags=None, javaHome=None, jythonHome=None, jythonOpts=None): args = [sys.executable, '--print'] memory = None @@ -132,27 +158,8 @@ else: jythonArgs = flag args.append(flag) - environ = None - if javaHome or jythonHome or jythonOpts: - environ = self.copyOsEnviron() # copy to prevent os.environ from being changed - if javaHome: - environ['JAVA_HOME'] = javaHome - if jythonHome: - environ['JYTHON_HOME'] = jythonHome - if jythonOpts: - environ['JYTHON_OPTS'] = jythonOpts - if environ: - # env changes can only be handled by Popen - process = Popen(args, stdout=PIPE, stderr=PIPE, env=environ) - out = process.stdout.read() - err = process.stderr.read() - else: - # since Popen escapes double quotes, we use a simple subprocess if no env changes are needed - simpleProcess = SimpleSubprocess(args) - simpleProcess.run() - out = simpleProcess.getStdout() - err = simpleProcess.getStderr() - self.assertEquals('', err) + process = StarterProcess() + out = process.run(args, javaHome, jythonHome, jythonOpts) self.assertNotEquals('', out) homeIdx = out.find('-Dpython.home=') java = 'java' @@ -275,21 +282,8 @@ def test_combined(self): self.assertOutput(['-W', 'action', 'line']) - # something adds double quotes, but in real life this works: - # jython.bat --print -c 'import sys;' def test_singlequoted(self): - args = [sys.executable] - args.append('--print') - args.append('-c') - args.append("'import sys;'") - simpleProcess = SimpleSubprocess(args) - simpleProcess.run() - out = simpleProcess.getStdout() - err = simpleProcess.getStderr() - self.assertEquals('', err) - self.assertNotEquals('', out) - tail = out[-19:] - self.assertEquals('-c "\'import sys;\'" ', tail) + self.assertOutput(['-c', "'import sys;'"]) def test_doublequoted(self): self.assertOutput(['-c', '"print \'something\'"']) @@ -323,6 +317,9 @@ def test_main(): if os._name == 'nt': test_support.run_unittest(VanillaTest, + JavaHomeTest, + JythonHomeTest, + JythonOptsTest, JavaOptsTest, ArgsTest, DoubleDashTest) @@ -333,4 +330,4 @@ if __name__ == '__main__': test_main() - \ No newline at end of file + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <am...@us...> - 2010-04-30 17:06:44
|
Revision: 7056 http://jython.svn.sourceforge.net/jython/?rev=7056&view=rev Author: amak Date: 2010-04-30 17:06:38 +0000 (Fri, 30 Apr 2010) Log Message: ----------- Updating the NEWS file with some bugs that I fixed but forgot to record. Modified Paths: -------------- trunk/jython/NEWS Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2010-04-29 16:16:46 UTC (rev 7055) +++ trunk/jython/NEWS 2010-04-30 17:06:38 UTC (rev 7056) @@ -5,7 +5,15 @@ - [ 1586 ] weakref reference count leak when kwargs are used - [ 1601 ] Can't serialize PyCode object - [ 1551 ] Java objects cannot be copied by the copy module + - [ 1375 ] XML SAX: attrs.get((None, 'attr')) gives NPE + - [ 1488 ] sax JyInputSourceWrapper does not support unicode strings + - [ 1510 ] minidom is not parsing comment information correctly + - [ 1549 ] Wrapping an InputStream with a PyFile wrongly carries out line-ending translation. - [ 1583 ] xml.dom.Node.data returns bytestrings of decoded unicode + - [ 1515 ] modjy sometimes adds None to the sys.path + - [ 1507 ] modjy crashes if any query string parameters are not set with '=' + - [ 1473 ] modjy servlet doesn't import site-packages by default + - [ 1474 ] modjy servlet doesn't call atexit handlers - [ 1225 ] socket.getservbyname/port() not yet supported - [ 1532 ] Cannot use docstring when defining class - [ 1530 ] BoolOp in multiple assign causes VerifyError This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <otm...@us...> - 2010-04-29 16:16:56
|
Revision: 7055 http://jython.svn.sourceforge.net/jython/?rev=7055&view=rev Author: otmarhumbel Date: 2010-04-29 16:16:46 +0000 (Thu, 29 Apr 2010) Log Message: ----------- activate more windows tests Modified Paths: -------------- trunk/jython/Lib/test/test_bat_jy.py Modified: trunk/jython/Lib/test/test_bat_jy.py =================================================================== --- trunk/jython/Lib/test/test_bat_jy.py 2010-04-29 14:26:03 UTC (rev 7054) +++ trunk/jython/Lib/test/test_bat_jy.py 2010-04-29 16:16:46 UTC (rev 7055) @@ -322,7 +322,10 @@ def test_main(): if os._name == 'nt': - test_support.run_unittest(VanillaTest) + test_support.run_unittest(VanillaTest, + JavaOptsTest, + ArgsTest, + DoubleDashTest) else: # provide at least one test for the other platforms - happier build bots test_support.run_unittest(DummyTest) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <otm...@us...> - 2010-04-29 14:26:09
|
Revision: 7054 http://jython.svn.sourceforge.net/jython/?rev=7054&view=rev Author: otmarhumbel Date: 2010-04-29 14:26:03 +0000 (Thu, 29 Apr 2010) Log Message: ----------- reintroduce the simplest test on windows Modified Paths: -------------- trunk/jython/Lib/test/test_bat_jy.py Modified: trunk/jython/Lib/test/test_bat_jy.py =================================================================== --- trunk/jython/Lib/test/test_bat_jy.py 2010-04-29 00:06:48 UTC (rev 7053) +++ trunk/jython/Lib/test/test_bat_jy.py 2010-04-29 14:26:03 UTC (rev 7054) @@ -321,7 +321,11 @@ pass def test_main(): - test_support.run_unittest(DummyTest) + if os._name == 'nt': + test_support.run_unittest(VanillaTest) + else: + # provide at least one test for the other platforms - happier build bots + test_support.run_unittest(DummyTest) if __name__ == '__main__': This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <otm...@us...> - 2010-04-29 00:06:54
|
Revision: 7053 http://jython.svn.sourceforge.net/jython/?rev=7053&view=rev Author: otmarhumbel Date: 2010-04-29 00:06:48 +0000 (Thu, 29 Apr 2010) Log Message: ----------- this test should do no harm any more Modified Paths: -------------- trunk/jython/Lib/test/test_bat_jy.py Modified: trunk/jython/Lib/test/test_bat_jy.py =================================================================== --- trunk/jython/Lib/test/test_bat_jy.py 2010-04-28 23:16:27 UTC (rev 7052) +++ trunk/jython/Lib/test/test_bat_jy.py 2010-04-29 00:06:48 UTC (rev 7053) @@ -316,18 +316,14 @@ def test_jdb(self): self.assertOutput(['--jdb']) +class DummyTest(unittest.TestCase): + def test_nothing(self): + pass + def test_main(): - test_support.run_unittest( - VanillaTest, - JavaHomeTest, - JythonHomeTest, - JythonOptsTest, - JavaOptsTest, - ArgsTest, - DoubleDashTest) + test_support.run_unittest(DummyTest) if __name__ == '__main__': - # these tests currently only make sense on windows - if os._name == 'nt': - test_main() + test_main() + \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <otm...@us...> - 2010-04-28 23:16:33
|
Revision: 7052 http://jython.svn.sourceforge.net/jython/?rev=7052&view=rev Author: otmarhumbel Date: 2010-04-28 23:16:27 +0000 (Wed, 28 Apr 2010) Log Message: ----------- add test cases for most of the use cases of jython.bat Modified Paths: -------------- trunk/jython/src/shell/jython.bat Added Paths: ----------- trunk/jython/Lib/test/test_bat_jy.py Added: trunk/jython/Lib/test/test_bat_jy.py =================================================================== --- trunk/jython/Lib/test/test_bat_jy.py (rev 0) +++ trunk/jython/Lib/test/test_bat_jy.py 2010-04-28 23:16:27 UTC (rev 7052) @@ -0,0 +1,333 @@ +'''Tests jython.bat using the --print option''' + +import os +import sys +import unittest +import tempfile + +from test import test_support +from subprocess import Popen, PIPE + +from java.lang import IllegalThreadStateException +from java.lang import Runtime +from java.lang import Thread +from java.io import File +from java.io import BufferedReader; +from java.io import InputStreamReader; + +class Monitor(Thread): + def __init__(self, process): + self.process = process + self.output = '' + + def run(self): + reader = BufferedReader(InputStreamReader(self.getStream())) + try: + line = reader.readLine() + while line: + self.output += line + line = reader.readLine() + finally: + reader.close() + + def getOutput(self): + return self.output + +class StdoutMonitor(Monitor): + def __init_(self, process): + Monitor.__init__(self, process) + + def getStream(self): + return self.process.getInputStream() + +class StderrMonitor(Monitor): + def __init_(self, process): + Monitor.__init__(self, process) + + def getStream(self): + return self.process.getErrorStream() + +class SimpleSubprocess: + def __init__(self, args): + self.args = args + self.exitValue = -999 + + def run(self): + self.process = Runtime.getRuntime().exec(self.args) + self.stdoutMonitor = StdoutMonitor(self.process) + self.stderrMonitor = StderrMonitor(self.process) + self.stdoutMonitor.start() + self.stderrMonitor.start() + while self.isAlive(): + Thread.sleep(1000) + return self.exitValue + + def getStdout(self): + return self.stdoutMonitor.getOutput() + + def getStderr(self): + return self.stderrMonitor.getOutput() + + def isAlive(self): + try: + self.exitValue = self.process.exitValue() + return False + except IllegalThreadStateException: + return True + +class BaseTest(unittest.TestCase): + def quote(self, s): + return '"' + s + '"' + + def unquote(self, s): + if len(s) > 0: + if s[:1] == '"': + s = s[1:] + if len(s) > 0: + if s[-1:] == '"': + s = s[:-1] + return s + + def getHomeDir(self): + ex = sys.executable + tail = ex[-15:] + if tail == '\\bin\\jython.bat': + home = ex[:-15] + else: + home = ex[:-11] # \jython.bat + return home + + def copyOsEnviron(self): + theCopy = {} + for key in os.environ.keys(): + theCopy[key] = os.environ[key] + return theCopy + + def assertOutput(self, flags=None, javaHome=None, jythonHome=None, jythonOpts=None): + args = [sys.executable, '--print'] + memory = None + stack = None + prop = None + jythonArgs = None + boot = False + jdb = False + if flags: + for flag in flags: + if flag[:2] == '-J': + if flag[2:6] == '-Xmx': + memory = flag[6:] + elif flag[2:6] == '-Xss': + stack = flag[6:] + elif flag[2:4] == '-D': + prop = flag[2:] + elif flag[:2] == '--': + if flag[2:6] == 'boot': + boot = True + elif flag[2:5] == 'jdb': + jdb = True + else: + if jythonArgs: + jythonArgs += ' ' + jythonArgs += flag + else: + jythonArgs = flag + args.append(flag) + environ = None + if javaHome or jythonHome or jythonOpts: + environ = self.copyOsEnviron() # copy to prevent os.environ from being changed + if javaHome: + environ['JAVA_HOME'] = javaHome + if jythonHome: + environ['JYTHON_HOME'] = jythonHome + if jythonOpts: + environ['JYTHON_OPTS'] = jythonOpts + if environ: + # env changes can only be handled by Popen + process = Popen(args, stdout=PIPE, stderr=PIPE, env=environ) + out = process.stdout.read() + err = process.stderr.read() + else: + # since Popen escapes double quotes, we use a simple subprocess if no env changes are needed + simpleProcess = SimpleSubprocess(args) + simpleProcess.run() + out = simpleProcess.getStdout() + err = simpleProcess.getStderr() + self.assertEquals('', err) + self.assertNotEquals('', out) + homeIdx = out.find('-Dpython.home=') + java = 'java' + if javaHome: + java = self.quote(self.unquote(javaHome) + '\\bin\\java') + elif jdb: + java = 'jdb' + if not memory: + memory = '512m' + if not stack: + stack = '1152k' + beginning = java + ' ' + if prop: + beginning += ' ' + prop + beginning += ' -Xmx' + memory + ' -Xss' + stack + ' ' + self.assertEquals(beginning, out[:homeIdx]) + executableIdx = out.find('-Dpython.executable=') + homeDir = self.getHomeDir() + if jythonHome: + homeDir = self.unquote(jythonHome) + home = '-Dpython.home=' + self.quote(homeDir) + ' ' + self.assertEquals(home, out[homeIdx:executableIdx]) + if boot: + classpathFlag = '-Xbootclasspath/a:' + else: + classpathFlag = '-classpath' + classpathIdx = out.find(classpathFlag) + executable = '-Dpython.executable=' + self.quote(sys.executable) + ' ' + if not boot: + executable += ' ' + self.assertEquals(executable, out[executableIdx:classpathIdx]) + # ignore full contents of classpath at the moment + classIdx = out.find('org.python.util.jython') + self.assertTrue(classIdx > classpathIdx) + restIdx = classIdx + len('org.python.util.jython') + rest = out[restIdx:].strip() + if jythonOpts: + self.assertEquals(self.quote(jythonOpts), rest) + else: + if jythonArgs: + self.assertEquals(jythonArgs, rest) + else: + self.assertEquals('', rest) + +class VanillaTest(BaseTest): + def test_plain(self): + self.assertOutput() + +class JavaHomeTest(BaseTest): + def test_unquoted(self): + self.assertOutput(javaHome='C:\\Program Files\\Java\\someJava') + + def test_quoted(self): + self.assertOutput(javaHome=self.quote('C:\\Program Files\\Java\\someJava')) + + # this currently fails, meaning we accept only quoted (x86) homes ... + def __test_x86_unquoted(self): + self.assertOutput(javaHome='C:\\Program Files (x86)\\Java\\someJava') + + def test_x86_quoted(self): + self.assertOutput(javaHome=self.quote('C:\\Program Files (x86)\\Java\\someJava')) + +class JythonHomeTest(BaseTest): + def createJythonJar(self, parentDir): + jar = File(parentDir, 'jython.jar') + if not jar.exists(): + self.assertTrue(jar.createNewFile()) + return jar + + def cleanup(self, tmpdir, jar=None): + if jar and jar.exists(): + self.assertTrue(jar.delete()) + os.rmdir(tmpdir) + + def test_unquoted(self): + jythonHomeDir = tempfile.mkdtemp() + jar = self.createJythonJar(jythonHomeDir) + self.assertOutput(jythonHome=jythonHomeDir) + self.cleanup(jythonHomeDir, jar) + + def test_quoted(self): + jythonHomeDir = tempfile.mkdtemp() + jar = self.createJythonJar(jythonHomeDir) + self.assertOutput(jythonHome=self.quote(jythonHomeDir)) + self.cleanup(jythonHomeDir, jar) + +class JythonOptsTest(BaseTest): + def test_single(self): + self.assertOutput(jythonOpts='myOpt') + + def test_multiple(self): + self.assertOutput(jythonOpts='some arbitrary options') + +class JavaOptsTest(BaseTest): + def test_memory(self): + self.assertOutput(['-J-Xmx321m']) + + def test_stack(self): + self.assertOutput(['-J-Xss321k']) + + def test_property(self): + self.assertOutput(['-J-DmyProperty=myValue']) + + def test_property_singlequote(self): + self.assertOutput(["-J-DmyProperty='myValue'"]) # a space inside value does not work in jython.bat + + def test_property_doublequote(self): + self.assertOutput(['-J-DmyProperty="myValue"']) # a space inside value does not work in jython.bat + + def test_property_underscore(self): + self.assertOutput(['-J-Dmy_Property=my_Value']) + +class ArgsTest(BaseTest): + def test_file(self): + self.assertOutput(['test.py']) + + def test_dash(self): + self.assertOutput(['-i']) + + def test_combined(self): + self.assertOutput(['-W', 'action', 'line']) + + # something adds double quotes, but in real life this works: + # jython.bat --print -c 'import sys;' + def test_singlequoted(self): + args = [sys.executable] + args.append('--print') + args.append('-c') + args.append("'import sys;'") + simpleProcess = SimpleSubprocess(args) + simpleProcess.run() + out = simpleProcess.getStdout() + err = simpleProcess.getStderr() + self.assertEquals('', err) + self.assertNotEquals('', out) + tail = out[-19:] + self.assertEquals('-c "\'import sys;\'" ', tail) + + def test_doublequoted(self): + self.assertOutput(['-c', '"print \'something\'"']) + + def test_underscored(self): + self.assertOutput(['-jar', 'my_stuff.jar']) + + def test_property(self): + self.assertOutput(['-DmyProperty=myValue']) + + def test_property_underscored(self): + self.assertOutput(['-DmyProperty=my_Value']) + + def test_property_singlequoted(self): + self.assertOutput(["-DmyProperty='my_Value'"]) + + def test_property_doublequoted(self): + self.assertOutput(['-DmyProperty="my_Value"']) + +class DoubleDashTest(BaseTest): + def test_boot(self): + self.assertOutput(['--boot']) + + def test_jdb(self): + self.assertOutput(['--jdb']) + +def test_main(): + test_support.run_unittest( + VanillaTest, + JavaHomeTest, + JythonHomeTest, + JythonOptsTest, + JavaOptsTest, + ArgsTest, + DoubleDashTest) + + +if __name__ == '__main__': + # these tests currently only make sense on windows + if os._name == 'nt': + test_main() Modified: trunk/jython/src/shell/jython.bat =================================================================== --- trunk/jython/src/shell/jython.bat 2010-04-27 06:07:08 UTC (rev 7051) +++ trunk/jython/src/shell/jython.bat 2010-04-28 23:16:27 UTC (rev 7052) @@ -183,7 +183,7 @@ set CLASSPATH=%_CP:"=%;%CLASSPATH:"=% :fullCmd -set _FULL_CMD=%_JAVA_CMD% %_JAVA_OPTS% %_JAVA_MEM% %_JAVA_STACK% %_BOOT_CP% -Dpython.home=%_JYTHON_HOME% -Dpython.executable="%~f0" -classpath "%CLASSPATH%" org.python.util.jython %_JYTHON_OPTS% %_JYTHON_ARGS% %_ARGS% +set _FULL_CMD=%_JAVA_CMD% %_JAVA_OPTS% %_JAVA_MEM% %_JAVA_STACK% -Dpython.home=%_JYTHON_HOME% -Dpython.executable="%~f0" %_BOOT_CP% -classpath "%CLASSPATH%" org.python.util.jython %_JYTHON_OPTS% %_JYTHON_ARGS% %_ARGS% if defined _PRINT ( echo %_FULL_CMD% ) else ( This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2010-04-27 06:07:14
|
Revision: 7051 http://jython.svn.sourceforge.net/jython/?rev=7051&view=rev Author: zyasoft Date: 2010-04-27 06:07:08 +0000 (Tue, 27 Apr 2010) Log Message: ----------- Now nulls the ref to the args array for #1586 instead of clearing the array, so callee code has no copy responsibility (Phil Jenvey's suggestion). Backed out change to thread.PyLocal accordingly in r7047. Bumped bytecode magic. Modified Paths: -------------- trunk/jython/src/org/python/compiler/CodeCompiler.java trunk/jython/src/org/python/core/imp.java trunk/jython/src/org/python/modules/thread/PyLocal.java Modified: trunk/jython/src/org/python/compiler/CodeCompiler.java =================================================================== --- trunk/jython/src/org/python/compiler/CodeCompiler.java 2010-04-26 18:39:57 UTC (rev 7050) +++ trunk/jython/src/org/python/compiler/CodeCompiler.java 2010-04-27 06:07:08 UTC (rev 7051) @@ -413,6 +413,12 @@ code.freeLocal(array); } + public void freeArrayRef(int array) { + code.aconst_null(); + code.astore(array); + code.freeLocal(array); + } + public Str getDocStr(java.util.List<stmt> suite) { if (suite.size() > 0) { stmt stmt = suite.get(0); @@ -1811,7 +1817,7 @@ stackConsume(3); // target + starargs + kwargs code.invokevirtual(p(PyObject.class), "_callextra", sig(PyObject.class, PyObject[].class, String[].class, PyObject.class, PyObject.class)); - freeArray(argArray); + freeArrayRef(argArray); } else if (keys.size() > 0) { loadThreadState(); stackProduce(p(ThreadState.class)); @@ -1823,7 +1829,7 @@ stackConsume(2); // target + ts code.invokevirtual(p(PyObject.class), "__call__", sig(PyObject.class, ThreadState.class, PyObject[].class, String[].class)); - freeArray(argArray); + freeArrayRef(argArray); } else { loadThreadState(); stackProduce(p(ThreadState.class)); Modified: trunk/jython/src/org/python/core/imp.java =================================================================== --- trunk/jython/src/org/python/core/imp.java 2010-04-26 18:39:57 UTC (rev 7050) +++ trunk/jython/src/org/python/core/imp.java 2010-04-27 06:07:08 UTC (rev 7051) @@ -21,7 +21,7 @@ private static final String UNKNOWN_SOURCEFILE = "<unknown>"; - private static final int APIVersion = 29; + private static final int APIVersion = 30; public static final int NO_MTIME = -1; Modified: trunk/jython/src/org/python/modules/thread/PyLocal.java =================================================================== --- trunk/jython/src/org/python/modules/thread/PyLocal.java 2010-04-26 18:39:57 UTC (rev 7050) +++ trunk/jython/src/org/python/modules/thread/PyLocal.java 2010-04-27 06:07:08 UTC (rev 7051) @@ -59,9 +59,7 @@ if (where[0] == TYPE && args.length > 0) { throw Py.TypeError("Initialization arguments are not supported"); } - // caller zeros out `args` - this.args = new PyObject[args.length]; - System.arraycopy(args, 0, this.args, 0, args.length); + this.args = args; this.keywords = keywords; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: Philip J. <pj...@un...> - 2010-04-27 03:47:14
|
On Apr 26, 2010, at 7:27 AM, zy...@us... wrote: > Revision: 7047 > http://jython.svn.sourceforge.net/jython/?rev=7047&view=rev > Author: zyasoft > Date: 2010-04-26 14:27:38 +0000 (Mon, 26 Apr 2010) > > Log Message: > ----------- > Fixed weakref leak in calling functions with kwargs by nulling out after call (in compiler). Fixes #1586. Bumped bytecode magic > > Modified Paths: > -------------- > trunk/jython/Lib/test/test_weakref_jy.py > trunk/jython/src/org/python/compiler/CodeCompiler.java > trunk/jython/src/org/python/core/imp.java > trunk/jython/src/org/python/modules/thread/PyLocal.java > > Modified: trunk/jython/src/org/python/modules/thread/PyLocal.java > =================================================================== > --- trunk/jython/src/org/python/modules/thread/PyLocal.java 2010-04-25 18:33:34 UTC (rev 7046) > +++ trunk/jython/src/org/python/modules/thread/PyLocal.java 2010-04-26 14:27:38 UTC (rev 7047) > @@ -59,7 +59,9 @@ > if (where[0] == TYPE && args.length > 0) { > throw Py.TypeError("Initialization arguments are not supported"); > } > - this.args = args; > + // caller zeros out `args` > + this.args = new PyObject[args.length]; > + System.arraycopy(args, 0, this.args, 0, args.length); > this.keywords = keywords; > } This this can affect any class that saves args for later, like _functools.partial (and I think there's others), right? Can we have the compiler just null its reference to the array instead of zero'ing it, and avoid the need for copying? -- Philip Jenvey |
From: <zy...@us...> - 2010-04-26 18:40:03
|
Revision: 7050 http://jython.svn.sourceforge.net/jython/?rev=7050&view=rev Author: zyasoft Date: 2010-04-26 18:39:57 +0000 (Mon, 26 Apr 2010) Log Message: ----------- Updated NEWS Modified Paths: -------------- trunk/jython/NEWS Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2010-04-26 18:24:42 UTC (rev 7049) +++ trunk/jython/NEWS 2010-04-26 18:39:57 UTC (rev 7050) @@ -2,6 +2,9 @@ Jython 2.5.2a1 Bugs Fixed + - [ 1586 ] weakref reference count leak when kwargs are used + - [ 1601 ] Can't serialize PyCode object + - [ 1551 ] Java objects cannot be copied by the copy module - [ 1583 ] xml.dom.Node.data returns bytestrings of decoded unicode - [ 1225 ] socket.getservbyname/port() not yet supported - [ 1532 ] Cannot use docstring when defining class This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2010-04-26 18:24:50
|
Revision: 7049 http://jython.svn.sourceforge.net/jython/?rev=7049&view=rev Author: zyasoft Date: 2010-04-26 18:24:42 +0000 (Mon, 26 Apr 2010) Log Message: ----------- Actual fix for missing synchronized on PyObject#getJavaProxy (missed checkin) Modified Paths: -------------- trunk/jython/src/org/python/core/PyObject.java Modified: trunk/jython/src/org/python/core/PyObject.java =================================================================== --- trunk/jython/src/org/python/core/PyObject.java 2010-04-26 18:16:08 UTC (rev 7048) +++ trunk/jython/src/org/python/core/PyObject.java 2010-04-26 18:24:42 UTC (rev 7049) @@ -174,6 +174,7 @@ return new PyString(toString()); } + @Override public String toString() { return object_toString(); } @@ -220,6 +221,7 @@ return new PyInteger(hashCode()); } + @Override public int hashCode() { return object___hash__(); } @@ -234,6 +236,7 @@ * If overridden, it is the subclasses responsibility to ensure that * <code>a.equals(b) == true</code> iff <code>cmp(a,b) == 0</code> **/ + @Override public boolean equals(Object ob_other) { if(ob_other == this) { return true; @@ -291,7 +294,7 @@ return Py.NoConversion; } - protected Object getJavaProxy() { + protected synchronized Object getJavaProxy() { if (javaProxy == null) { proxyInit(); } @@ -1890,7 +1893,7 @@ // situations // XXX: This method isn't expensive but could (and maybe // should?) be optimized for worst case scenarios - return op == "+" && (t1 == PyString.TYPE || t1 == PyUnicode.TYPE) && + return (op == "+") && (t1 == PyString.TYPE || t1 == PyUnicode.TYPE) && (t2.isSubType(PyString.TYPE) || t2.isSubType(PyUnicode.TYPE)); } @@ -4116,6 +4119,7 @@ list = elements; } + @Override public int hashCode() { int x, y; int len = list.length; @@ -4129,6 +4133,7 @@ return x; } + @Override public boolean equals(Object o) { if (!(o instanceof PyIdentityTuple)) return false; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2010-04-26 18:16:14
|
Revision: 7048 http://jython.svn.sourceforge.net/jython/?rev=7048&view=rev Author: zyasoft Date: 2010-04-26 18:16:08 +0000 (Mon, 26 Apr 2010) Log Message: ----------- Fixed synchronization bugs on IdImpl#java_obj_id (issue #1602), PyObject#getJavaProxy Modified Paths: -------------- trunk/jython/src/org/python/core/IdImpl.java Modified: trunk/jython/src/org/python/core/IdImpl.java =================================================================== --- trunk/jython/src/org/python/core/IdImpl.java 2010-04-26 14:27:38 UTC (rev 7047) +++ trunk/jython/src/org/python/core/IdImpl.java 2010-04-26 18:16:08 UTC (rev 7048) @@ -14,6 +14,7 @@ private Map<WeakIdKey, Object> objHashcodeToPyId = Generic.map(); + @SuppressWarnings("element-type-mismatch") private void cleanup() { Object k; while ((k = idKeys.poll()) != null) { @@ -29,10 +30,12 @@ hashcode = System.identityHashCode(obj); } + @Override public int hashCode() { return hashcode; } + @Override public boolean equals(Object other) { Object obj = get(); if (obj != null) { @@ -82,7 +85,7 @@ return String.format("0x%x", id(o)); } - public long java_obj_id(Object o) { + public synchronized long java_obj_id(Object o) { Long cand = (Long)idMap.get(o); if (cand == null) { long new_id = ++sequentialId; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2010-04-26 14:27:44
|
Revision: 7047 http://jython.svn.sourceforge.net/jython/?rev=7047&view=rev Author: zyasoft Date: 2010-04-26 14:27:38 +0000 (Mon, 26 Apr 2010) Log Message: ----------- Fixed weakref leak in calling functions with kwargs by nulling out after call (in compiler). Fixes #1586. Bumped bytecode magic Modified Paths: -------------- trunk/jython/Lib/test/test_weakref_jy.py trunk/jython/src/org/python/compiler/CodeCompiler.java trunk/jython/src/org/python/core/imp.java trunk/jython/src/org/python/modules/thread/PyLocal.java Modified: trunk/jython/Lib/test/test_weakref_jy.py =================================================================== --- trunk/jython/Lib/test/test_weakref_jy.py 2010-04-25 18:33:34 UTC (rev 7046) +++ trunk/jython/Lib/test/test_weakref_jy.py 2010-04-26 14:27:38 UTC (rev 7047) @@ -5,6 +5,7 @@ import unittest import weakref from test import test_support +from test_weakref import extra_collect class ReferencesTestCase(unittest.TestCase): @@ -38,8 +39,45 @@ self.assertEqual(len(hash_called), 2) +class ArgsTestCase(unittest.TestCase): + + # XXX consider adding other tests for dict, list, etc + + def test_python_fn_kwargs(self): + + weakrefs = [] + sentinel = [] + + def watch(obj, kwarg=True): + self.assertEqual(kwarg, True) + # log the death of the reference by appending to the sentinel + ref = weakref.ref(obj, sentinel.append) + weakrefs.append(ref) + + self.assert_(not sentinel) + + thunk1 = lambda: None + watch(thunk1) + self.assert_(not sentinel) + + del thunk1 + extra_collect() + self.assert_(sentinel) + + del sentinel[:] + + thunk2 = lambda: None + watch(thunk2, kwarg=True) # <--- only difference: called with a kwarg + self.assert_(not sentinel) + + del thunk2 + extra_collect() + self.assert_(sentinel) + + + def test_main(): - test_support.run_unittest(ReferencesTestCase) + test_support.run_unittest(ReferencesTestCase, ArgsTestCase) if __name__ == '__main__': Modified: trunk/jython/src/org/python/compiler/CodeCompiler.java =================================================================== --- trunk/jython/src/org/python/compiler/CodeCompiler.java 2010-04-25 18:33:34 UTC (rev 7046) +++ trunk/jython/src/org/python/compiler/CodeCompiler.java 2010-04-26 14:27:38 UTC (rev 7047) @@ -1804,15 +1804,14 @@ code.aload(argArray); code.aload(strArray); - code.freeLocal(argArray); code.freeLocal(strArray); code.dup2_x2(); code.pop2(); stackConsume(3); // target + starargs + kwargs - code.invokevirtual(p(PyObject.class), "_callextra", sig(PyObject.class, PyObject[].class, String[].class, PyObject.class, PyObject.class)); + freeArray(argArray); } else if (keys.size() > 0) { loadThreadState(); stackProduce(p(ThreadState.class)); @@ -1820,11 +1819,11 @@ int strArray = makeStrings(code, keys); code.aload(argArray); code.aload(strArray); - code.freeLocal(argArray); code.freeLocal(strArray); stackConsume(2); // target + ts code.invokevirtual(p(PyObject.class), "__call__", sig(PyObject.class, ThreadState.class, PyObject[].class, String[].class)); + freeArray(argArray); } else { loadThreadState(); stackProduce(p(ThreadState.class)); Modified: trunk/jython/src/org/python/core/imp.java =================================================================== --- trunk/jython/src/org/python/core/imp.java 2010-04-25 18:33:34 UTC (rev 7046) +++ trunk/jython/src/org/python/core/imp.java 2010-04-26 14:27:38 UTC (rev 7047) @@ -21,7 +21,7 @@ private static final String UNKNOWN_SOURCEFILE = "<unknown>"; - private static final int APIVersion = 28; + private static final int APIVersion = 29; public static final int NO_MTIME = -1; Modified: trunk/jython/src/org/python/modules/thread/PyLocal.java =================================================================== --- trunk/jython/src/org/python/modules/thread/PyLocal.java 2010-04-25 18:33:34 UTC (rev 7046) +++ trunk/jython/src/org/python/modules/thread/PyLocal.java 2010-04-26 14:27:38 UTC (rev 7047) @@ -59,7 +59,9 @@ if (where[0] == TYPE && args.length > 0) { throw Py.TypeError("Initialization arguments are not supported"); } - this.args = args; + // caller zeros out `args` + this.args = new PyObject[args.length]; + System.arraycopy(args, 0, this.args, 0, args.length); this.keywords = keywords; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2010-04-25 18:33:40
|
Revision: 7046 http://jython.svn.sourceforge.net/jython/?rev=7046&view=rev Author: zyasoft Date: 2010-04-25 18:33:34 +0000 (Sun, 25 Apr 2010) Log Message: ----------- Remove leftover semicolons from translating Java to Python Modified Paths: -------------- trunk/jython/Lib/test/test_java_integration.py Modified: trunk/jython/Lib/test/test_java_integration.py =================================================================== --- trunk/jython/Lib/test/test_java_integration.py 2010-04-25 17:46:34 UTC (rev 7045) +++ trunk/jython/Lib/test/test_java_integration.py 2010-04-25 18:33:34 UTC (rev 7046) @@ -499,12 +499,11 @@ class CloneInput(ObjectInputStream): def __init__(self, input, output): - ObjectInputStream.__init__(self, input); - self.output = output; + ObjectInputStream.__init__(self, input) + self.output = output def resolveClass(self, obj_stream_class): - c = self.output.classQueue.popleft() - return c + return self.output.classQueue.popleft() def resolveProxyClass(self, interfaceNames): return self.output.classQueue.popleft() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2010-04-25 17:46:40
|
Revision: 7045 http://jython.svn.sourceforge.net/jython/?rev=7045&view=rev Author: zyasoft Date: 2010-04-25 17:46:34 +0000 (Sun, 25 Apr 2010) Log Message: ----------- Added support for __copy__, __deepcopy__ of Java objects (fixes #1551); and (somewhat) related serialization of PyCode objects (fixes #1601); some unit testing; bumped bytecode magic Modified Paths: -------------- trunk/jython/Lib/test/test_java_integration.py trunk/jython/src/org/python/core/CompilerFlags.java trunk/jython/src/org/python/core/PyFunctionTable.java trunk/jython/src/org/python/core/PyJavaType.java trunk/jython/src/org/python/core/imp.java Modified: trunk/jython/Lib/test/test_java_integration.py =================================================================== --- trunk/jython/Lib/test/test_java_integration.py 2010-04-24 17:30:40 UTC (rev 7044) +++ trunk/jython/Lib/test/test_java_integration.py 2010-04-25 17:46:34 UTC (rev 7045) @@ -1,3 +1,4 @@ +import copy import operator import os import unittest @@ -5,6 +6,7 @@ import sys import re +from collections import deque from test import test_support from java.lang import (ClassCastException, ExceptionInInitializerError, String, Runnable, System, @@ -469,19 +471,78 @@ self.assertRaises(TypeError, __import__, "org.python.tests.mro.ConfusedOnImport") self.assertRaises(TypeError, GetitemAdder.addPostdefined) + +def roundtrip_serialization(obj): + """Returns a deep copy of an object, via serializing it + + see http://weblogs.java.net/blog/emcmanus/archive/2007/04/cloning_java_ob.html + """ + output = ByteArrayOutputStream() + serializer = CloneOutput(output) + serializer.writeObject(obj) + serializer.close() + input = ByteArrayInputStream(output.toByteArray()) + unserializer = CloneInput(input, serializer) # to get the list of classes seen, in order + return unserializer.readObject() + +class CloneOutput(ObjectOutputStream): + def __init__(self, output): + ObjectOutputStream.__init__(self, output) + self.classQueue = deque() + + def annotateClass(self, c): + self.classQueue.append(c) + + def annotateProxyClass(self, c): + self.classQueue.append(c) + +class CloneInput(ObjectInputStream): + + def __init__(self, input, output): + ObjectInputStream.__init__(self, input); + self.output = output; + + def resolveClass(self, obj_stream_class): + c = self.output.classQueue.popleft() + return c + + def resolveProxyClass(self, interfaceNames): + return self.output.classQueue.popleft() + + class SerializationTest(unittest.TestCase): def test_java_serialization(self): date_list = [Date(), Date()] - output = ByteArrayOutputStream() - serializer = ObjectOutputStream(output) - serializer.writeObject(date_list) - serializer.close() + self.assertEqual(date_list, roundtrip_serialization(date_list)) - input = ByteArrayInputStream(output.toByteArray()) - unserializer = ObjectInputStream(input) - self.assertEqual(date_list, unserializer.readObject()) + def test_java_serialization_pycode(self): + def universal_answer(): + return 42 + + serialized_code = roundtrip_serialization(universal_answer.func_code) + self.assertEqual(eval(serialized_code), universal_answer()) + + +class CopyTest(unittest.TestCase): + + def test_copy(self): + fruits = ArrayList(["apple", "banana"]) + fruits_copy = copy.copy(fruits) + self.assertEqual(fruits, fruits_copy) + self.assertNotEqual(id(fruits), id(fruits_copy)) + + def test_deepcopy(self): + items = ArrayList([ArrayList(["apple", "banana"]), + ArrayList(["trs80", "vic20"])]) + items_copy = copy.deepcopy(items) + self.assertEqual(items, items_copy) + self.assertNotEqual(id(items), id(items_copy)) + self.assertNotEqual(id(items[0]), id(items_copy[0])) + self.assertNotEqual(id(items[1]), id(items_copy[1])) + + class UnicodeTest(unittest.TestCase): def test_unicode_conversion(self): @@ -505,6 +566,7 @@ SecurityManagerTest, JavaWrapperCustomizationTest, SerializationTest, + CopyTest, UnicodeTest) if __name__ == "__main__": Modified: trunk/jython/src/org/python/core/CompilerFlags.java =================================================================== --- trunk/jython/src/org/python/core/CompilerFlags.java 2010-04-24 17:30:40 UTC (rev 7044) +++ trunk/jython/src/org/python/core/CompilerFlags.java 2010-04-25 17:46:34 UTC (rev 7045) @@ -6,11 +6,12 @@ package org.python.core; +import java.io.Serializable; import java.util.Set; import org.python.Version; -public class CompilerFlags { +public class CompilerFlags implements Serializable { // These flags don't mean anything to the code, only to the compiler public static final int PyCF_SOURCE_IS_UTF8 = 0x0100; public static final int PyCF_DONT_IMPLY_DEDENT = 0x0200; Modified: trunk/jython/src/org/python/core/PyFunctionTable.java =================================================================== --- trunk/jython/src/org/python/core/PyFunctionTable.java 2010-04-24 17:30:40 UTC (rev 7044) +++ trunk/jython/src/org/python/core/PyFunctionTable.java 2010-04-25 17:46:34 UTC (rev 7045) @@ -1,6 +1,8 @@ // Copyright (c) Corporation for National Research Initiatives package org.python.core; +import java.io.Serializable; + /** * An entry point for class that implements several function calls. * <P> @@ -9,6 +11,6 @@ * @see PyTableCode */ -public abstract class PyFunctionTable { +public abstract class PyFunctionTable implements Serializable { abstract public PyObject call_function(int index, PyFrame frame, ThreadState ts); } Modified: trunk/jython/src/org/python/core/PyJavaType.java =================================================================== --- trunk/jython/src/org/python/core/PyJavaType.java 2010-04-24 17:30:40 UTC (rev 7044) +++ trunk/jython/src/org/python/core/PyJavaType.java 2010-04-25 17:46:34 UTC (rev 7045) @@ -1,5 +1,15 @@ package org.python.core; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InvalidClassException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.ObjectStreamClass; +import java.io.OutputStream; +import java.io.Serializable; import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Member; @@ -10,9 +20,11 @@ import java.util.Enumeration; import java.util.EventListener; import java.util.Iterator; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.Queue; import org.python.core.util.StringUtil; import org.python.util.Generic; @@ -578,8 +590,113 @@ } }); } + + // TODO consider adding support for __copy__ of immutable Java objects + // (__deepcopy__ should just work since it uses serialization) + + if(forClass == Cloneable.class) { + addMethod(new PyBuiltinMethodNarrow("__copy__") { + @Override + public PyObject __call__() { + Object obj = self.getJavaProxy(); + Method clone; + // we could specialize so that for well known objects like collections, + // we don't use reflection to get around the fact that Object#clone is protected (but most subclasses are not); + // also we can potentially cache the method handle in the proxy instead of looking it up each time + try { + clone = obj.getClass().getMethod("clone"); + Object copy; + copy = clone.invoke(obj); + return Py.java2py(copy); + } catch (Exception ex) { + throw Py.TypeError("Could not copy Java object"); + } + } + }); + } + + if(forClass == Serializable.class) { + addMethod(new PyBuiltinMethodNarrow("__deepcopy__") { + @Override + public PyObject __call__(PyObject memo) { + Object obj = self.getJavaProxy(); + try { + Object copy = cloneX(obj); + return Py.java2py(copy); + } catch (Exception ex) { + throw Py.TypeError("Could not copy Java object"); + } + } + }); + + } } + // cloneX, CloneOutput, CloneInput are verbatim from Eamonn McManus' + // http://weblogs.java.net/blog/emcmanus/archive/2007/04/cloning_java_ob.html + // blog post on deep cloning through serialization - + // just what we need for __deepcopy__ support of Java objects + + private static <T> T cloneX(T x) throws IOException, ClassNotFoundException { + ByteArrayOutputStream bout = new ByteArrayOutputStream(); + CloneOutput cout = new CloneOutput(bout); + cout.writeObject(x); + byte[] bytes = bout.toByteArray(); + + ByteArrayInputStream bin = new ByteArrayInputStream(bytes); + CloneInput cin = new CloneInput(bin, cout); + + @SuppressWarnings("unchecked") // thanks to Bas de Bakker for the tip! + T clone = (T) cin.readObject(); + return clone; + } + + private static class CloneOutput extends ObjectOutputStream { + Queue<Class<?>> classQueue = new LinkedList<Class<?>>(); + + CloneOutput(OutputStream out) throws IOException { + super(out); + } + + @Override + protected void annotateClass(Class<?> c) { + classQueue.add(c); + } + + @Override + protected void annotateProxyClass(Class<?> c) { + classQueue.add(c); + } + } + + private static class CloneInput extends ObjectInputStream { + private final CloneOutput output; + + CloneInput(InputStream in, CloneOutput output) throws IOException { + super(in); + this.output = output; + } + + @Override + protected Class<?> resolveClass(ObjectStreamClass osc) + throws IOException, ClassNotFoundException { + Class<?> c = output.classQueue.poll(); + String expected = osc.getName(); + String found = (c == null) ? null : c.getName(); + if (!expected.equals(found)) { + throw new InvalidClassException("Classes desynchronized: " + + "found " + found + " when expecting " + expected); + } + return c; + } + + @Override + protected Class<?> resolveProxyClass(String[] interfaceNames) + throws IOException, ClassNotFoundException { + return output.classQueue.poll(); + } + } + /** * Private, protected or package protected classes that implement public interfaces or extend * public classes can't have their implementations of the methods of their supertypes called Modified: trunk/jython/src/org/python/core/imp.java =================================================================== --- trunk/jython/src/org/python/core/imp.java 2010-04-24 17:30:40 UTC (rev 7044) +++ trunk/jython/src/org/python/core/imp.java 2010-04-25 17:46:34 UTC (rev 7045) @@ -21,7 +21,7 @@ private static final String UNKNOWN_SOURCEFILE = "<unknown>"; - private static final int APIVersion = 27; + private static final int APIVersion = 28; public static final int NO_MTIME = -1; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2010-04-24 17:30:46
|
Revision: 7044 http://jython.svn.sourceforge.net/jython/?rev=7044&view=rev Author: pjenvey Date: 2010-04-24 17:30:40 +0000 (Sat, 24 Apr 2010) Log Message: ----------- fix readall not actually detecting overflow Modified Paths: -------------- trunk/jython/src/org/python/core/io/RawIOBase.java Modified: trunk/jython/src/org/python/core/io/RawIOBase.java =================================================================== --- trunk/jython/src/org/python/core/io/RawIOBase.java 2010-04-23 05:14:49 UTC (rev 7043) +++ trunk/jython/src/org/python/core/io/RawIOBase.java 2010-04-24 17:30:40 UTC (rev 7044) @@ -55,15 +55,19 @@ * @return a ByteBuffer containing the bytes read */ public ByteBuffer readall() { - long allCount = 0; - int readCount = 0; ByteBuffer all = ByteBuffer.allocate(DEFAULT_BUFFER_SIZE); ByteBuffer readBuffer = ByteBuffer.allocate(DEFAULT_BUFFER_SIZE); - while ((readCount = readinto(readBuffer)) > 0) { + + for (int readCount = 0; (readCount = readinto(readBuffer)) > 0;) { if (all.remaining() < readCount) { + long newSize = (long) all.position() + readCount; + if (newSize > Integer.MAX_VALUE) { + throw Py.OverflowError("requested number of bytes is more than a Python " + + "string can hold"); + } + ByteBuffer old = all; - all = ByteBuffer.allocate(Math.max(old.capacity() * 2, - old.position() + readCount)); + all = ByteBuffer.allocate(Math.max(old.capacity() * 2, (int) newSize)); old.flip(); all.put(old); } @@ -72,11 +76,6 @@ readBuffer.clear(); } - if (allCount > Integer.MAX_VALUE) { - throw Py.OverflowError("requested number of bytes is more than a Python string can " - + "hold"); - } - all.flip(); return all; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2010-04-23 05:14:56
|
Revision: 7043 http://jython.svn.sourceforge.net/jython/?rev=7043&view=rev Author: pjenvey Date: 2010-04-23 05:14:49 +0000 (Fri, 23 Apr 2010) Log Message: ----------- move more into SocketIOBase, make getChannel return types covariant Modified Paths: -------------- trunk/jython/src/org/python/core/io/DatagramSocketIO.java trunk/jython/src/org/python/core/io/FileIO.java trunk/jython/src/org/python/core/io/ServerSocketIO.java trunk/jython/src/org/python/core/io/SocketIO.java trunk/jython/src/org/python/core/io/SocketIOBase.java Modified: trunk/jython/src/org/python/core/io/DatagramSocketIO.java =================================================================== --- trunk/jython/src/org/python/core/io/DatagramSocketIO.java 2010-04-23 05:06:48 UTC (rev 7042) +++ trunk/jython/src/org/python/core/io/DatagramSocketIO.java 2010-04-23 05:14:49 UTC (rev 7043) @@ -3,7 +3,6 @@ import java.io.IOException; import java.nio.ByteBuffer; -import java.nio.channels.Channel; import java.nio.channels.DatagramChannel; import org.python.core.Py; @@ -13,11 +12,8 @@ * * @author Philip Jenvey */ -public class DatagramSocketIO extends SocketIOBase { +public class DatagramSocketIO extends SocketIOBase<DatagramChannel> { - /** The underlying socket */ - private DatagramChannel socketChannel; - /** * Construct a DatagramSocketIO for the given DatagramChannel. * @@ -25,8 +21,7 @@ * @param mode a raw io socket mode String */ public DatagramSocketIO(DatagramChannel socketChannel, String mode) { - super(mode); - this.socketChannel = socketChannel; + super(socketChannel, mode); } @Override @@ -47,6 +42,7 @@ * @param bufs {@inheritDoc} * @return {@inheritDoc} */ + @Override public long readinto(ByteBuffer[] bufs) { checkClosed(); checkReadable(); @@ -75,6 +71,7 @@ * @param bufs {@inheritDoc} * @return {@inheritDoc} */ + @Override public long write(ByteBuffer[] bufs) { checkClosed(); checkWritable(); @@ -84,22 +81,4 @@ throw Py.IOError(ioe); } } - - @Override - public void close() { - if (closed()) { - return; - } - try { - socketChannel.close(); - } catch (IOException ioe) { - throw Py.IOError(ioe); - } - super.close(); - } - - @Override - public Channel getChannel() { - return socketChannel; - } } Modified: trunk/jython/src/org/python/core/io/FileIO.java =================================================================== --- trunk/jython/src/org/python/core/io/FileIO.java 2010-04-23 05:06:48 UTC (rev 7042) +++ trunk/jython/src/org/python/core/io/FileIO.java 2010-04-23 05:14:49 UTC (rev 7043) @@ -9,7 +9,6 @@ import java.io.OutputStream; import java.io.RandomAccessFile; import java.nio.ByteBuffer; -import java.nio.channels.Channel; import java.nio.channels.Channels; import java.nio.channels.FileChannel; @@ -423,7 +422,7 @@ } @Override - public Channel getChannel() { + public FileChannel getChannel() { return fileChannel; } } Modified: trunk/jython/src/org/python/core/io/ServerSocketIO.java =================================================================== --- trunk/jython/src/org/python/core/io/ServerSocketIO.java 2010-04-23 05:06:48 UTC (rev 7042) +++ trunk/jython/src/org/python/core/io/ServerSocketIO.java 2010-04-23 05:14:49 UTC (rev 7043) @@ -1,9 +1,7 @@ /* Copyright (c) 2007 Jython Developers */ package org.python.core.io; -import java.io.IOException; import java.nio.ByteBuffer; -import java.nio.channels.Channel; import java.nio.channels.ServerSocketChannel; import com.kenai.constantine.platform.Errno; @@ -14,11 +12,8 @@ * * @author Philip Jenvey */ -public class ServerSocketIO extends SocketIOBase { +public class ServerSocketIO extends SocketIOBase<ServerSocketChannel> { - /** The underlying socket */ - private ServerSocketChannel socketChannel; - /** * Construct a ServerSocketIO for the given ServerSocketChannel. * @@ -26,8 +21,7 @@ * @param mode a raw io socket mode String */ public ServerSocketIO(ServerSocketChannel socketChannel, String mode) { - super(mode); - this.socketChannel = socketChannel; + super(socketChannel, mode); } @Override @@ -43,22 +37,4 @@ checkWritable(); throw Py.IOError(Errno.EBADF); } - - @Override - public void close() { - if (closed()) { - return; - } - try { - socketChannel.close(); - } catch (IOException ioe) { - throw Py.IOError(ioe); - } - super.close(); - } - - @Override - public Channel getChannel() { - return socketChannel; - } } Modified: trunk/jython/src/org/python/core/io/SocketIO.java =================================================================== --- trunk/jython/src/org/python/core/io/SocketIO.java 2010-04-23 05:06:48 UTC (rev 7042) +++ trunk/jython/src/org/python/core/io/SocketIO.java 2010-04-23 05:14:49 UTC (rev 7043) @@ -3,7 +3,6 @@ import java.io.IOException; import java.nio.ByteBuffer; -import java.nio.channels.Channel; import java.nio.channels.SocketChannel; import org.python.core.Py; @@ -13,11 +12,8 @@ * * @author Philip Jenvey */ -public class SocketIO extends SocketIOBase { +public class SocketIO extends SocketIOBase<SocketChannel> { - /** The underlying socket */ - private SocketChannel socketChannel; - /** * Construct a SocketIO for the given SocketChannel. * @@ -25,8 +21,7 @@ * @param mode a raw io socket mode String */ public SocketIO(SocketChannel socketChannel, String mode) { - super(mode); - this.socketChannel = socketChannel; + super(socketChannel, mode); } @Override @@ -47,6 +42,7 @@ * @param bufs {@inheritDoc} * @return {@inheritDoc} */ + @Override public long readinto(ByteBuffer[] bufs) { checkClosed(); checkReadable(); @@ -75,6 +71,7 @@ * @param bufs {@inheritDoc} * @return {@inheritDoc} */ + @Override public long write(ByteBuffer[] bufs) { checkClosed(); checkWritable(); @@ -84,22 +81,4 @@ throw Py.IOError(ioe); } } - - @Override - public void close() { - if (closed()) { - return; - } - try { - socketChannel.close(); - } catch (IOException ioe) { - throw Py.IOError(ioe); - } - super.close(); - } - - @Override - public Channel getChannel() { - return socketChannel; - } } Modified: trunk/jython/src/org/python/core/io/SocketIOBase.java =================================================================== --- trunk/jython/src/org/python/core/io/SocketIOBase.java 2010-04-23 05:06:48 UTC (rev 7042) +++ trunk/jython/src/org/python/core/io/SocketIOBase.java 2010-04-23 05:14:49 UTC (rev 7043) @@ -1,6 +1,9 @@ /* Copyright (c) 2007 Jython Developers */ package org.python.core.io; +import java.io.IOException; +import java.nio.channels.Channel; + import org.python.core.Py; /** @@ -8,8 +11,11 @@ * * @author Philip Jenvey */ -public abstract class SocketIOBase extends RawIOBase { +public abstract class SocketIOBase<T extends Channel> extends RawIOBase { + /** The underlying socket */ + protected T socketChannel; + /** true if the socket is allowed to be read from */ private boolean readable = false; @@ -17,11 +23,13 @@ private boolean writable = false; /** - * Construct a SocketIOBase. + * Construct a SocketIOBase for the given socket Channel * + * @param socketChannel a Channel to wrap * @param mode a raw io socket mode String */ - public SocketIOBase(String mode) { + public SocketIOBase(T socketChannel, String mode) { + this.socketChannel = socketChannel; parseMode(mode); } @@ -33,7 +41,7 @@ * * @param mode a raw io socket mode String */ - private void parseMode(String mode) { + protected void parseMode(String mode) { if (mode.equals("r")) { readable = true; } else if (mode.equals("w")) { @@ -46,6 +54,24 @@ } @Override + public void close() { + if (closed()) { + return; + } + try { + socketChannel.close(); + } catch (IOException ioe) { + throw Py.IOError(ioe); + } + super.close(); + } + + @Override + public T getChannel() { + return socketChannel; + } + + @Override public boolean readable() { return readable; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2010-04-23 05:06:54
|
Revision: 7042 http://jython.svn.sourceforge.net/jython/?rev=7042&view=rev Author: pjenvey Date: 2010-04-23 05:06:48 +0000 (Fri, 23 Apr 2010) Log Message: ----------- reuse concurrentMap Modified Paths: -------------- trunk/jython/src/org/python/util/Generic.java Modified: trunk/jython/src/org/python/util/Generic.java =================================================================== --- trunk/jython/src/org/python/util/Generic.java 2010-04-18 21:45:51 UTC (rev 7041) +++ trunk/jython/src/org/python/util/Generic.java 2010-04-23 05:06:48 UTC (rev 7042) @@ -89,9 +89,7 @@ * whatever this is being assigned to. */ public static <E> Set<E> concurrentSet() { - return newSetFromMap(new ConcurrentHashMap<E, Boolean>(CHM_INITIAL_CAPACITY, - CHM_LOAD_FACTOR, - CHM_CONCURRENCY_LEVEL)); + return newSetFromMap(Generic.<E, Boolean>concurrentMap()); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2010-04-18 21:45:57
|
Revision: 7041 http://jython.svn.sourceforge.net/jython/?rev=7041&view=rev Author: pjenvey Date: 2010-04-18 21:45:51 +0000 (Sun, 18 Apr 2010) Log Message: ----------- this doesn't need to grab the javaProxy field directly Modified Paths: -------------- trunk/jython/src/org/python/core/__builtin__.java Modified: trunk/jython/src/org/python/core/__builtin__.java =================================================================== --- trunk/jython/src/org/python/core/__builtin__.java 2010-04-18 18:06:07 UTC (rev 7040) +++ trunk/jython/src/org/python/core/__builtin__.java 2010-04-18 21:45:51 UTC (rev 7041) @@ -1544,12 +1544,13 @@ PyObject obj = ap.getPyObject(0); if (obj.getJavaProxy() != null) { int bufsize = ap.getInt(2, -1); - if (obj.javaProxy instanceof InputStream) { + Object javaProxy = obj.getJavaProxy(); + if (javaProxy instanceof InputStream) { Py.warning(Py.DeprecationWarning, warning); - return new PyFile((InputStream)obj.javaProxy, bufsize); - } else if (obj.javaProxy instanceof OutputStream) { + return new PyFile((InputStream) javaProxy, bufsize); + } else if (javaProxy instanceof OutputStream) { Py.warning(Py.DeprecationWarning, warning); - return new PyFile((OutputStream)obj.javaProxy, bufsize); + return new PyFile((OutputStream) javaProxy, bufsize); } } return PyFile.TYPE.__call__(args, kwds); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2010-04-18 18:06:14
|
Revision: 7040 http://jython.svn.sourceforge.net/jython/?rev=7040&view=rev Author: pjenvey Date: 2010-04-18 18:06:07 +0000 (Sun, 18 Apr 2010) Log Message: ----------- use our more canonical windows check Modified Paths: -------------- trunk/jython/src/org/python/modules/errno.java Modified: trunk/jython/src/org/python/modules/errno.java =================================================================== --- trunk/jython/src/org/python/modules/errno.java 2010-04-18 17:56:20 UTC (rev 7039) +++ trunk/jython/src/org/python/modules/errno.java 2010-04-18 18:06:07 UTC (rev 7040) @@ -3,8 +3,8 @@ import com.kenai.constantine.Constant; import com.kenai.constantine.ConstantSet; -import com.kenai.constantine.Platform; import com.kenai.constantine.platform.Errno; +import org.jruby.ext.posix.util.Platform; import org.python.core.ClassDictInit; import org.python.core.Py; import org.python.core.PyDictionary; @@ -34,7 +34,7 @@ public static final PyObject errorcode = new PyDictionary(); public static void classDictInit(PyObject dict) { - if (Platform.OS.equals("windows")) { + if (Platform.IS_WINDOWS) { initWindows(dict); } else { initPosix(dict); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2010-04-18 17:56:26
|
Revision: 7039 http://jython.svn.sourceforge.net/jython/?rev=7039&view=rev Author: pjenvey Date: 2010-04-18 17:56:20 +0000 (Sun, 18 Apr 2010) Log Message: ----------- bump to jnr-posix 1.1.4 to fix a stat regression on windows Modified Paths: -------------- trunk/jython/extlibs/jnr-posix.jar Modified: trunk/jython/extlibs/jnr-posix.jar =================================================================== (Binary files differ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <otm...@us...> - 2010-04-18 09:54:34
|
Revision: 7038 http://jython.svn.sourceforge.net/jython/?rev=7038&view=rev Author: otmarhumbel Date: 2010-04-18 09:54:28 +0000 (Sun, 18 Apr 2010) Log Message: ----------- add *$py.class to svn:ignore Property Changed: ---------------- trunk/jython/tests/modjy/lib_python_folder/ trunk/jython/tests/modjy/lib_python_folder/mock_framework/ trunk/jython/tests/modjy/lib_python_folder/mock_framework/web/ trunk/jython/tests/modjy/lib_python_folder/mock_framework/web/handlers/ trunk/jython/tests/modjy/lib_python_folder/test_lib/ Property changes on: trunk/jython/tests/modjy/lib_python_folder ___________________________________________________________________ Added: svn:ignore + *$py.class Property changes on: trunk/jython/tests/modjy/lib_python_folder/mock_framework ___________________________________________________________________ Added: svn:ignore + *$py.class Property changes on: trunk/jython/tests/modjy/lib_python_folder/mock_framework/web ___________________________________________________________________ Added: svn:ignore + *$py.class Property changes on: trunk/jython/tests/modjy/lib_python_folder/mock_framework/web/handlers ___________________________________________________________________ Added: svn:ignore + *$py.class Property changes on: trunk/jython/tests/modjy/lib_python_folder/test_lib ___________________________________________________________________ Added: svn:ignore + *$py.class This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <otm...@us...> - 2010-04-18 09:53:30
|
Revision: 7037 http://jython.svn.sourceforge.net/jython/?rev=7037&view=rev Author: otmarhumbel Date: 2010-04-18 09:53:23 +0000 (Sun, 18 Apr 2010) Log Message: ----------- fix javadoc warning (parameter name) in full-build Modified Paths: -------------- trunk/jython/src/org/python/modules/jffi/Memory.java Modified: trunk/jython/src/org/python/modules/jffi/Memory.java =================================================================== --- trunk/jython/src/org/python/modules/jffi/Memory.java 2010-04-18 09:52:12 UTC (rev 7036) +++ trunk/jython/src/org/python/modules/jffi/Memory.java 2010-04-18 09:53:23 UTC (rev 7037) @@ -200,7 +200,7 @@ * @param offset The offset within the memory area of the start of the string. * @param bytes The byte array to write to the memory. * @param off The offset with the byte array to start copying. - * @param maxlen The number of bytes of the byte array to write to the memory area. (not including zero byte) + * @param len The number of bytes of the byte array to write to the memory area. (not including zero byte) */ public void putZeroTerminatedByteArray(long offset, byte[] bytes, int off, int len); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <otm...@us...> - 2010-04-18 09:52:19
|
Revision: 7036 http://jython.svn.sourceforge.net/jython/?rev=7036&view=rev Author: otmarhumbel Date: 2010-04-18 09:52:12 +0000 (Sun, 18 Apr 2010) Log Message: ----------- enable jython.bat in the 4nt (Take Command) shell fixes bug #1557 many thanks to stuaxo for the patch Modified Paths: -------------- trunk/jython/NEWS trunk/jython/src/shell/jython.bat Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2010-04-18 05:46:24 UTC (rev 7035) +++ trunk/jython/NEWS 2010-04-18 09:52:12 UTC (rev 7036) @@ -33,6 +33,7 @@ - [ 1456 ] sys.trace/profile attributes cause: AttributeError: write-only attr: trace in PyAMF - [ 1385 ] generator.throw uncaught on new generator doesn't stop the generator - [ 1596 ] SynchronizedCallable does not report that it is callable [suggested fix] + - [ 1557 ] jython.bat doesn't work in 4nt - Fix runtime issues during exitfuncs triggered via SystemRestart (such as during Django or Pylons development mode reloading) - Fix pickling of collections.defaultdict objects Modified: trunk/jython/src/shell/jython.bat =================================================================== --- trunk/jython/src/shell/jython.bat 2010-04-18 05:46:24 UTC (rev 7035) +++ trunk/jython/src/shell/jython.bat 2010-04-18 09:52:12 UTC (rev 7036) @@ -12,6 +12,12 @@ rem rem --------------------------------------------------------------------------- +rem If running in Take Command (4NT), force to run in cmd.exe +if not "%@eval[2+2]" == "4" goto normalstart +cmd /C %0 %* +goto finish + +:normalstart setlocal enabledelayedexpansion rem ----- Verify and set required environment variables ----------------------- This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2010-04-18 05:46:31
|
Revision: 7035 http://jython.svn.sourceforge.net/jython/?rev=7035&view=rev Author: pjenvey Date: 2010-04-18 05:46:24 +0000 (Sun, 18 Apr 2010) Log Message: ----------- constantine now has accurate Windows errnos so we actually have to map the missing errnos to the WSA equivalents like CPython does. and update to constantine-0.8-2355d07 for more WSA errnos Modified Paths: -------------- trunk/jython/extlibs/constantine.jar trunk/jython/src/org/python/modules/errno.java Modified: trunk/jython/extlibs/constantine.jar =================================================================== (Binary files differ) Modified: trunk/jython/src/org/python/modules/errno.java =================================================================== --- trunk/jython/src/org/python/modules/errno.java 2010-04-18 00:59:01 UTC (rev 7034) +++ trunk/jython/src/org/python/modules/errno.java 2010-04-18 05:46:24 UTC (rev 7035) @@ -3,6 +3,8 @@ import com.kenai.constantine.Constant; import com.kenai.constantine.ConstantSet; +import com.kenai.constantine.Platform; +import com.kenai.constantine.platform.Errno; import org.python.core.ClassDictInit; import org.python.core.Py; import org.python.core.PyDictionary; @@ -32,9 +34,12 @@ public static final PyObject errorcode = new PyDictionary(); public static void classDictInit(PyObject dict) { - for (Constant constant : ConstantSet.getConstantSet("Errno")) { - addCode(dict, constant.name(), constant.value(), constant.toString()); + if (Platform.OS.equals("windows")) { + initWindows(dict); + } else { + initPosix(dict); } + // XXX: necessary? addCode(dict, "ESOCKISBLOCKING", 20000, "Socket is in blocking mode"); addCode(dict, "EGETADDRINFOFAILED", 20001, "getaddrinfo failed"); @@ -43,6 +48,44 @@ dict.__setitem__("classDictInit", null); } + /** + * Setup errnos for Windows. + * + * Windows replaced the BSD/POSIX socket errnos with its own Winsock equivalents + * (e.g. EINVAL -> WSAEINVAL). We painstakenly map the missing constants to their WSA + * equivalent values and expose the WSA constants on their own. + */ + private static void initWindows(PyObject dict) { + // the few POSIX errnos Windows defines + ConstantSet winErrnos = ConstantSet.getConstantSet("Errno"); + // WSA errnos (and other Windows LastErrors) + ConstantSet lastErrors = ConstantSet.getConstantSet("LastError"); + + // Fill the gaps by searching through every possible constantine Errno first + // checking if it's defined on Windows, then falling back to the WSA prefixed + // version if it exists + Constant constant; + for (Constant errno : Errno.values()) { + String errnoName = errno.name(); + if ((constant = winErrnos.getConstant(errnoName)) != null + || (constant = lastErrors.getConstant("WSA" + errnoName)) != null) { + addCode(dict, errnoName, constant.value(), constant.toString()); + } + } + // Then provide the WSA names + for (Constant lastError : lastErrors) { + if (lastError.name().startsWith("WSA")) { + addCode(dict, lastError.name(), lastError.value(), lastError.toString()); + } + } + } + + private static void initPosix(PyObject dict) { + for (Constant constant : ConstantSet.getConstantSet("Errno")) { + addCode(dict, constant.name(), constant.value(), constant.toString()); + } + } + private static void addCode(PyObject dict, String name, int code, String message) { PyObject nameObj = Py.newString(name); PyObject codeObj = Py.newInteger(code); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |