MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / enablerlcompleter

Function enablerlcompleter

tools/python-3.11.9-amd64/Lib/site.py:443–500  ·  view source on GitHub ↗

Enable default readline configuration on interactive prompts, by registering a sys.__interactivehook__. 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 sitecust

()

Source from the content-addressed store, hash-verified

441 builtins.help = _sitebuiltins._Helper()
442
443def enablerlcompleter():
444 """Enable default readline configuration on interactive prompts, by
445 registering a sys.__interactivehook__.
446
447 If the readline module can be imported, the hook will set the Tab key
448 as completion key and register ~/.python_history as history file.
449 This can be overridden in the sitecustomize or usercustomize module,
450 or in a PYTHONSTARTUP file.
451 """
452 def register_readline():
453 import atexit
454 try:
455 import readline
456 import rlcompleter
457 except ImportError:
458 return
459
460 # Reading the initialization (config) file may not be enough to set a
461 # completion key, so we set one first and then read the file.
462 readline_doc = getattr(readline, '__doc__', '')
463 if readline_doc is not None and 'libedit' in readline_doc:
464 readline.parse_and_bind('bind ^I rl_complete')
465 else:
466 readline.parse_and_bind('tab: complete')
467
468 try:
469 readline.read_init_file()
470 except OSError:
471 # An OSError here could have many causes, but the most likely one
472 # is that there's no .inputrc file (or .editrc file in the case of
473 # Mac OS X + libedit) in the expected location. In that case, we
474 # want to ignore the exception.
475 pass
476
477 if readline.get_current_history_length() == 0:
478 # If no history was loaded, default to .python_history.
479 # The guard is necessary to avoid doubling history size at
480 # each interpreter exit when readline was already configured
481 # through a PYTHONSTARTUP hook, see:
482 # http://bugs.python.org/issue5845#msg198636
483 history = os.path.join(os.path.expanduser('~'),
484 '.python_history')
485 try:
486 readline.read_history_file(history)
487 except OSError:
488 pass
489
490 def write_history():
491 try:
492 readline.write_history_file(history)
493 except OSError:
494 # bpo-19891, bpo-41193: Home directory does not exist
495 # or is not writable, or the filesystem is read-only.
496 pass
497
498 atexit.register(write_history)
499
500 sys.__interactivehook__ = register_readline

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected