def main(): """Wdb entry point""" sys.path.insert(0, os.getcwd()) args, extrargs = parser.parse_known_args() sys.argv = ['wdb'] + extrargs if args.file: file = os.path.join(os.getcwd(), args.file) if args.source: print('The source argument cannot be used with file.') sys.exit(1) if not os.path.exists(file): print('Error:', file, 'does not exist') sys.exit(1) Wdb.get().run_file(file) else: source = None if args.source: source = os.path.join(os.getcwd(), args.source) if not os.path.exists(source): print('Error:', source, 'does not exist') sys.exit(1) Wdb.get().shell(source)
async def run_file(file_name: str) -> None: # pragma: no cover """ Function for run file debug """ # pylint: disable=import-outside-toplevel from wdb import Wdb # isort:skip Wdb.get().run_file(file_name)
async def run_shell() -> None: # pragma: no cover """ Function for run shell(debug) """ # pylint: disable=import-outside-toplevel from wdb import Wdb # isort:skip Wdb.get().shell()
def main(): """Inspired by python -m pdb. Debug any python script with wdb""" if not sys.argv[1:] or sys.argv[1] in ("--help", "-h"): print("usage: wdb.py scriptfile [arg] ...") sys.exit(2) mainpyfile = sys.argv[1] if not os.path.exists(mainpyfile): print('Error:', mainpyfile, 'does not exist') sys.exit(1) del sys.argv[0] sys.path[0] = os.path.dirname(mainpyfile) Wdb.get().run_file(mainpyfile)
def _wdb_execute(*args, **kwargs): from wdb import trace, Wdb if Wdb.enabled: wdb = Wdb.get() wdb.closed = False # Activate request ignores interesting = True if len(args) > 0 and isinstance(args[0], ErrorHandler): interesting = False elif (len(args) > 2 and isinstance(args[0], StaticFileHandler) and args[2] == 'favicon.ico'): interesting = False if Wdb.enabled and interesting: with trace(close_on_exit=True, under=under): old_execute(*args, **kwargs) else: old_execute(*args, **kwargs) # Close set_trace debuggers stop_trace(close_on_exit=True) if Wdb.enabled: # Reset closed state wdb.closed = False
def f(): # Enable wdb wdb = Wdb.get() Wdb.enabled = True start_response('200 OK', [ ('Content-Type', 'text/html'), ('X-Thing', wdb.uuid)]) yield to_bytes(' ' * 4096) wdb = set_trace() wdb.die() yield to_bytes('Exited')
def f(): # Enable wdb wdb = Wdb.get() Wdb.enabled = True start_response('200 OK', [('Content-Type', 'text/html'), ('X-Thing', wdb.uuid)]) yield to_bytes(' ' * 4096) wdb = set_trace() wdb.die() yield to_bytes('Exited')
def main(): """Wdb entry point""" sys.path.insert(0, os.getcwd()) args, extrargs = parser.parse_known_args() sys.argv = ['wdb'] + args.args + extrargs if args.file: file = os.path.join(os.getcwd(), args.file) if args.source: print('The source argument cannot be used with file.') sys.exit(1) if not os.path.exists(file): print('Error:', file, 'does not exist') sys.exit(1) if args.trace: Wdb.get().run_file(file) else: def wdb_pm(xtype, value, traceback): sys.__excepthook__(xtype, value, traceback) wdb = Wdb.get() wdb.reset() wdb.interaction(None, traceback, post_mortem=True) sys.excepthook = wdb_pm with open(file) as f: code = compile(f.read(), file, 'exec') execute(code, globals(), globals()) else: source = None if args.source: source = os.path.join(os.getcwd(), args.source) if not os.path.exists(source): print('Error:', source, 'does not exist') sys.exit(1) Wdb.get().shell(source)
def trace_wsgi(environ, start_response): wdb = Wdb.get() wdb.closed = False appiter = None try: with trace(close_on_exit=True, under=self.app): appiter = self.app(environ, start_response) for item in appiter: yield item except Exception: start_response('500 INTERNAL SERVER ERROR', [ ('Content-Type', 'text/html')]) yield _handle_off() finally: hasattr(appiter, 'close') and appiter.close() wdb.closed = False
def trace_wsgi(environ, start_response): wdb = Wdb.get() wdb.closed = False appiter = None try: with trace(close_on_exit=True, under=self.app): appiter = self.app(environ, start_response) for item in appiter: yield item except Exception: start_response('500 INTERNAL SERVER ERROR', [('Content-Type', 'text/html')]) yield _handle_off() finally: hasattr(appiter, 'close') and appiter.close() wdb.closed = False
def catch(environ, start_response): wdb = Wdb.get() wdb.closed = False appiter = None try: appiter = self.app(environ, start_response) for item in appiter: yield item except Exception: start_response('500 INTERNAL SERVER ERROR', [ ('Content-Type', 'text/html')]) yield _handle_off() finally: # Close set_trace debuggers stop_trace(close_on_exit=True) hasattr(appiter, 'close') and appiter.close() wdb.closed = False
def catch(environ, start_response): wdb = Wdb.get() wdb.closed = False appiter = None try: appiter = self.app(environ, start_response) for item in appiter: yield item except Exception: start_response('500 INTERNAL SERVER ERROR', [('Content-Type', 'text/html')]) yield _handle_off() finally: # Close set_trace debuggers stop_trace(close_on_exit=True) hasattr(appiter, 'close') and appiter.close() wdb.closed = False
def _wdb_execute(*args, **kwargs): from wdb import trace, Wdb wdb = Wdb.get() wdb.closed = False # Activate request ignores interesting = True if len(args) > 0 and isinstance(args[0], ErrorHandler): interesting = False elif len(args) > 2 and isinstance( args[0], StaticFileHandler) and args[2] == 'favicon.ico': interesting = False if Wdb.enabled and interesting: with trace(close_on_exit=True, under=under): old_execute(*args, **kwargs) else: old_execute(*args, **kwargs) # Close set_trace debuggers stop_trace(close_on_exit=True) # Reset closed state wdb.closed = False
def post_mortem_interaction(uuid, exc_info): wdb = Wdb.get(force_uuid=uuid) type_, value, tb = exc_info frame = None _value = value if not isinstance(_value, BaseException): _value = type_(value) wdb.obj_cache[id(exc_info)] = exc_info wdb.extra_vars['__exception__'] = exc_info exception = type_.__name__ exception_description = str(value) + ' [POST MORTEM]' init = 'Echo|%s' % dump( { 'for': '__exception__', 'val': escape('%s: %s') % (exception, exception_description) }) wdb.interaction(frame, tb, exception, exception_description, init=init, iframe_mode=True)
def run(): from wdb import Wdb Wdb.get().run_file(fn)
def run(): from wdb import Wdb Wdb.get().run_file(fn[0].decode('utf-8'))
def run(): from wdb import Wdb Wdb.get().shell()
def wdb_pm(xtype, value, traceback): sys.__excepthook__(xtype, value, traceback) wdb = Wdb.get() wdb.reset() wdb.interaction(None, traceback, post_mortem=True)