def execstring(pytext, globals, locals, filename="<string>", debugging=0, modname="__main__", profiling=0): if debugging: import PyDebugger, bdb BdbQuit = bdb.BdbQuit else: BdbQuit = 'BdbQuitDummyException' pytext = string.split(pytext, '\r') pytext = string.join(pytext, '\n') + '\n' W.SetCursor("watch") globals['__name__'] = modname globals['__file__'] = filename sys.argv = [filename] try: code = compile(pytext, filename, "exec") except: # XXXX BAAAADDD.... We let tracebackwindow decide to treat SyntaxError # special. That's wrong because THIS case is special (could be literal # overflow!) and SyntaxError could mean we need a traceback (syntax error # in imported module!!! tracebackwindow.traceback(1, filename) return try: if debugging: PyDebugger.startfromhere() else: if hasattr(MacOS, 'EnableAppswitch'): MacOS.EnableAppswitch(0) try: if profiling: import profile, ProfileBrowser p = profile.Profile() p.set_cmd(filename) try: p.runctx(code, globals, locals) finally: import pstats stats = pstats.Stats(p) ProfileBrowser.ProfileBrowser(stats) else: exec code in globals, locals finally: if hasattr(MacOS, 'EnableAppswitch'): MacOS.EnableAppswitch(-1) except W.AlertError, detail: raise W.AlertError, detail
def showbreakpoints(self, onoff): if (not not self._debugger) <> onoff: if onoff: if not __debug__: import W raise W.AlertError, "Can't debug in \"Optimize bytecode\" mode.\r(see \"Default startup options\" in EditPythonPreferences)" import PyDebugger self._debugger = PyDebugger.getdebugger() self._debugger.register_editor(self, self.file) elif self._debugger: self._debugger.unregister_editor(self, self.file) self._debugger = None self.adjust(self._bounds)
def showbreakpoints(self, onoff): if (not not self._debugger) <> onoff: if onoff: if not __debug__: import W raise W.AlertError, 'Can\'t debug in "Optimize bytecode" mode.\r(see "Default startup options" in EditPythonPreferences)' import PyDebugger self._debugger = PyDebugger.getdebugger() self._debugger.register_editor(self, self.file) elif self._debugger: self._debugger.unregister_editor(self, self.file) self._debugger = None self.adjust(self._bounds)
def postmortem(self): import PyDebugger PyDebugger.postmortem(self.type, self.value, self.tb)
else: exec code in globals, locals finally: if hasattr(MacOS, 'EnableAppswitch'): MacOS.EnableAppswitch(-1) except W.AlertError, detail: raise W.AlertError, detail except (KeyboardInterrupt, BdbQuit): pass except SystemExit, arg: if arg.code: sys.stderr.write("Script exited with status code: %s\n" % repr(arg.code)) except: if debugging: sys.settrace(None) PyDebugger.postmortem(sys.exc_type, sys.exc_value, sys.exc_traceback) return else: tracebackwindow.traceback(1, filename) if debugging: sys.settrace(None) PyDebugger.stop() _identifieRE = re.compile(r"[A-Za-z_][A-Za-z_0-9]*") def identifieRE_match(str): match = _identifieRE.match(str) if not match: return -1 return match.end()