comparison Python/sysmodule.c @ 85081:dd0d751cc7f1

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.
author Christian Heimes <christian@cheimes.de>
date Sat, 10 Aug 2013 16:36:18 +0200
parents 31796b188bec
children 6cb3ae431bef
comparison
equal deleted inserted replaced
85080:d43435e82e21 85081:dd0d751cc7f1
1367 /* {"unbuffered", "-u"}, */ 1367 /* {"unbuffered", "-u"}, */
1368 /* {"skip_first", "-x"}, */ 1368 /* {"skip_first", "-x"}, */
1369 {"bytes_warning", "-b"}, 1369 {"bytes_warning", "-b"},
1370 {"quiet", "-q"}, 1370 {"quiet", "-q"},
1371 {"hash_randomization", "-R"}, 1371 {"hash_randomization", "-R"},
1372 {"isolated", "-I"},
1372 {0} 1373 {0}
1373 }; 1374 };
1374 1375
1375 static PyStructSequence_Desc flags_desc = { 1376 static PyStructSequence_Desc flags_desc = {
1376 "sys.flags", /* name */ 1377 "sys.flags", /* name */
1377 flags__doc__, /* doc */ 1378 flags__doc__, /* doc */
1378 flags_fields, /* fields */ 1379 flags_fields, /* fields */
1379 12 1380 13
1380 }; 1381 };
1381 1382
1382 static PyObject* 1383 static PyObject*
1383 make_flags(void) 1384 make_flags(void)
1384 { 1385 {
1404 /* SetFlag(saw_unbuffered_flag); */ 1405 /* SetFlag(saw_unbuffered_flag); */
1405 /* SetFlag(skipfirstline); */ 1406 /* SetFlag(skipfirstline); */
1406 SetFlag(Py_BytesWarningFlag); 1407 SetFlag(Py_BytesWarningFlag);
1407 SetFlag(Py_QuietFlag); 1408 SetFlag(Py_QuietFlag);
1408 SetFlag(Py_HashRandomizationFlag); 1409 SetFlag(Py_HashRandomizationFlag);
1410 SetFlag(Py_IsolatedFlag);
1409 #undef SetFlag 1411 #undef SetFlag
1410 1412
1411 if (PyErr_Occurred()) { 1413 if (PyErr_Occurred()) {
1412 return NULL; 1414 return NULL;
1413 } 1415 }
1942 } 1944 }
1943 1945
1944 void 1946 void
1945 PySys_SetArgv(int argc, wchar_t **argv) 1947 PySys_SetArgv(int argc, wchar_t **argv)
1946 { 1948 {
1947 PySys_SetArgvEx(argc, argv, 1); 1949 PySys_SetArgvEx(argc, argv, Py_IsolatedFlag == 0);
1948 } 1950 }
1949 1951
1950 /* Reimplementation of PyFile_WriteString() no calling indirectly 1952 /* Reimplementation of PyFile_WriteString() no calling indirectly
1951 PyErr_CheckSignals(): avoid the call to PyObject_Str(). */ 1953 PyErr_CheckSignals(): avoid the call to PyObject_Str(). */
1952 1954