Пример #1
0
def sse(request):
    response = request.response
    response.content_type = 'text/event-stream'
    history = request.pdtb_history
    response.text = U_BLANK

    active_request_id = text_(request.GET.get('request_id'))
    client_last_request_id = text_(request.headers.get('Last-Event-Id', 0))

    max_visible_requests = get_setting(request.registry.settings,
                                       'max_visible_requests')
    if history:
        last_request_pair = history.last(1)[0]
        last_request_id = last_request_pair[0]
        if not last_request_id == client_last_request_id:
            data = [
                [
                    _id,
                    toolbar.json,
                    'active' if active_request_id == _id else ''
                ]
                for _id, toolbar in history.last(max_visible_requests)
                if toolbar.visible
            ]
            if data:
                response.text = U_SSE_PAYLOAD.format(last_request_id,
                                                     json.dumps(data))
    return response
Пример #2
0
    def process_response(self, response):
        data = []
        for index, query in enumerate(self.queries):
            stmt = query['statement']

            is_select = stmt.strip().lower().startswith('select')
            params = ''
            try:
                params = url_quote(json.dumps(query['parameters']))
            except TypeError:
                pass  # object not JSON serializable
            except UnicodeDecodeError:
                pass  # parameters contain non-utf8 (probably binary) data

            data.append({
                'engine_id': query['engine_id'],
                'duration': query['duration'],
                'sql': format_sql(stmt),
                'raw_sql': stmt,
                'parameters': query['parameters'],
                'params': params,
                'is_select': is_select,
                'context': query['context'],
                'query_index': index,
            })

        self.data = {
            'queries': data,
            'text': text_,
            'engines': self.engines,
        }
Пример #3
0
    def process_response(self, response):
        data = []
        for index, query in enumerate(self.queries):
            stmt = query['statement']

            is_select = stmt.strip().lower().startswith('select')
            params = ''
            try:
                params = url_quote(json.dumps(query['parameters']))
            except TypeError:
                pass  # object not JSON serializable
            except UnicodeDecodeError:
                pass  # parameters contain non-utf8 (probably binary) data

            need = self.token + stmt + params
            hash = hashlib.sha1(bytes_(need)).hexdigest()

            data.append({
                'engine_id': query['engine_id'],
                'duration': query['duration'],
                'sql': format_sql(stmt),
                'raw_sql': stmt,
                'hash': hash,
                'parameters': query['parameters'],
                'params': params,
                'is_select': is_select,
                'context': query['context'],
                'query_index': index,
            })

        self.data = {
            'queries': data,
            'text': text,
        }
Пример #4
0
    def process_response(self, response):
        data = []
        for query in self.queries:
            stmt = query['statement']

            is_select = stmt.strip().lower().startswith('select')
            params = ''
            try:
                params = url_quote(json.dumps(query['parameters']))
            except TypeError:
                pass # object not JSON serializable
            except UnicodeDecodeError:
                pass # parameters contain non-utf8 (probably binary) data

            need = self.token + stmt + params
            hash = hashlib.sha1(bytes_(need)).hexdigest()

            data.append({
                'engine_id': query['engine_id'],
                'duration': query['duration'],
                'sql': format_sql(stmt),
                'raw_sql': stmt,
                'hash': hash,
                'parameters': query['parameters'],
                'params': params,
                'is_select': is_select,
                'context': query['context'],
            })

        self.data = {
            'queries':data,
            'text':text,
            }
Пример #5
0
    def process_response(self, response):
        data = []
        for index, query in enumerate(self.queries):
            stmt = query['statement']

            is_select = stmt.strip().lower().startswith('select')
            params = ''
            try:
                params = url_quote(json.dumps(query['parameters']))
            except TypeError:
                pass  # object not JSON serializable
            except ValueError:
                pass  # JSON parameters serialization can generate ValueError
            except UnicodeDecodeError:
                pass  # parameters contain non-utf8 (probably binary) data

            data.append(
                {
                    'engine_id': query['engine_id'],
                    'duration': query['duration'],
                    'sql': format_sql(stmt),
                    'raw_sql': stmt,
                    'parameters': query['parameters'],
                    'params': params,
                    'is_select': is_select,
                    'context': query['context'],
                    'query_index': index,
                }
            )

        self.data = {
            'queries': data,
            'text': text_,
            'engines': self.engines,
        }
