Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 313523c

Browse files
committed
Issue #28192: Don't import readline in isolated mode
1 parent d2154ab commit 313523c

3 files changed

Lines changed: 11 additions & 12 deletions

File tree

Lib/site.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@
6060
6161
The readline module is also automatically configured to enable
6262
completion for systems that support it. This can be overridden in
63-
sitecustomize, usercustomize or PYTHONSTARTUP.
63+
sitecustomize, usercustomize or PYTHONSTARTUP. Starting Python in
64+
isolated mode (-I) disables automatic readline configuration.
6465
6566
After these operations, an attempt is made to import a module
6667
named sitecustomize, which can perform arbitrary additional
@@ -491,7 +492,7 @@ def execsitecustomize():
491492
else:
492493
raise
493494
except Exception as err:
494-
if os.environ.get("PYTHONVERBOSE"):
495+
if sys.flags.verbose:
495496
sys.excepthook(*sys.exc_info())
496497
else:
497498
sys.stderr.write(
@@ -511,7 +512,7 @@ def execusercustomize():
511512
else:
512513
raise
513514
except Exception as err:
514-
if os.environ.get("PYTHONVERBOSE"):
515+
if sys.flags.verbose:
515516
sys.excepthook(*sys.exc_info())
516517
else:
517518
sys.stderr.write(
@@ -538,12 +539,13 @@ def main():
538539
setquit()
539540
setcopyright()
540541
sethelper()
541-
enablerlcompleter()
542+
if not sys.flags.isolated:
543+
enablerlcompleter()
542544
execsitecustomize()
543545
if ENABLE_USER_SITE:
544546
execusercustomize()
545547

546-
# Prevent edition of sys.path when python was started with -S and
548+
# Prevent extending of sys.path when python was started with -S and
547549
# site is imported later.
548550
if not sys.flags.no_site:
549551
main()

Lib/test/test_site.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,6 @@ def test_addpackage_import_bad_exec(self):
140140
self.assertRegex(err_out.getvalue(), 'Traceback')
141141
self.assertRegex(err_out.getvalue(), 'ModuleNotFoundError')
142142

143-
@unittest.skipIf(sys.platform == "win32", "Windows does not raise an "
144-
"error for file paths containing null characters")
145143
def test_addpackage_import_bad_pth_file(self):
146144
# Issue 5258
147145
pth_dir, pth_fn = self.make_pth("abc\x00def\n")
@@ -447,10 +445,9 @@ def test_startup_imports(self):
447445
popen = subprocess.Popen([sys.executable, '-I', '-v', '-c',
448446
'import sys; print(set(sys.modules))'],
449447
stdout=subprocess.PIPE,
450-
stderr=subprocess.PIPE)
448+
stderr=subprocess.PIPE,
449+
encoding='utf-8')
451450
stdout, stderr = popen.communicate()
452-
stdout = stdout.decode('utf-8')
453-
stderr = stderr.decode('utf-8')
454451
modules = eval(stdout)
455452

456453
self.assertIn('site', modules)
@@ -474,6 +471,5 @@ def test_startup_imports(self):
474471
if sys.platform != 'darwin':
475472
self.assertFalse(modules.intersection(collection_mods), stderr)
476473

477-
478474
if __name__ == "__main__":
479475
unittest.main()

Modules/main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,8 @@ Py_Main(int argc, wchar_t **argv)
703703
PySys_SetArgv(argc-_PyOS_optind, argv+_PyOS_optind);
704704

705705
if ((Py_InspectFlag || (command == NULL && filename == NULL && module == NULL)) &&
706-
isatty(fileno(stdin))) {
706+
isatty(fileno(stdin)) &&
707+
!Py_IsolatedFlag) {
707708
PyObject *v;
708709
v = PyImport_ImportModule("readline");
709710
if (v == NULL)

0 commit comments

Comments
 (0)