Weak*Dictionary.update(): Fix calls to [].append() to only have one

parameter.

Weak*Dictionary.get():  Make the second parameter optional.

WeakKeyDictionary.has_key(), .keys():  Make these actually work!
This commit is contained in:
Fred Drake 2001-04-16 17:34:48 +00:00
parent 67addfe2a8
commit 1d9e4b7de3

View File

@ -54,7 +54,7 @@ class WeakValueDictionary(UserDict.UserDict):
new[key] = o
return new
def get(self, key, default):
def get(self, key, default=None):
try:
ref = self.data[key]
except KeyError:
@ -100,7 +100,7 @@ class WeakValueDictionary(UserDict.UserDict):
for key, o in dict.items():
def remove(o, data=d, key=key):
del data[key]
L.append(key, ref(o, remove))
L.append((key, ref(o, remove)))
for key, r in L:
d[key] = r
@ -139,9 +139,12 @@ class WeakKeyDictionary(UserDict.UserDict):
new[o] = value
return new
def get(self, key, default):
def get(self, key, default=None):
return self.data.get(ref(key),default)
def has_key(self, key):
return self.data.has_key(ref(key))
def items(self):
L = []
for key, value in self.data.items():
@ -150,6 +153,14 @@ class WeakKeyDictionary(UserDict.UserDict):
L.append((o, value))
return L
def keys(self):
L = []
for ref in self.data.keys():
o = ref()
if o is not None:
L.append(o)
return L
def popitem(self):
while 1:
key, value = self.data.popitem()
@ -164,7 +175,7 @@ class WeakKeyDictionary(UserDict.UserDict):
d = self.data
L = []
for key, value in dict.items():
L.append(ref(key, self._remove), value)
L.append((ref(key, self._remove), value))
for key, r in L:
d[key] = r