Exemplo n.º 1
0
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)
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
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()
Exemplo n.º 4
0
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)
Exemplo n.º 5
0
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)
Exemplo n.º 6
0
    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
Exemplo n.º 7
0
Arquivo: ext.py Projeto: niziou/wdb
 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')
Exemplo n.º 8
0
Arquivo: ext.py Projeto: minisin/wdb
 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')
Exemplo n.º 9
0
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)
Exemplo n.º 10
0
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)
Exemplo n.º 11
0
Arquivo: ext.py Projeto: niziou/wdb
 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
Exemplo n.º 12
0
Arquivo: ext.py Projeto: minisin/wdb
 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
Exemplo n.º 13
0
Arquivo: ext.py Projeto: niziou/wdb
 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
Exemplo n.º 14
0
 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
Exemplo n.º 15
0
Arquivo: ext.py Projeto: niziou/wdb
    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
Exemplo n.º 16
0
Arquivo: ext.py Projeto: minisin/wdb
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)
Exemplo n.º 17
0
 def run():
     from wdb import Wdb
     Wdb.get().run_file(fn)
Exemplo n.º 18
0
 def run():
     from wdb import Wdb
     Wdb.get().run_file(fn[0].decode('utf-8'))
Exemplo n.º 19
0
 def run():
     from wdb import Wdb
     Wdb.get().shell()
Exemplo n.º 20
0
 def wdb_pm(xtype, value, traceback):
     sys.__excepthook__(xtype, value, traceback)
     wdb = Wdb.get()
     wdb.reset()
     wdb.interaction(None, traceback, post_mortem=True)
Exemplo n.º 21
0
 def wdb_pm(xtype, value, traceback):
     sys.__excepthook__(xtype, value, traceback)
     wdb = Wdb.get()
     wdb.reset()
     wdb.interaction(None, traceback, post_mortem=True)
Exemplo n.º 22
0
 def run():
     from wdb import Wdb
     Wdb.get().run_file(fn)
Exemplo n.º 23
0
 def run():
     from wdb import Wdb
     Wdb.get().shell()