Ticket #7598: keyOrder_fix.diff

File keyOrder_fix.diff, 4.6 KB (added by floguy, 16 years ago)

Patch to replace keyOrder with key_order wherever it's used in Django.

  • django/utils/datastructures.py

     
    5959            data = {}
    6060        super(SortedDict, self).__init__(data)
    6161        if isinstance(data, dict):
    62             self.keyOrder = data.keys()
     62            self.key_order = data.keys()
    6363        else:
    64             self.keyOrder = []
     64            self.key_order = []
    6565            for key, value in data:
    66                 if key not in self.keyOrder:
    67                     self.keyOrder.append(key)
     66                if key not in self.key_order:
     67                    self.key_order.append(key)
    6868
    6969    def __deepcopy__(self, memo):
    7070        from copy import deepcopy
     
    7373
    7474    def __setitem__(self, key, value):
    7575        super(SortedDict, self).__setitem__(key, value)
    76         if key not in self.keyOrder:
    77             self.keyOrder.append(key)
     76        if key not in self.key_order:
     77            self.key_order.append(key)
    7878
    7979    def __delitem__(self, key):
    8080        super(SortedDict, self).__delitem__(key)
    81         self.keyOrder.remove(key)
     81        self.key_order.remove(key)
    8282
    8383    def __iter__(self):
    84         for k in self.keyOrder:
     84        for k in self.key_order:
    8585            yield k
    8686
    8787    def pop(self, k, *args):
    8888        result = super(SortedDict, self).pop(k, *args)
    8989        try:
    90             self.keyOrder.remove(k)
     90            self.key_order.remove(k)
    9191        except ValueError:
    9292            # Key wasn't in the dictionary in the first place. No problem.
    9393            pass
     
    9595
    9696    def popitem(self):
    9797        result = super(SortedDict, self).popitem()
    98         self.keyOrder.remove(result[0])
     98        self.key_order.remove(result[0])
    9999        return result
    100100
    101101    def items(self):
    102         return zip(self.keyOrder, self.values())
     102        return zip(self.key_order, self.values())
    103103
    104104    def iteritems(self):
    105         for key in self.keyOrder:
     105        for key in self.key_order:
    106106            yield key, super(SortedDict, self).__getitem__(key)
    107107
    108108    def keys(self):
    109         return self.keyOrder[:]
     109        return self.key_order[:]
    110110
    111111    def iterkeys(self):
    112         return iter(self.keyOrder)
     112        return iter(self.key_order)
    113113
    114114    def values(self):
    115         return [super(SortedDict, self).__getitem__(k) for k in self.keyOrder]
     115        return [super(SortedDict, self).__getitem__(k) for k in self.key_order]
    116116
    117117    def itervalues(self):
    118         for key in self.keyOrder:
     118        for key in self.key_order:
    119119            yield super(SortedDict, self).__getitem__(key)
    120120
    121121    def update(self, dict_):
     
    123123            self.__setitem__(k, v)
    124124
    125125    def setdefault(self, key, default):
    126         if key not in self.keyOrder:
    127             self.keyOrder.append(key)
     126        if key not in self.key_order:
     127            self.key_order.append(key)
    128128        return super(SortedDict, self).setdefault(key, default)
    129129
    130130    def value_for_index(self, index):
    131131        """Returns the value of the item at the given zero-based index."""
    132         return self[self.keyOrder[index]]
     132        return self[self.key_order[index]]
    133133
    134134    def insert(self, index, key, value):
    135135        """Inserts the key, value pair before the item with the given index."""
    136         if key in self.keyOrder:
    137             n = self.keyOrder.index(key)
    138             del self.keyOrder[n]
     136        if key in self.key_order:
     137            n = self.key_order.index(key)
     138            del self.key_order[n]
    139139            if n < index:
    140140                index -= 1
    141         self.keyOrder.insert(index, key)
     141        self.key_order.insert(index, key)
    142142        super(SortedDict, self).__setitem__(key, value)
    143143
    144144    def copy(self):
    145145        """Returns a copy of this object."""
    146146        # This way of initializing the copy means it works for subclasses, too.
    147147        obj = self.__class__(self)
    148         obj.keyOrder = self.keyOrder[:]
     148        obj.key_order = self.key_order[:]
    149149        return obj
    150150
    151151    def __repr__(self):
     
    157157
    158158    def clear(self):
    159159        super(SortedDict, self).clear()
    160         self.keyOrder = []
     160        self.key_order = []
    161161
    162162class MultiValueDictKeyError(KeyError):
    163163    pass
  • tests/regressiontests/datastructures/tests.py

     
    104104>>> d.clear()
    105105>>> d
    106106{}
    107 >>> d.keyOrder
     107>>> d.key_order
    108108[]
    109109
    110110### DotExpandedDict ############################################################
Back to Top