/usr/lib/python2.7/dist-packages/debug_toolbar/panels/redirects.py is in python-django-debug-toolbar 1:1.0.1-0+nmu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | from __future__ import absolute_import, unicode_literals
from django.core.handlers.wsgi import STATUS_CODE_TEXT
from django.shortcuts import render
from django.utils.translation import ugettext_lazy as _
from debug_toolbar.panels import Panel
class RedirectsPanel(Panel):
"""
Panel that intercepts redirects and displays a page with debug info.
"""
@property
def enabled(self):
default = 'on' if self.toolbar.config['INTERCEPT_REDIRECTS'] else 'off'
return self.toolbar.request.COOKIES.get('djdt' + self.panel_id, default) == 'on'
has_content = False
nav_title = _("Intercept redirects")
def process_response(self, request, response):
if 300 <= int(response.status_code) < 400:
redirect_to = response.get('Location', None)
if redirect_to:
try: # Django >= 1.6
reason_phrase = response.reason_phrase
except AttributeError:
reason_phrase = STATUS_CODE_TEXT.get(response.status_code,
'UNKNOWN STATUS CODE')
status_line = '%s %s' % (response.status_code, reason_phrase)
cookies = response.cookies
context = {'redirect_to': redirect_to, 'status_line': status_line}
response = render(request, 'debug_toolbar/redirect.html', context)
response.cookies = cookies
return response
|