Skip to content

Dropped a branch for Python < 2.7 compatibility. #840

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion debug_toolbar/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@
from django.template.base import linebreak_iter # NOQA
except ImportError: # Django < 1.9
from django.views.debug import linebreak_iter # NOQA

11 changes: 2 additions & 9 deletions debug_toolbar/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,8 @@ def process_response(self, request, response):
# Insert the toolbar in the response.
content = force_text(response.content, encoding=settings.DEFAULT_CHARSET)
insert_before = dt_settings.get_config()['INSERT_BEFORE']
try: # Python >= 2.7
pattern = re.escape(insert_before)
bits = re.split(pattern, content, flags=re.IGNORECASE)
except TypeError: # Python < 2.7
pattern = '(.+?)(%s|$)' % re.escape(insert_before)
matches = re.findall(pattern, content, flags=re.DOTALL | re.IGNORECASE)
bits = [m[0] for m in matches if m[1] == insert_before]
# When the body ends with a newline, there's two trailing groups.
bits.append(''.join(m[0] for m in matches if m[1] == ''))
pattern = re.escape(insert_before)
bits = re.split(pattern, content, flags=re.IGNORECASE)
if len(bits) > 1:
# When the toolbar will be inserted for sure, generate the stats.
for panel in reversed(toolbar.enabled_panels):
Expand Down
3 changes: 1 addition & 2 deletions debug_toolbar/panels/templates/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
from os.path import normpath
from pprint import pformat

import django
from django import http
from django.conf.urls import url
from django.db.models.query import QuerySet, RawQuerySet
from django.template import Context, RequestContext, Template
from django.template import RequestContext, Template
from django.test.signals import template_rendered
from django.test.utils import instrumented_test_render
from django.utils import six
Expand Down
3 changes: 1 addition & 2 deletions debug_toolbar/panels/templates/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
from django.http import HttpResponseBadRequest
from django.shortcuts import render_to_response
from django.template import TemplateDoesNotExist
from django.utils.safestring import mark_safe

from django.template.engine import Engine
from django.utils.safestring import mark_safe


def template_source(request):
Expand Down