From: <otm...@us...> - 2009-06-02 08:23:29
|
Revision: 6439 http://jython.svn.sourceforge.net/jython/?rev=6439&view=rev Author: otmarhumbel Date: 2009-06-02 08:23:27 +0000 (Tue, 02 Jun 2009) Log Message: ----------- - restrict jar sys.executable to our own jython.jar - pass the following tests in the java -jar case: test_subprocess, test_subprocess_jy, test_popen, test_popen2 Modified Paths: -------------- trunk/jython/Lib/subprocess.py Modified: trunk/jython/Lib/subprocess.py =================================================================== --- trunk/jython/Lib/subprocess.py 2009-06-02 08:23:00 UTC (rev 6438) +++ trunk/jython/Lib/subprocess.py 2009-06-02 08:23:27 UTC (rev 6439) @@ -1236,16 +1236,21 @@ raise TypeError('args must contain only strings') args = _escape_args(args) - if len(args) > 0 and '.jar' == args[0][-4:] and executable is None: - args = ['java', '-jar'] + args + if len(args) > 0 and self.isJarExecutable(args[0]) and executable is None: + args = self.prefixJarExecutable(args) if shell: + if len(args) == 1: + splittedArgs = args[0].split(' ') + # TODO:Oti breaks if path to jython.jar contains spaces + if self.isJarExecutable(splittedArgs[0]): + args = self.prefixJarExecutable(args, single=True) args = _shell_command + args if executable is not None: args[0] = executable - if '.jar' == executable[-4:]: - args = ['java', '-jar'] + args + if self.isJarExecutable(args[0]): + args = self.prefixJarExecutable(args) builder = java.lang.ProcessBuilder(args) # os.environ may be inherited for compatibility with CPython @@ -1274,7 +1279,19 @@ raise OSError(e.getMessage() or e) self._child_created = True + def isJarExecutable(self, argument): + """returns true if argument is a path to jython.jar""" + return 'jython.jar' == argument[-10:] + def prefixJarExecutable(self, args, single=False): + """prepend java -jar to args + if single is True, args list is assumed to consit of one single element only""" + if not single: + args = ['java', '-jar'] + args + else: + args[0] = 'java -jar ' + args[0] + return args + def poll(self, _deadstate=None): """Check if child process has terminated. Returns returncode attribute.""" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |