Issue #16400: Add command line option for isolated mode.
-I
Run Python in isolated mode. This also implies -E and -s. In isolated mode
sys.path contains neither the script’s directory nor the user’s
site-packages directory. All PYTHON* environment variables are ignored,
too. Further restrictions may be imposed to prevent the user from
injecting malicious code.
diff --git a/Modules/main.c b/Modules/main.c
index 435bd1b..25190b8 100644
--- a/Modules/main.c
+++ b/Modules/main.c
@@ -43,7 +43,7 @@
static int orig_argc;
/* command line options */
-#define BASE_OPTS L"bBc:dEhiJm:OqRsStuvVW:xX:?"
+#define BASE_OPTS L"bBc:dEhiIJm:OqRsStuvVW:xX:?"
#define PROGRAM_OPTS BASE_OPTS
@@ -65,6 +65,7 @@
static char *usage_2 = "\
-i : inspect interactively after running script; forces a prompt even\n\
if stdin does not appear to be a terminal; also PYTHONINSPECT=x\n\
+-I : isolate Python from the user's environment (implies -E and -s)\n\
-m mod : run library module as a script (terminates option list)\n\
-O : optimize generated bytecode slightly; also PYTHONOPTIMIZE=x\n\
-OO : remove doc-strings in addition to the -O optimizations\n\
@@ -426,6 +427,12 @@
Py_InteractiveFlag++;
break;
+ case 'I':
+ Py_IsolatedFlag++;
+ Py_NoUserSiteDirectory++;
+ Py_IgnoreEnvironmentFlag++;
+ break;
+
/* case 'J': reserved for Jython */
case 'O':