예제 #1
0
파일: ext.py 프로젝트: 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')
예제 #2
0
파일: ext.py 프로젝트: 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')
예제 #3
0
파일: ext.py 프로젝트: rayleyva/wdb
    def __call__(self, environ, start_response):
        path = environ.get('PATH_INFO', '')

        if path == '/__wdb/on':
            # Enable wdb
            Wdb.enabled = True
            start_response('200 OK', [('Content-Type', 'text/html')])
            return to_bytes('Wdb is now on'),

        if path == '/__wdb/shell':
            # Enable wdb
            Wdb.enabled = True
            wdb = set_trace()
            start_response('200 OK', [('Content-Type', 'text/html')])
            wdb.die()
            return to_bytes('Exited'),

        if Wdb.enabled:

            def trace_wsgi(environ, start_response):
                appiter = None
                try:
                    with trace(close_on_exit=True):
                        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()

            return trace_wsgi(environ, start_response)

        def catch(environ, start_response):
            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()

        return catch(environ, start_response)
예제 #4
0
파일: ext.py 프로젝트: B-Rich/wdb
    def __call__(self, environ, start_response):
        path = environ.get('PATH_INFO', '')

        if path == '/__wdb/on':
            # Enable wdb
            Wdb.enabled = True
            start_response('200 OK', [('Content-Type', 'text/html')])
            return to_bytes('Wdb is now on'),

        if path == '/__wdb/shell':
            # Enable wdb
            Wdb.enabled = True
            wdb = set_trace()
            start_response('200 OK', [('Content-Type', 'text/html')])
            wdb.die()
            return to_bytes('Exited'),

        if Wdb.enabled:
            def trace_wsgi(environ, start_response):
                appiter = None
                try:
                    with trace(close_on_exit=True):
                        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()
            return trace_wsgi(environ, start_response)

        def catch(environ, start_response):
            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()

        return catch(environ, start_response)
예제 #5
0
파일: ext.py 프로젝트: minisin/wdb
def _handle_off(silent=False):
    if not silent:
        log.exception('Exception with wdb off')

    uuid = str(uuid4())
    Thread(target=post_mortem_interaction, args=(uuid, sys.exc_info())).start()

    web_url = 'http://%s:%d/pm/session/%s' % (WEB_SERVER or 'localhost',
                                              WEB_PORT or 1984, uuid)
    return to_bytes('''
        <html>
            <head>
                <title>WDB Post Mortem</title>
                <style>
                  html, body {
                    margin: 0;
                    padding: 0;
                  }
                </style>
                <script>
                    addEventListener("message", function (e) {
                        if (e.data == 'activate') {
                            var request = new XMLHttpRequest();
                            request.open('GET', '/__wdb/on', true);
                            request.onload = function() {
                                location.reload(true);
                            }
                            request.send();
                        }
                    }, false);
                </script>
            </head>
            <body>
                <iframe
                    src="%s"
                    marginheight="0"
                    marginwidth="0"
                    frameborder="0"
                    scrolling="no"
                    width="100%%"
                    height="100%%"
                    id="wdbframe">
                </iframe>
            </body>
        </html>
    ''' % web_url)
예제 #6
0
def _handle_off(silent=False):
    if not silent:
        log.exception('Exception with wdb off')
    type_, value, tb = sys.exc_info()
    stack = traceback.extract_tb(tb)
    stack.reverse()

    with open(
            os.path.join(os.path.abspath(os.path.dirname(__file__)), 'res',
                         '500.html')) as f:
        return to_bytes(f.read() % dict(
            trace=traceback.format_exc(),
            title=type_.__name__.replace("'", "\\'").replace('\n', ' '),
            subtitle=str(value).replace("'", "\\'").replace('\n', ' '),
            state='',
            trace_dict=dump({
                'trace': [tuple(frame_summary) for frame_summary in stack],
            })))
예제 #7
0
파일: ext.py 프로젝트: niziou/wdb
def _handle_off(silent=False):
    if not silent:
        log.exception('Exception with wdb off')
    type_, value, tb = sys.exc_info()
    stack = traceback.extract_tb(tb)
    stack.reverse()

    with open(
            os.path.join(
                os.path.abspath(os.path.dirname(__file__)),
                'res',
                '500.html')) as f:
        return to_bytes(
            f.read() % dict(
                trace=traceback.format_exc(),
                title=type_.__name__.replace("'", "\\'").replace('\n', ' '),
                subtitle=str(value).replace("'", "\\'").replace('\n', ' '),
                state='',
                trace_dict=dump({
                    'trace': [tuple(frame_summary) for frame_summary in stack],
                })
            )
        )