(namespace: Mapping[str, Any])
| 569 | |
| 570 | |
| 571 | def _setup(namespace: Mapping[str, Any]) -> None: |
| 572 | global raw_input |
| 573 | if raw_input is not None: |
| 574 | return # don't run _setup twice |
| 575 | |
| 576 | try: |
| 577 | f_in = sys.stdin.fileno() |
| 578 | f_out = sys.stdout.fileno() |
| 579 | except (AttributeError, ValueError): |
| 580 | return |
| 581 | if not os.isatty(f_in) or not os.isatty(f_out): |
| 582 | return |
| 583 | |
| 584 | _wrapper.f_in = f_in |
| 585 | _wrapper.f_out = f_out |
| 586 | |
| 587 | # set up namespace in rlcompleter, which requires it to be a bona fide dict |
| 588 | if not isinstance(namespace, dict): |
| 589 | namespace = dict(namespace) |
| 590 | _wrapper.config.readline_completer = RLCompleter(namespace).complete |
| 591 | |
| 592 | # this is not really what readline.c does. Better than nothing I guess |
| 593 | import builtins |
| 594 | raw_input = builtins.input |
| 595 | builtins.input = _wrapper.input |
| 596 | |
| 597 | |
| 598 | raw_input: Callable[[object], str] | None = None |
no test coverage detected