Changed several hardcoding of `dict` method calls in `django.utils.datastructures.py` to use `super` instead.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@6712 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Gary Wilson Jr 2007-11-25 18:10:45 +00:00
parent 8df3d2b467
commit 303d22b0d2
1 changed files with 20 additions and 19 deletions

View File

@ -56,7 +56,7 @@ class SortedDict(dict):
def __init__(self, data=None): def __init__(self, data=None):
if data is None: if data is None:
data = {} data = {}
dict.__init__(self, data) super(SortedDict, self).__init__(data)
if isinstance(data, dict): if isinstance(data, dict):
self.keyOrder = data.keys() self.keyOrder = data.keys()
else: else:
@ -68,12 +68,12 @@ class SortedDict(dict):
for key, value in self.iteritems()]) for key, value in self.iteritems()])
def __setitem__(self, key, value): def __setitem__(self, key, value):
dict.__setitem__(self, key, value) super(SortedDict, self).__setitem__(key, value)
if key not in self.keyOrder: if key not in self.keyOrder:
self.keyOrder.append(key) self.keyOrder.append(key)
def __delitem__(self, key): def __delitem__(self, key):
dict.__delitem__(self, key) super(SortedDict, self).__delitem__(key)
self.keyOrder.remove(key) self.keyOrder.remove(key)
def __iter__(self): def __iter__(self):
@ -81,7 +81,7 @@ class SortedDict(dict):
yield k yield k
def pop(self, k, *args): def pop(self, k, *args):
result = dict.pop(self, k, *args) result = super(SortedDict, self).pop(k, *args)
try: try:
self.keyOrder.remove(k) self.keyOrder.remove(k)
except ValueError: except ValueError:
@ -90,7 +90,7 @@ class SortedDict(dict):
return result return result
def popitem(self): def popitem(self):
result = dict.popitem(self) result = super(SortedDict, self).popitem()
self.keyOrder.remove(result[0]) self.keyOrder.remove(result[0])
return result return result
@ -99,7 +99,7 @@ class SortedDict(dict):
def iteritems(self): def iteritems(self):
for key in self.keyOrder: for key in self.keyOrder:
yield key, dict.__getitem__(self, key) yield key, super(SortedDict, self).__getitem__(key)
def keys(self): def keys(self):
return self.keyOrder[:] return self.keyOrder[:]
@ -108,11 +108,11 @@ class SortedDict(dict):
return iter(self.keyOrder) return iter(self.keyOrder)
def values(self): def values(self):
return [dict.__getitem__(self, k) for k in self.keyOrder] return [super(SortedDict, self).__getitem__(k) for k in self.keyOrder]
def itervalues(self): def itervalues(self):
for key in self.keyOrder: for key in self.keyOrder:
yield dict.__getitem__(self, key) yield super(SortedDict, self).__getitem__(key)
def update(self, dict_): def update(self, dict_):
for k, v in dict_.items(): for k, v in dict_.items():
@ -121,7 +121,7 @@ class SortedDict(dict):
def setdefault(self, key, default): def setdefault(self, key, default):
if key not in self.keyOrder: if key not in self.keyOrder:
self.keyOrder.append(key) self.keyOrder.append(key)
return dict.setdefault(self, key, default) return super(SortedDict, self).setdefault(key, default)
def value_for_index(self, index): def value_for_index(self, index):
"""Returns the value of the item at the given zero-based index.""" """Returns the value of the item at the given zero-based index."""
@ -135,7 +135,7 @@ class SortedDict(dict):
if n < index: if n < index:
index -= 1 index -= 1
self.keyOrder.insert(index, key) self.keyOrder.insert(index, key)
dict.__setitem__(self, key, value) super(SortedDict, self).__setitem__(key, value)
def copy(self): def copy(self):
"""Returns a copy of this object.""" """Returns a copy of this object."""
@ -173,10 +173,11 @@ class MultiValueDict(dict):
single name-value pairs. single name-value pairs.
""" """
def __init__(self, key_to_list_mapping=()): def __init__(self, key_to_list_mapping=()):
dict.__init__(self, key_to_list_mapping) super(MultiValueDict, self).__init__(key_to_list_mapping)
def __repr__(self): def __repr__(self):
return "<%s: %s>" % (self.__class__.__name__, dict.__repr__(self)) return "<%s: %s>" % (self.__class__.__name__,
super(MultiValueDict, self).__repr__())
def __getitem__(self, key): def __getitem__(self, key):
""" """
@ -184,7 +185,7 @@ class MultiValueDict(dict):
raises KeyError if not found. raises KeyError if not found.
""" """
try: try:
list_ = dict.__getitem__(self, key) list_ = super(MultiValueDict, self).__getitem__(key)
except KeyError: except KeyError:
raise MultiValueDictKeyError, "Key %r not found in %r" % (key, self) raise MultiValueDictKeyError, "Key %r not found in %r" % (key, self)
try: try:
@ -193,10 +194,10 @@ class MultiValueDict(dict):
return [] return []
def __setitem__(self, key, value): def __setitem__(self, key, value):
dict.__setitem__(self, key, [value]) super(MultiValueDict, self).__setitem__(key, [value])
def __copy__(self): def __copy__(self):
return self.__class__(dict.items(self)) return self.__class__(super(MultiValueDict, self).items())
def __deepcopy__(self, memo=None): def __deepcopy__(self, memo=None):
import copy import copy
@ -222,12 +223,12 @@ class MultiValueDict(dict):
def getlist(self, key): def getlist(self, key):
"""Returns an empty list if the requested data doesn't exist.""" """Returns an empty list if the requested data doesn't exist."""
try: try:
return dict.__getitem__(self, key) return super(MultiValueDict, self).__getitem__(key)
except KeyError: except KeyError:
return [] return []
def setlist(self, key, list_): def setlist(self, key, list_):
dict.__setitem__(self, key, list_) super(MultiValueDict, self).__setitem__(key, list_)
def setdefault(self, key, default=None): def setdefault(self, key, default=None):
if key not in self: if key not in self:
@ -242,7 +243,7 @@ class MultiValueDict(dict):
def appendlist(self, key, value): def appendlist(self, key, value):
"""Appends an item to the internal list associated with key.""" """Appends an item to the internal list associated with key."""
self.setlistdefault(key, []) self.setlistdefault(key, [])
dict.__setitem__(self, key, self.getlist(key) + [value]) super(MultiValueDict, self).__setitem__(key, self.getlist(key) + [value])
def items(self): def items(self):
""" """
@ -253,7 +254,7 @@ class MultiValueDict(dict):
def lists(self): def lists(self):
"""Returns a list of (key, list) pairs.""" """Returns a list of (key, list) pairs."""
return dict.items(self) return super(MultiValueDict, self).items()
def values(self): def values(self):
"""Returns a list of the last value on every key list.""" """Returns a list of the last value on every key list."""