summaryrefslogtreecommitdiffstats
path: root/Lib/test/script_helper.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2012-02-20 18:54:16 (GMT)
committerGeorg Brandl <georg@python.org>2012-02-20 18:54:16 (GMT)
commit2daf6ae2495c862adf8bc717bfe9964081ea0b10 (patch)
treeebd7efe668e4f7842c6d51bdbde47b00f92a57db /Lib/test/script_helper.py
parentec1712a1662282c909b4cd4cc0c7486646bc9246 (diff)
downloadcpython-2daf6ae2495c862adf8bc717bfe9964081ea0b10.zip
cpython-2daf6ae2495c862adf8bc717bfe9964081ea0b10.tar.gz
cpython-2daf6ae2495c862adf8bc717bfe9964081ea0b10.tar.bz2
Issue #13703: add a way to randomize the hash values of basic types (str, bytes, datetime)
in order to make algorithmic complexity attacks on (e.g.) web apps much more complicated. The environment variable PYTHONHASHSEED and the new command line flag -R control this behavior.
Diffstat (limited to 'Lib/test/script_helper.py')
-rw-r--r--Lib/test/script_helper.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/Lib/test/script_helper.py b/Lib/test/script_helper.py
index 0699cf6..fca28d3 100644
--- a/Lib/test/script_helper.py
+++ b/Lib/test/script_helper.py
@@ -3,7 +3,6 @@
import sys
import os
-import re
import os.path
import tempfile
import subprocess
@@ -19,11 +18,15 @@ def _assert_python(expected_success, *args, **env_vars):
cmd_line = [sys.executable]
if not env_vars:
cmd_line.append('-E')
- cmd_line.extend(args)
# Need to preserve the original environment, for in-place testing of
# shared library builds.
env = os.environ.copy()
+ # But a special flag that can be set to override -- in this case, the
+ # caller is responsible to pass the full environment.
+ if env_vars.pop('__cleanenv', None):
+ env = {}
env.update(env_vars)
+ cmd_line.extend(args)
p = subprocess.Popen(cmd_line, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
env=env)