Пример #6
0
    def content(self):
        if not self.queries:
            return "No queries in executed in request."

        data = []
        for query in self.queries:
            stmt = query["statement"]

            is_select = stmt.strip().lower().startswith("select")
            params = ""
            try:
                params = url_quote(json.dumps(query["parameters"]))
            except TypeError:
                pass  # object not JSON serializable
            except UnicodeDecodeError:
                pass  # parameters contain non-utf8 (probably binary) data

            need = self.request.exc_history.token + stmt + params
            hash = hashlib.sha1(bytes_(need)).hexdigest()

            data.append(
                {
                    "engine_id": query["engine_id"],
                    "duration": query["duration"],
                    "sql": format_sql(stmt),
                    "raw_sql": stmt,
                    "hash": hash,
                    "parameters": query["parameters"],
                    "params": params,
                    "is_select": is_select,
                    "context": query["context"],
                }
            )

        vars = {
            "static_path": self.request.static_url(STATIC_PATH),
            "root_path": self.request.route_url(ROOT_ROUTE_NAME),
            "queries": data,
            "text": text,
        }

        delattr(self.request, "pdtb_sqla_queries")

        return self.render("pyramid_debugtoolbar.panels:templates/sqlalchemy.dbtmako", vars, self.request)
Пример #7
0
    def content(self):
        if not self.queries:
            return 'No queries in executed in request.'

        data = []
        for query in self.queries:
            stmt = query['statement']

            is_select = stmt.strip().lower().startswith('select')
            params = ''
            try:
                params = url_quote(json.dumps(query['parameters']))
            except TypeError:
                pass  # object not JSON serializable
            except UnicodeDecodeError:
                pass  # parameters contain non-utf8 (probably binary) data

            need = self.request.exc_history.token + stmt + params
            hash = hashlib.sha1(bytes_(need)).hexdigest()

            data.append({
                'engine_id': query['engine_id'],
                'duration': query['duration'],
                'sql': format_sql(stmt),
                'raw_sql': stmt,
                'hash': hash,
                'parameters': query['parameters'],
                'params': params,
                'is_select': is_select,
                'context': query['context'],
            })

        vars = {
            'static_path': self.request.static_url(STATIC_PATH),
            'root_path': self.request.route_url(ROOT_ROUTE_NAME),
            'queries': data,
            'text': text,
        }

        delattr(self.request, 'pdtb_sqla_queries')

        return self.render(
            'pyramid_debugtoolbar.panels:templates/sqlalchemy.dbtmako', vars,
            self.request)
Пример #8
0
    def content(self):
        if not self.queries:
            return 'No queries in executed in request.'

        data = []
        for query in self.queries:
            stmt = query['statement']

            is_select = stmt.strip().lower().startswith('select')
            params = ''
            try:
                params = url_quote(json.dumps(query['parameters']))
            except TypeError:
                pass # object not JSON serializable
            except UnicodeDecodeError:
                pass # parameters contain non-utf8 (probably binary) data

            need = self.request.exc_history.token + stmt + params
            hash = hashlib.sha1(bytes_(need)).hexdigest()

            data.append({
                'engine_id': query['engine_id'],
                'duration': query['duration'],
                'sql': format_sql(stmt),
                'raw_sql': stmt,
                'hash': hash,
                'parameters': query['parameters'],
                'params': params,
                'is_select': is_select,
                'context': query['context'],
            })

        vars = {
            'static_path': self.request.static_url(STATIC_PATH),
            'root_path': self.request.route_url(ROOT_ROUTE_NAME),
            'queries':data,
            'text':text,
            }

        delattr(self.request, 'pdtb_sqla_queries')

        return self.render(
            'pyramid_debugtoolbar.panels:templates/sqlalchemy.dbtmako',
            vars, self.request)
Пример #9
0
def sse(request):
    response = request.response
    response.content_type = 'text/event-stream'
    history = find_request_history(request)
    response.text = U_BLANK

    active_request_id = text_(request.GET.get('request_id'))
    client_last_request_id = text_(request.headers.get('Last-Event-Id', 0))

    if history:
        last_request_pair = history.last(1)[0]
        last_request_id = last_request_pair[0]
        if not last_request_id == client_last_request_id:
            data = [[_id, toolbar.json, 'active'
                        if active_request_id == _id else '']
                            for _id,toolbar in history.last(10)]
            if data:
                response.text = U_SSE_PAYLOAD.format(last_request_id,
                                                     json.dumps(data))
    return response
Пример #10
0
def sse(request):
    response = request.response
    response.content_type = 'text/event-stream'
    history = find_request_history(request)
    response.text = U_BLANK

    active_request_id = text_(request.GET.get('request_id'))
    client_last_request_id = text_(request.headers.get('Last-Event-Id', 0))

    if history:
        last_request_pair = history.last(1)[0]
        last_request_id = last_request_pair[0]
        if not last_request_id == client_last_request_id:
            data = [[
                _id, toolbar.json, 'active' if active_request_id == _id else ''
            ] for _id, toolbar in history.last(10)]
            if data:
                response.text = U_SSE_PAYLOAD.format(last_request_id,
                                                     json.dumps(data))
    return response