| 560 | |
| 561 | |
| 562 | class Executive: |
| 563 | |
| 564 | def __init__(self, rpchandler): |
| 565 | self.rpchandler = rpchandler |
| 566 | if idlelib.testing is False: |
| 567 | self.locals = __main__.__dict__ |
| 568 | self.calltip = calltip.Calltip() |
| 569 | self.autocomplete = autocomplete.AutoComplete() |
| 570 | else: |
| 571 | self.locals = {} |
| 572 | |
| 573 | def runcode(self, code): |
| 574 | global interruptable |
| 575 | try: |
| 576 | self.user_exc_info = None |
| 577 | interruptable = True |
| 578 | try: |
| 579 | exec(code, self.locals) |
| 580 | finally: |
| 581 | interruptable = False |
| 582 | except SystemExit as e: |
| 583 | if e.args: # SystemExit called with an argument. |
| 584 | ob = e.args[0] |
| 585 | if not isinstance(ob, (type(None), int)): |
| 586 | print('SystemExit: ' + str(ob), file=sys.stderr) |
| 587 | # Return to the interactive prompt. |
| 588 | except: |
| 589 | self.user_exc_info = sys.exc_info() # For testing, hook, viewer. |
| 590 | if quitting: |
| 591 | exit() |
| 592 | if sys.excepthook is sys.__excepthook__: |
| 593 | print_exception() |
| 594 | else: |
| 595 | try: |
| 596 | sys.excepthook(*self.user_exc_info) |
| 597 | except: |
| 598 | self.user_exc_info = sys.exc_info() # For testing. |
| 599 | print_exception() |
| 600 | jit = self.rpchandler.console.getvar("<<toggle-jit-stack-viewer>>") |
| 601 | if jit: |
| 602 | self.rpchandler.interp.open_remote_stack_viewer() |
| 603 | else: |
| 604 | flush_stdout() |
| 605 | |
| 606 | def interrupt_the_server(self): |
| 607 | if interruptable: |
| 608 | thread.interrupt_main() |
| 609 | |
| 610 | def start_the_debugger(self, gui_adap_oid): |
| 611 | return debugger_r.start_debugger(self.rpchandler, gui_adap_oid) |
| 612 | |
| 613 | def stop_the_debugger(self, idb_adap_oid): |
| 614 | "Unregister the Idb Adapter. Link objects and Idb then subject to GC" |
| 615 | self.rpchandler.unregister(idb_adap_oid) |
| 616 | |
| 617 | def get_the_calltip(self, name): |
| 618 | return self.calltip.fetch_tip(name) |
| 619 | |