Skip to content

Commit 082f132

Browse files
committed
Drop obsolete conditional code.
1 parent 13491c9 commit 082f132

File tree

4 files changed

+7
-20
lines changed

4 files changed

+7
-20
lines changed

debug_toolbar/middleware.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77
import re
88
import threading
9-
from importlib import import_module
109

1110
from django.conf import settings
1211
from django.utils import six
1312
from django.utils.encoding import force_text
13+
from django.utils.module_loading import import_string
1414

1515
from debug_toolbar import settings as dt_settings
1616
from debug_toolbar.toolbar import DebugToolbar
@@ -45,9 +45,7 @@ def __init__(self):
4545
# setup, resolve it to the corresponding callable.
4646
func_or_path = dt_settings.CONFIG['SHOW_TOOLBAR_CALLBACK']
4747
if isinstance(func_or_path, six.string_types):
48-
# Replace this with import_by_path in Django >= 1.6.
49-
mod_path, func_name = func_or_path.rsplit('.', 1)
50-
self.show_toolbar = getattr(import_module(mod_path), func_name)
48+
self.show_toolbar = import_string(func_or_path)
5149
else:
5250
self.show_toolbar = func_or_path
5351

debug_toolbar/panels/redirects.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import absolute_import, unicode_literals
22

3-
from django.core.handlers.wsgi import STATUS_CODE_TEXT
43
from django.shortcuts import render_to_response
54
from django.utils.translation import ugettext_lazy as _
65

@@ -20,12 +19,7 @@ def process_response(self, request, response):
2019
if 300 <= int(response.status_code) < 400:
2120
redirect_to = response.get('Location', None)
2221
if redirect_to:
23-
try: # Django >= 1.6
24-
reason_phrase = response.reason_phrase
25-
except AttributeError:
26-
reason_phrase = STATUS_CODE_TEXT.get(response.status_code,
27-
'UNKNOWN STATUS CODE')
28-
status_line = '%s %s' % (response.status_code, reason_phrase)
22+
status_line = '%s %s' % (response.status_code, response.reason_phrase)
2923
cookies = response.cookies
3024
context = {'redirect_to': redirect_to, 'status_line': status_line}
3125
response = render_to_response('debug_toolbar/redirect.html', context)

debug_toolbar/settings.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from django.conf import settings
77
from django.utils import six
8+
from django.utils.module_loading import import_string
89

910
# Always import this module as follows:
1011
# from debug_toolbar import settings [as dt_settings]
@@ -174,12 +175,9 @@ def check_middleware():
174175

175176

176177
def is_middleware_class(middleware_class, middleware_path):
177-
# This could be replaced by import_by_path in Django >= 1.6.
178178
try:
179-
mod_path, cls_name = middleware_path.rsplit('.', 1)
180-
mod = import_module(mod_path)
181-
middleware_cls = getattr(mod, cls_name)
182-
except (AttributeError, ImportError, ValueError):
179+
middleware_cls = import_string(middleware_path)
180+
except ImportError:
183181
return
184182
return issubclass(middleware_cls, middleware_class)
185183

tests/panels/test_profiling.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ def test_view_executed_once(self):
4949
self.assertEqual(User.objects.count(), 1)
5050

5151
with self.assertRaises(IntegrityError):
52-
if hasattr(transaction, 'atomic'): # Django >= 1.6
53-
with transaction.atomic():
54-
response = self.client.get('/new_user/')
55-
else:
52+
with transaction.atomic():
5653
response = self.client.get('/new_user/')
5754
self.assertEqual(User.objects.count(), 1)

0 commit comments

Comments
 (0)