mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-23 14:52:26 +00:00
remove unused UtilDict
This commit is contained in:
parent
a76d9e084f
commit
4f493b1a03
@ -1408,11 +1408,8 @@ class DictUtil(unittest.TestCase):
|
||||
d[fake3] = 8
|
||||
|
||||
def test_all(self):
|
||||
self._help_test_eq_but_notis(dictutil.UtilDict)
|
||||
self._help_test_eq_but_notis(dictutil.ValueOrderedDict)
|
||||
self._help_test_nonempty_dict(dictutil.UtilDict)
|
||||
self._help_test_nonempty_dict(dictutil.ValueOrderedDict)
|
||||
self._help_test_eq_but_notis(dictutil.UtilDict)
|
||||
self._help_test_eq_but_notis(dictutil.ValueOrderedDict)
|
||||
|
||||
def test_dict_of_sets(self):
|
||||
@ -1467,62 +1464,6 @@ class DictUtil(unittest.TestCase):
|
||||
d3 = dictutil.subtract(d1, d2)
|
||||
self.failUnlessEqual(d3, {1: "a", 3: "c"})
|
||||
|
||||
def test_utildict(self):
|
||||
d = dictutil.UtilDict({1: "a", 2: "b"})
|
||||
d.del_if_present(1)
|
||||
d.del_if_present(3)
|
||||
self.failUnlessEqual(d, {2: "b"})
|
||||
def eq(a, b):
|
||||
return a == b
|
||||
self.failUnlessRaises(TypeError, eq, d, "not a dict")
|
||||
|
||||
d = dictutil.UtilDict({1: "b", 2: "a"})
|
||||
self.failUnlessEqual(d.items_sorted_by_value(),
|
||||
[(2, "a"), (1, "b")])
|
||||
self.failUnlessEqual(d.items_sorted_by_key(),
|
||||
[(1, "b"), (2, "a")])
|
||||
self.failUnlessEqual(repr(d), "{1: 'b', 2: 'a'}")
|
||||
self.failUnless(1 in d)
|
||||
|
||||
d2 = dictutil.UtilDict({3: "c", 4: "d"})
|
||||
self.failUnless(d != d2)
|
||||
self.failUnless(d2 > d)
|
||||
self.failUnless(d2 >= d)
|
||||
self.failUnless(d <= d2)
|
||||
self.failUnless(d < d2)
|
||||
self.failUnlessEqual(d[1], "b")
|
||||
self.failUnlessEqual(sorted(list([k for k in d])), [1,2])
|
||||
|
||||
d3 = d.copy()
|
||||
self.failUnlessEqual(d, d3)
|
||||
self.failUnless(isinstance(d3, dictutil.UtilDict))
|
||||
|
||||
d4 = d.fromkeys([3,4], "e")
|
||||
self.failUnlessEqual(d4, {3: "e", 4: "e"})
|
||||
|
||||
self.failUnlessEqual(d.get(1), "b")
|
||||
self.failUnlessEqual(d.get(3), None)
|
||||
self.failUnlessEqual(d.get(3, "default"), "default")
|
||||
self.failUnlessEqual(sorted(list(d.items())),
|
||||
[(1, "b"), (2, "a")])
|
||||
self.failUnlessEqual(sorted(list(d.iteritems())),
|
||||
[(1, "b"), (2, "a")])
|
||||
self.failUnlessEqual(sorted(d.keys()), [1, 2])
|
||||
self.failUnlessEqual(sorted(d.values()), ["a", "b"])
|
||||
x = d.setdefault(1, "new")
|
||||
self.failUnlessEqual(x, "b")
|
||||
self.failUnlessEqual(d[1], "b")
|
||||
x = d.setdefault(3, "new")
|
||||
self.failUnlessEqual(x, "new")
|
||||
self.failUnlessEqual(d[3], "new")
|
||||
del d[3]
|
||||
|
||||
x = d.popitem()
|
||||
self.failUnless(x in [(1, "b"), (2, "a")])
|
||||
x = d.popitem()
|
||||
self.failUnless(x in [(1, "b"), (2, "a")])
|
||||
self.failUnlessRaises(KeyError, d.popitem)
|
||||
|
||||
def test_del_if_present(self):
|
||||
d = {1: "a", 2: "b"}
|
||||
dictutil.del_if_present(d, 1)
|
||||
|
@ -54,128 +54,6 @@ class DictOfSets(dict):
|
||||
if not self[key]:
|
||||
del self[key]
|
||||
|
||||
class UtilDict:
|
||||
def __init__(self, initialdata={}):
|
||||
self.d = {}
|
||||
self.update(initialdata)
|
||||
|
||||
def del_if_present(self, key):
|
||||
if self.has_key(key):
|
||||
del self[key]
|
||||
|
||||
def items_sorted_by_value(self):
|
||||
"""
|
||||
@return a sequence of (key, value,) pairs sorted according to value
|
||||
"""
|
||||
l = [(x[1], x[0],) for x in self.d.iteritems()]
|
||||
l.sort()
|
||||
return [(x[1], x[0],) for x in l]
|
||||
|
||||
def items_sorted_by_key(self):
|
||||
"""
|
||||
@return a sequence of (key, value,) pairs sorted according to key
|
||||
"""
|
||||
l = self.d.items()
|
||||
l.sort()
|
||||
return l
|
||||
|
||||
def __repr__(self, *args, **kwargs):
|
||||
return self.d.__repr__(*args, **kwargs)
|
||||
|
||||
def __str__(self, *args, **kwargs):
|
||||
return self.d.__str__(*args, **kwargs)
|
||||
|
||||
def __contains__(self, *args, **kwargs):
|
||||
return self.d.__contains__(*args, **kwargs)
|
||||
|
||||
def __len__(self, *args, **kwargs):
|
||||
return self.d.__len__(*args, **kwargs)
|
||||
|
||||
def __cmp__(self, other):
|
||||
try:
|
||||
return self.d.__cmp__(other)
|
||||
except TypeError, le:
|
||||
# maybe we should look for a .d member in other. I know this is insanely kludgey, but the Right Way To Do It is for dict.__cmp__ to use structural typing ("duck typing")
|
||||
try:
|
||||
return self.d.__cmp__(other.d)
|
||||
except:
|
||||
raise le
|
||||
|
||||
def __eq__(self, *args, **kwargs):
|
||||
return self.d.__eq__(*args, **kwargs)
|
||||
|
||||
def __ne__(self, *args, **kwargs):
|
||||
return self.d.__ne__(*args, **kwargs)
|
||||
|
||||
def __gt__(self, *args, **kwargs):
|
||||
return self.d.__gt__(*args, **kwargs)
|
||||
|
||||
def __ge__(self, *args, **kwargs):
|
||||
return self.d.__ge__(*args, **kwargs)
|
||||
|
||||
def __le__(self, *args, **kwargs):
|
||||
return self.d.__le__(*args, **kwargs)
|
||||
|
||||
def __lt__(self, *args, **kwargs):
|
||||
return self.d.__lt__(*args, **kwargs)
|
||||
|
||||
def __getitem__(self, *args, **kwargs):
|
||||
return self.d.__getitem__(*args, **kwargs)
|
||||
|
||||
def __setitem__(self, *args, **kwargs):
|
||||
return self.d.__setitem__(*args, **kwargs)
|
||||
|
||||
def __delitem__(self, *args, **kwargs):
|
||||
return self.d.__delitem__(*args, **kwargs)
|
||||
|
||||
def __iter__(self, *args, **kwargs):
|
||||
return self.d.__iter__(*args, **kwargs)
|
||||
|
||||
def clear(self, *args, **kwargs):
|
||||
return self.d.clear(*args, **kwargs)
|
||||
|
||||
def copy(self, *args, **kwargs):
|
||||
return self.__class__(self.d.copy(*args, **kwargs))
|
||||
|
||||
def fromkeys(self, *args, **kwargs):
|
||||
return self.__class__(self.d.fromkeys(*args, **kwargs))
|
||||
|
||||
def get(self, key, default=None):
|
||||
return self.d.get(key, default)
|
||||
|
||||
def has_key(self, *args, **kwargs):
|
||||
return self.d.has_key(*args, **kwargs)
|
||||
|
||||
def items(self, *args, **kwargs):
|
||||
return self.d.items(*args, **kwargs)
|
||||
|
||||
def iteritems(self, *args, **kwargs):
|
||||
return self.d.iteritems(*args, **kwargs)
|
||||
|
||||
def iterkeys(self, *args, **kwargs):
|
||||
return self.d.iterkeys(*args, **kwargs)
|
||||
|
||||
def itervalues(self, *args, **kwargs):
|
||||
return self.d.itervalues(*args, **kwargs)
|
||||
|
||||
def keys(self, *args, **kwargs):
|
||||
return self.d.keys(*args, **kwargs)
|
||||
|
||||
def pop(self, *args, **kwargs):
|
||||
return self.d.pop(*args, **kwargs)
|
||||
|
||||
def popitem(self, *args, **kwargs):
|
||||
return self.d.popitem(*args, **kwargs)
|
||||
|
||||
def setdefault(self, *args, **kwargs):
|
||||
return self.d.setdefault(*args, **kwargs)
|
||||
|
||||
def update(self, *args, **kwargs):
|
||||
self.d.update(*args, **kwargs)
|
||||
|
||||
def values(self, *args, **kwargs):
|
||||
return self.d.values(*args, **kwargs)
|
||||
|
||||
def del_if_present(d, k):
|
||||
if d.has_key(k):
|
||||
del d[k]
|
||||
|
Loading…
Reference in New Issue
Block a user