Skip to content

Commit

Permalink
Deprecated SortedDict (replaced with collections.OrderedDict)
Browse files Browse the repository at this point in the history
Thanks Loic Bistuer for the review.
  • Loading branch information
funkybob authored and timgraham committed Aug 4, 2013
1 parent b278f74 commit 07876cf
Show file tree
Hide file tree
Showing 26 changed files with 139 additions and 107 deletions.
8 changes: 4 additions & 4 deletions django/contrib/admin/options.py
@@ -1,3 +1,4 @@
from collections import OrderedDict
import copy
import operator
from functools import partial, reduce, update_wrapper
Expand Down Expand Up @@ -29,7 +30,6 @@
from django.shortcuts import get_object_or_404
from django.template.response import SimpleTemplateResponse, TemplateResponse
from django.utils.decorators import method_decorator
from django.utils.datastructures import SortedDict
from django.utils.html import escape, escapejs
from django.utils.safestring import mark_safe
from django.utils import six
Expand Down Expand Up @@ -672,7 +672,7 @@ def get_actions(self, request):
# want *any* actions enabled on this page.
from django.contrib.admin.views.main import _is_changelist_popup
if self.actions is None or _is_changelist_popup(request):
return SortedDict()
return OrderedDict()

actions = []

Expand All @@ -693,8 +693,8 @@ def get_actions(self, request):
# get_action might have returned None, so filter any of those out.
actions = filter(None, actions)

