def process_response(self, response): # If the body is HTML, then we add the toolbar to the response. request = self.request if isinstance(response, WSGIHTTPException): # the body of a WSGIHTTPException needs to be "prepared" response.prepare(request.environ) for panel in self.panels: panel.process_response(response) if response.content_type in self.html_types: static_path = request.static_url(STATIC_PATH) root_path = request.route_url(ROOT_ROUTE_NAME) button_style = get_setting(request.registry.settings, 'button_style', '') vars = { 'panels': self.panels, 'static_path': static_path, 'root_path': root_path, 'button_style': button_style } toolbar_html = render( 'pyramid_debugtoolbar:templates/toolbar.mako', vars, request=request) response_html = response.body toolbar_html = toolbar_html.encode(response.charset or 'utf-8') body = replace_insensitive(response_html, bytes_('</body>'), toolbar_html + bytes_('</body>')) response.app_iter = [body]
def process_response(self, response): # If the body is HTML, then we add the toolbar to the response. request = self.request if isinstance(response, WSGIHTTPException): # the body of a WSGIHTTPException needs to be "prepared" response.prepare(request.environ) for panel in self.panels: panel.process_response(response) if response.content_type in self.html_types: static_path = request.static_url(STATIC_PATH) root_path = request.route_url(ROOT_ROUTE_NAME) button_style = get_setting(request.registry.settings, 'button_style', '') vars = {'panels': self.panels, 'static_path': static_path, 'root_path': root_path, 'button_style': button_style} toolbar_html = render( 'pyramid_debugtoolbar:templates/toolbar.dbtmako', vars, request=request) response_html = response.body toolbar_html = toolbar_html.encode(response.charset or 'utf-8') body = replace_insensitive( response_html, bytes_('</body>'), toolbar_html + bytes_('</body>') ) response.app_iter = [body] response.content_length = len(body)
def inject(self, request, response): """ Inject the debug toolbar iframe into an HTML response. """ # called in host app response_html = response.body toolbar_url = debug_toolbar_url(request, request.id) button_style = get_setting(request.registry.settings, "button_style", "") css_path = request.static_url(STATIC_PATH + "css/toolbar.css") toolbar_html = toolbar_html_template % { "button_style": button_style, "css_path": css_path, "toolbar_url": toolbar_url, } toolbar_html = toolbar_html.encode(response.charset or "utf-8") response.body = replace_insensitive(response_html, bytes_("</body>"), toolbar_html + bytes_("</body>"))
def process_response(self, response): # If the body is HTML, then we add the toolbar to the response. request = self.request for panel in self.panels: panel.process_response(response) if response.content_type in self.html_types: static_path = request.static_url(STATIC_PATH) root_path = request.route_url(ROOT_ROUTE_NAME) vars = {"panels": self.panels, "static_path": static_path, "root_path": root_path} toolbar_html = render("pyramid_debugtoolbar:templates/toolbar.jinja2", vars, request=request) toolbar_html = toolbar_html.encode(response.charset) response_html = response.body body = replace_insensitive(response_html, "</body>", toolbar_html + "</body>") response.app_iter = [body]
def inject(self, request, response): """ Inject the debug toolbar iframe into an HTML response. """ # called in host app response_html = response.body toolbar_url = debug_toolbar_url(request, request.id) button_style = get_setting(request.registry.settings, 'button_style', '') css_path = request.static_url(STATIC_PATH + 'css/toolbar_button.css') toolbar_html = toolbar_html_template % { 'button_style': button_style, 'css_path': css_path, 'toolbar_url': toolbar_url } toolbar_html = toolbar_html.encode(response.charset or 'utf-8') response.body = replace_insensitive(response_html, bytes_('</body>'), toolbar_html + bytes_('</body>'))
def inject(self, request, response): """ Inject the debug toolbar iframe into an HTML response. """ # called in host app response_html = response.body toolbar_url = debug_toolbar_url(request, request.id) button_style = get_setting(request.registry.settings, 'button_style', '') css_path = request.static_url(STATIC_PATH + 'css/toolbar_button.css') toolbar_html = toolbar_html_template % { 'button_style': button_style, 'css_path': css_path, 'toolbar_url': toolbar_url} toolbar_html = toolbar_html.encode(response.charset or 'utf-8') response.body = replace_insensitive( response_html, bytes_('</body>'), toolbar_html + bytes_('</body>') )
def process_response(self, response): # If the body is HTML, then we add the toolbar to the response. request = self.request if isinstance(response, WSGIHTTPException): # the body of a WSGIHTTPException needs to be "prepared" response.prepare(request.environ) for panel in self.panels: panel.process_response(response) if response.content_type in self.html_types: static_path = request.static_url(STATIC_PATH) root_path = request.route_url(ROOT_ROUTE_NAME) vars = {'panels': self.panels, 'static_path': static_path, 'root_path': root_path} toolbar_html = render( 'pyramid_debugtoolbar:templates/toolbar.jinja2', vars, request=request) response_html = response.body toolbar_html = toolbar_html.encode(response.charset or 'utf-8') body = replace_insensitive(response_html, '</body>', toolbar_html + '</body>') response.app_iter = [body]