From: <pj...@us...> - 2009-05-05 07:19:39
|
Revision: 6296 http://jython.svn.sourceforge.net/jython/?rev=6296&view=rev Author: pjenvey Date: 2009-05-05 07:19:13 +0000 (Tue, 05 May 2009) Log Message: ----------- avoid overwriting any ProcessBuilder env vars unless it's necessary. it inherits them from Sysem.getenv and will maintain their underlying byte values (which may be butchered as Strings) on UNIX platforms if we don't touch them Modified Paths: -------------- trunk/jython/Lib/subprocess.py Modified: trunk/jython/Lib/subprocess.py =================================================================== --- trunk/jython/Lib/subprocess.py 2009-05-05 01:31:30 UTC (rev 6295) +++ trunk/jython/Lib/subprocess.py 2009-05-05 07:19:13 UTC (rev 6296) @@ -1132,6 +1132,30 @@ return CouplerThread(*args, **kwargs) + def _setup_env(self, env, builder_env): + """Carefully merge env with ProcessBuilder's only + overwriting key/values that differ + + System.getenv (Map<String, String>) may be backed by + <byte[], byte[]> on UNIX platforms where these are really + bytes. ProcessBuilder's env inherits its contents and will + maintain those byte values (which may be butchered as + Strings) for the subprocess if they haven't been modified. + """ + # Determine what's safe to merge + merge_env = dict((key, value) for key, value in env.iteritems() + if key not in builder_env or + builder_env.get(key) != value) + + # Prune anything not in env + entries = builder_env.entrySet().iterator() + for entry in entries: + if entry.getKey() not in env: + entries.remove() + + builder_env.putAll(merge_env) + + def _execute_child(self, args, executable, preexec_fn, close_fds, cwd, env, universal_newlines, startupinfo, creationflags, shell, @@ -1163,16 +1187,10 @@ except java.lang.IllegalArgumentException, iae: raise OSError(iae.getMessage() or iae) - if env is None: - # For compatibility with CPython which calls - # os.execvp(). os.environ is "inherited" there if env is - # not explicitly set - env = os.environ + # os.environ may be inherited for compatibility with CPython + self._setup_env(dict(os.environ if env is None else env), + builder.environment()) - builder_env = builder.environment() - builder_env.clear() - builder_env.putAll(dict(env)) - if cwd is None: cwd = os.getcwd() elif not os.path.exists(cwd): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |