Skip to content

Commit 810a2fb

Browse files
committed
Use collections.OrderedDict if available.
1 parent e4fafb9 commit 810a2fb

File tree

6 files changed

+28
-14
lines changed

6 files changed

+28
-14
lines changed

debug_toolbar/panels/cache.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@
1010
from django.core.cache.backends.base import BaseCache
1111
from django.dispatch import Signal
1212
from django.template import Node
13-
from django.utils.datastructures import SortedDict
1413
from django.utils.translation import ugettext_lazy as _, ungettext
14+
try:
15+
from collections import OrderedDict
16+
except ImportError:
17+
from django.utils.datastructures import SortedDict as OrderedDict
1518

1619
from debug_toolbar.panels import Panel
1720
from debug_toolbar.utils import (tidy_stacktrace, render_stacktrace,
@@ -139,7 +142,7 @@ def __init__(self, *args, **kwargs):
139142
self.hits = 0
140143
self.misses = 0
141144
self.calls = []
142-
self.counts = SortedDict((
145+
self.counts = OrderedDict((
143146
('add', 0),
144147
('get', 0),
145148
('set', 0),

debug_toolbar/panels/settings.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
from django.conf import settings
44
from django.views.debug import get_safe_settings
55
from django.utils.translation import ugettext_lazy as _
6-
from django.utils.datastructures import SortedDict
6+
try:
7+
from collections import OrderedDict
8+
except ImportError:
9+
from django.utils.datastructures import SortedDict as OrderedDict
710

811
from debug_toolbar.panels import Panel
912

@@ -21,5 +24,6 @@ def title(self):
2124

2225
def process_response(self, request, response):
2326
self.record_stats({
24-
'settings': SortedDict(sorted(get_safe_settings().items(), key=lambda s: s[0])),
27+
'settings': OrderedDict(sorted(get_safe_settings().items(),
28+
key=lambda s: s[0])),
2529
})

debug_toolbar/panels/staticfiles.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@
1212
from django.contrib.staticfiles.templatetags import staticfiles
1313

1414
from django.utils.translation import ungettext, ugettext_lazy as _
15-
from django.utils.datastructures import SortedDict
1615
from django.utils.functional import LazyObject
16+
try:
17+
from collections import OrderedDict
18+
except ImportError:
19+
from django.utils.datastructures import SortedDict as OrderedDict
1720

1821
from debug_toolbar import panels
1922
from debug_toolbar.utils import ThreadCollector
@@ -132,7 +135,7 @@ def get_staticfiles_finders(self):
132135
of relative and file system paths which that finder was able
133136
to find.
134137
"""
135-
finders_mapping = SortedDict()
138+
finders_mapping = OrderedDict()
136139
for finder in finders.get_finders():
137140
for path, finder_storage in finder.list([]):
138141
if getattr(finder_storage, 'prefix', None):

debug_toolbar/panels/versions.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44

55
import django
66
from django.conf import settings
7-
from django.utils.translation import ugettext_lazy as _
8-
from django.utils.datastructures import SortedDict
97
from django.utils.importlib import import_module
8+
from django.utils.translation import ugettext_lazy as _
9+
try:
10+
from collections import OrderedDict
11+
except ImportError:
12+
from django.utils.datastructures import SortedDict as OrderedDict
1013

1114
from debug_toolbar.panels import Panel
1215

@@ -46,6 +49,6 @@ def process_response(self, request, response):
4649
versions = sorted(versions, key=lambda version: version[0])
4750

4851
self.record_stats({
49-
'versions': SortedDict(versions),
52+
'versions': OrderedDict(versions),
5053
'paths': sys.path,
5154
})

debug_toolbar/toolbar.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99
from django.conf.urls import patterns, url
1010
from django.core.exceptions import ImproperlyConfigured
1111
from django.template.loader import render_to_string
12-
from django.utils.datastructures import SortedDict
1312
from django.utils.importlib import import_module
13+
try:
14+
from collections import OrderedDict
15+
except ImportError:
16+
from django.utils.datastructures import SortedDict as OrderedDict
1417

1518
from debug_toolbar import settings as dt_settings
1619

@@ -20,7 +23,7 @@ class DebugToolbar(object):
2023
def __init__(self, request):
2124
self.request = request
2225
self.config = dt_settings.CONFIG.copy()
23-
self._panels = SortedDict()
26+
self._panels = OrderedDict()
2427
for panel_class in self.get_panel_classes():
2528
panel_instance = panel_class(self)
2629
self._panels[panel_instance.panel_id] = panel_instance
@@ -61,7 +64,7 @@ def render_toolbar(self):
6164

6265
# Handle storing toolbars in memory and fetching them later on
6366

64-
_store = SortedDict()
67+
_store = OrderedDict()
6568

6669
def should_render_panels(self):
6770
render_panels = self.config['RENDER_PANELS']

tests/panels/test_staticfiles.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
from __future__ import absolute_import, unicode_literals
44

55
from django.conf import settings
6-
from django.contrib.staticfiles.templatetags import staticfiles
7-
from django.template import Context, RequestContext, Template
86

97
from ..base import BaseTestCase
108

0 commit comments

Comments
 (0)