MCPcopy Index your code
hub / github.com/RustPython/RustPython / register_readline

Function register_readline

Lib/site.py:495–593  ·  view source on GitHub ↗

Configure readline completion on interactive prompts. If the readline module can be imported, the hook will set the Tab key as completion key and register ~/.python_history as history file. This can be overridden in the sitecustomize or usercustomize module, or in a PYTHONSTARTUP fi

()

Source from the content-addressed store, hash-verified

493
494
495def register_readline():
496 """Configure readline completion on interactive prompts.
497
498 If the readline module can be imported, the hook will set the Tab key
499 as completion key and register ~/.python_history as history file.
500 This can be overridden in the sitecustomize or usercustomize module,
501 or in a PYTHONSTARTUP file.
502 """
503 if not sys.flags.ignore_environment:
504 PYTHON_BASIC_REPL = os.getenv("PYTHON_BASIC_REPL")
505 else:
506 PYTHON_BASIC_REPL = False
507
508 import atexit
509
510 try:
511 try:
512 import readline
513 except ImportError:
514 readline = None
515 else:
516 import rlcompleter # noqa: F401
517 except ImportError:
518 return
519
520 try:
521 if PYTHON_BASIC_REPL:
522 CAN_USE_PYREPL = False
523 else:
524 original_path = sys.path
525 sys.path = [p for p in original_path if p != '']
526 try:
527 import _pyrepl.readline
528 if os.name == "nt":
529 import _pyrepl.windows_console
530 console_errors = (_pyrepl.windows_console._error,)
531 else:
532 import _pyrepl.unix_console
533 console_errors = _pyrepl.unix_console._error
534 from _pyrepl.main import CAN_USE_PYREPL
535 finally:
536 sys.path = original_path
537 except ImportError:
538 return
539
540 if readline is not None:
541 # Reading the initialization (config) file may not be enough to set a
542 # completion key, so we set one first and then read the file.
543 if readline.backend == 'editline':
544 readline.parse_and_bind('bind ^I rl_complete')
545 else:
546 readline.parse_and_bind('tab: complete')
547
548 try:
549 readline.read_init_file()
550 except OSError:
551 # An OSError here could have many causes, but the most likely one
552 # is that there's no .inputrc file (or .editrc file in the case of

Callers

nothing calls this directly

Calls 5

gethistoryfileFunction · 0.85
parse_and_bindMethod · 0.80
read_history_fileMethod · 0.80
registerMethod · 0.45

Tested by

no test coverage detected