# Convert the actions into a SortedDict keyed by name.
actions = SortedDict([
# Convert the actions into an OrderedDict keyed by name.
actions = OrderedDict([
(name, (func, name, desc))
for func, name, desc in actions
])
Expand Down
6 changes: 3 additions & 3 deletions django/contrib/admin/views/main.py
@@ -1,3 +1,4 @@
from collections import OrderedDict
import sys
import warnings

Expand All @@ -7,7 +8,6 @@
from django.db import models
from django.db.models.fields import FieldDoesNotExist
from django.utils import six
from django.utils.datastructures import SortedDict
from django.utils.deprecation import RenameMethodsBase
from django.utils.encoding import force_str, force_text
from django.utils.translation import ugettext, ugettext_lazy
Expand Down Expand Up @@ -319,13 +319,13 @@ def get_ordering(self, request, queryset):

def get_ordering_field_columns(self):
"""
Returns a SortedDict of ordering field column numbers and asc/desc
Returns an OrderedDict of ordering field column numbers and asc/desc
"""

# We must cope with more than one column having the same underlying sort
# field, so we base things on column numbers.
ordering = self._get_default_ordering()
ordering_fields = SortedDict()
ordering_fields = OrderedDict()
if ORDER_VAR not in self.params:
# for ordering specified on ModelAdmin or model Meta, we don't know
# the right column numbers absolutely, because there might be more
Expand Down
5 changes: 3 additions & 2 deletions django/contrib/auth/forms.py
@@ -1,9 +1,10 @@
from __future__ import unicode_literals

from collections import OrderedDict

from django import forms
from django.forms.util import flatatt
from django.template import loader
from django.utils.datastructures import SortedDict
from django.utils.encoding import force_bytes
from django.utils.html import format_html, format_html_join
from django.utils.http import urlsafe_base64_encode
Expand Down Expand Up @@ -324,7 +325,7 @@ def clean_old_password(self):
)
return old_password

PasswordChangeForm.base_fields = SortedDict([
PasswordChangeForm.base_fields = OrderedDict([
(k, PasswordChangeForm.base_fields[k])
for k in ['old_password', 'new_password1', 'new_password2']
])
Expand Down
16 changes: 8 additions & 8 deletions django/contrib/auth/hashers.py
Expand Up @@ -2,13 +2,13 @@

import base64
import binascii
from collections import OrderedDict
import hashlib
import importlib

from django.dispatch import receiver
from django.conf import settings
from django.test.signals import setting_changed
from django.utils.datastructures import SortedDict
from django.utils.encoding import force_bytes, force_str, force_text
from django.core.exceptions import ImproperlyConfigured
from django.utils.crypto import (
Expand Down Expand Up @@ -243,7 +243,7 @@ def verify(self, password, encoded):
def safe_summary(self, encoded):
algorithm, iterations, salt, hash = encoded.split('$', 3)
assert algorithm == self.algorithm
return SortedDict([
return OrderedDict([
(_('algorithm'), algorithm),
(_('iterations'), iterations),
(_('salt'), mask_hash(salt)),
Expand Down Expand Up @@ -320,7 +320,7 @@ def safe_summary(self, encoded):
algorithm, empty, algostr, work_factor, data = encoded.split('$', 4)
assert algorithm == self.algorithm
salt, checksum = data[:22], data[22:]
return SortedDict([
return OrderedDict([
(_('algorithm'), algorithm),
(_('work factor'), work_factor),
(_('salt'), mask_hash(salt)),
Expand Down Expand Up @@ -368,7 +368,7 @@ def verify(self, password, encoded):
def safe_summary(self, encoded):
algorithm, salt, hash = encoded.split('$', 2)
assert algorithm == self.algorithm
return SortedDict([
return OrderedDict([
(_('algorithm'), algorithm),
(_('salt'), mask_hash(salt, show=2)),
(_('hash'), mask_hash(hash)),
Expand Down Expand Up @@ -396,7 +396,7 @@ def verify(self, password, encoded):
def safe_summary(self, encoded):
algorithm, salt, hash = encoded.split('$', 2)
assert algorithm == self.algorithm
return SortedDict([
return OrderedDict([
(_('algorithm'), algorithm),
(_('salt'), mask_hash(salt, show=2)),
(_('hash'), mask_hash(hash)),
Expand Down Expand Up @@ -429,7 +429,7 @@ def verify(self, password, encoded):
def safe_summary(self, encoded):
assert encoded.startswith('sha1$$')
hash = encoded[6:]
return SortedDict([
return OrderedDict([
(_('algorithm'), self.algorithm),
(_('hash'), mask_hash(hash)),
])
Expand Down Expand Up @@ -462,7 +462,7 @@ def verify(self, password, encoded):
return constant_time_compare(encoded, encoded_2)

def safe_summary(self, encoded):
return SortedDict([
return OrderedDict([
(_('algorithm'), self.algorithm),
(_('hash'), mask_hash(encoded, show=3)),
])
Expand Down Expand Up @@ -496,7 +496,7 @@ def verify(self, password, encoded):
def safe_summary(self, encoded):
algorithm, salt, data = encoded.split('$', 2)
assert algorithm == self.algorithm
return SortedDict([
return OrderedDict([
(_('algorithm'), algorithm),
(_('salt'), salt),
(_('hash'), mask_hash(data, show=3)),
Expand Down
20 changes: 11 additions & 9 deletions django/contrib/formtools/wizard/views.py
@@ -1,11 +1,11 @@
from collections import OrderedDict
import re

from django import forms
from django.shortcuts import redirect
from django.core.urlresolvers import reverse
from django.forms import formsets, ValidationError
from django.views.generic import TemplateView
from django.utils.datastructures import SortedDict
from django.utils.decorators import classonlymethod
from django.utils.translation import ugettext as _
from django.utils import six
Expand Down Expand Up @@ -158,7 +158,7 @@ def get_initkwargs(cls, form_list=None, initial_dict=None,
form_list = form_list or kwargs.pop('form_list',
getattr(cls, 'form_list', None)) or []

computed_form_list = SortedDict()
computed_form_list = OrderedDict()

assert len(form_list) > 0, 'at least one form is needed'

Expand Down Expand Up @@ -206,7 +206,7 @@ def get_form_list(self):
The form_list is always generated on the fly because condition methods
could use data from other (maybe previous forms).
"""
form_list = SortedDict()
form_list = OrderedDict()
for form_key, form_class in six.iteritems(self.form_list):
# try to fetch the value from condition list, by default, the form
# gets passed to the new list.
Expand Down Expand Up @@ -498,9 +498,10 @@ def get_next_step(self, step=None):
if step is None:
step = self.steps.current
form_list = self.get_form_list()
key = form_list.keyOrder.index(step) + 1
if len(form_list.keyOrder) > key:
return form_list.keyOrder[key]
keys = list(form_list.keys())
key = keys.index(step) + 1
if len(keys) > key:
return keys[key]
return None

def get_prev_step(self, step=None):
Expand All @@ -512,9 +513,10 @@ def get_prev_step(self, step=None):
if step is None:
step = self.steps.current
form_list = self.get_form_list()
key = form_list.keyOrder.index(step) - 1
keys = list(form_list.keys())
key = keys.index(step) - 1
if key >= 0:
return form_list.keyOrder[key]
return keys[key]
return None

def get_step_index(self, step=None):
Expand All @@ -524,7 +526,7 @@ def get_step_index(self, step=None):
"""
if step is None:
step = self.steps.current
return self.get_form_list().keyOrder.index(step)
return list(self.get_form_list().keys()).index(step)

def get_context_data(self, form, **kwargs):
"""
Expand Down
9 changes: 5 additions & 4 deletions django/contrib/staticfiles/finders.py
@@ -1,8 +1,9 @@
from collections import OrderedDict
import os

from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.core.files.storage import default_storage, Storage, FileSystemStorage
from django.utils.datastructures import SortedDict
from django.utils.functional import empty, memoize, LazyObject
from django.utils.module_loading import import_by_path
from django.utils._os import safe_join
Expand All @@ -11,7 +12,7 @@
from django.contrib.staticfiles import utils
from django.contrib.staticfiles.storage import AppStaticStorage

_finders = SortedDict()
_finders = OrderedDict()


class BaseFinder(object):
Expand Down Expand Up @@ -47,7 +48,7 @@ def __init__(self, apps=None, *args, **kwargs):
# List of locations with static files
self.locations = []
# Maps dir paths to an appropriate storage instance
self.storages = SortedDict()
self.storages = OrderedDict()
if not isinstance(settings.STATICFILES_DIRS, (list, tuple)):
raise ImproperlyConfigured(
"Your STATICFILES_DIRS setting is not a tuple or list; "
Expand Down Expand Up @@ -118,7 +119,7 @@ def __init__(self, apps=None, *args, **kwargs):
# The list of apps that are handled
self.apps = []
# Mapping of app module paths to storage instances
self.storages = SortedDict()
self.storages = OrderedDict()
if apps is None:
apps = settings.INSTALLED_APPS
for app in apps:
Expand Down
Expand Up @@ -2,12 +2,12 @@

import os
import sys
from collections import OrderedDict
from optparse import make_option

from django.core.files.storage import FileSystemStorage
from django.core.management.base import CommandError, NoArgsCommand
from django.utils.encoding import smart_text
from django.utils.datastructures import SortedDict
from django.utils.six.moves import input

from django.contrib.staticfiles import finders, storage
Expand Down Expand Up @@ -97,7 +97,7 @@ def collect(self):
else:
handler = self.copy_file

found_files = SortedDict()
found_files = OrderedDict()
for finder in finders.get_finders():
for path, storage in finder.list(self.ignore_patterns):
# Prefix the relative path if the source storage contains it
Expand Down
6 changes: 3 additions & 3 deletions django/contrib/staticfiles/storage.py
@@ -1,4 +1,5 @@
from __future__ import unicode_literals
from collections import OrderedDict
import hashlib
from importlib import import_module
import os
Expand All @@ -16,7 +17,6 @@
from django.core.exceptions import ImproperlyConfigured
from django.core.files.base import ContentFile
from django.core.files.storage import FileSystemStorage, get_storage_class
from django.utils.datastructures import SortedDict
from django.utils.encoding import force_bytes, force_text
from django.utils.functional import LazyObject
from django.utils._os import upath
Expand Down Expand Up @@ -64,7 +64,7 @@ def __init__(self, *args, **kwargs):
except InvalidCacheBackendError:
# Use the default backend
self.cache = default_cache
self._patterns = SortedDict()
self._patterns = OrderedDict()
for extension, patterns in self.patterns:
for pattern in patterns:
if isinstance(pattern, (tuple, list)):
Expand Down Expand Up @@ -202,7 +202,7 @@ def converter(matchobj):

def post_process(self, paths, dry_run=False, **options):
"""
Post process the given SortedDict of files (called from collectstatic).
Post process the given OrderedDict of files (called from collectstatic).
Processing is actually two separate operations:
Expand Down
9 changes: 5 additions & 4 deletions django/core/management/commands/dumpdata.py
@@ -1,10 +1,11 @@
from collections import OrderedDict
from optparse import make_option

from django.core.exceptions import ImproperlyConfigured
from django.core.management.base import BaseCommand, CommandError
from django.core import serializers
from django.db import router, DEFAULT_DB_ALIAS
from django.utils.datastructures import SortedDict

from optparse import make_option

class Command(BaseCommand):
option_list = BaseCommand.option_list + (
Expand Down Expand Up @@ -66,11 +67,11 @@ def handle(self, *app_labels, **options):
if len(app_labels) == 0:
if primary_keys:
raise CommandError("You can only use --pks option with one model")
app_list = SortedDict((app, None) for app in get_apps() if app not in excluded_apps)
app_list = OrderedDict((app, None) for app in get_apps() if app not in excluded_apps)
else:
if len(app_labels) > 1 and primary_keys:
raise CommandError("You can only use --pks option with one model")
app_list = SortedDict()
app_list = OrderedDict()
for label in app_labels:
try:
app_label, model_label = label.split('.')
Expand Down
6 changes: 3 additions & 3 deletions django/core/management/commands/inspectdb.py
@@ -1,12 +1,12 @@
from __future__ import unicode_literals

from collections import OrderedDict
import keyword
import re
from optparse import make_option

from django.core.management.base import NoArgsCommand, CommandError
from django.db import connections, DEFAULT_DB_ALIAS
from django.utils.datastructures import SortedDict


class Command(NoArgsCommand):
Expand Down Expand Up @@ -69,7 +69,7 @@ def handle_inspection(self, options):
used_column_names = [] # Holds column names used in the table so far
for i, row in enumerate(connection.introspection.get_table_description(cursor, table_name)):
comment_notes = [] # Holds Field notes, to be displayed in a Python comment.
extra_params = SortedDict() # Holds Field parameters such as 'db_column'.
extra_params = OrderedDict() # Holds Field parameters such as 'db_column'.
column_name = row[0]
is_relation = i in relations

Expand Down Expand Up @@ -193,7 +193,7 @@ def get_field_type(self, connection, table_name, row):
description, this routine will return the given field type name, as
well as any additional keyword parameters and notes for the field.
"""
field_params = SortedDict()
field_params = OrderedDict()
field_notes = []

try:
Expand Down

0 comments on commit 07876cf

Please sign in to comment.