()
| 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 |
| 501 |
nothing calls this directly
no test coverage detected