summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/weakref.py19
1 files changed, 15 insertions, 4 deletions
diff --git a/Lib/weakref.py b/Lib/weakref.py
index 6945757..b6b4528 100644
--- a/Lib/weakref.py
+++ b/Lib/weakref.py
@@ -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