summaryrefslogtreecommitdiffstats
path: root/Lib/site.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/site.py')
-rw-r--r--Lib/site.py26
1 files changed, 19 insertions, 7 deletions
diff --git a/Lib/site.py b/Lib/site.py
index cafd3ab..b3194d7 100644
--- a/Lib/site.py
+++ b/Lib/site.py
@@ -491,12 +491,21 @@ def register_readline():
This can be overridden in the sitecustomize or usercustomize module,
or in a PYTHONSTARTUP file.
"""
+ if not sys.flags.ignore_environment:
+ PYTHON_BASIC_REPL = os.getenv("PYTHON_BASIC_REPL")
+ else:
+ PYTHON_BASIC_REPL = False
+
import atexit
try:
import readline
import rlcompleter # noqa: F401
- import _pyrepl.readline
- import _pyrepl.unix_console
+ if PYTHON_BASIC_REPL:
+ CAN_USE_PYREPL = False
+ else:
+ import _pyrepl.readline
+ import _pyrepl.unix_console
+ from _pyrepl.main import CAN_USE_PYREPL
except ImportError:
return
@@ -517,7 +526,6 @@ def register_readline():
pass
if readline.get_current_history_length() == 0:
- from _pyrepl.main import CAN_USE_PYREPL
# If no history was loaded, default to .python_history,
# or PYTHON_HISTORY.
# The guard is necessary to avoid doubling history size at
@@ -525,13 +533,17 @@ def register_readline():
# through a PYTHONSTARTUP hook, see:
# http://bugs.python.org/issue5845#msg198636
history = gethistoryfile()
- if os.getenv("PYTHON_BASIC_REPL") or not CAN_USE_PYREPL:
- readline_module = readline
- else:
+
+ if CAN_USE_PYREPL:
readline_module = _pyrepl.readline
+ exceptions = (OSError, *_pyrepl.unix_console._error)
+ else:
+ readline_module = readline
+ exceptions = OSError
+
try:
readline_module.read_history_file(history)
- except (OSError,* _pyrepl.unix_console._error):
+ except exceptions:
pass
def write_history():